From cc61a7ae65d427e862e67ed92ec39f449cb23345 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 23 Jan 2025 19:43:55 +0100 Subject: The rest of warning cleanup so far. --- LibMatrix/RoomTypes/GenericRoom.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'LibMatrix/RoomTypes') diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index b8e68f8..14276d7 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -135,7 +135,7 @@ public class GenericRoom { return await GetStateEventAsync(type, stateKey); } catch (MatrixException e) { - if (e.ErrorCode == "M_NOT_FOUND") return default; + if (e.ErrorCode == "M_NOT_FOUND") return null; throw; } } @@ -237,10 +237,11 @@ public class GenericRoom { var result = await JsonSerializer.DeserializeAsync(await res.Content.ReadAsStreamAsync(), new JsonSerializerOptions() { TypeInfoResolver = ChunkedStateEventResponseSerializerContext.Default }); + if (result is null) throw new Exception("Failed to deserialise members response"); // if (sw.ElapsedMilliseconds > 100) // Console.WriteLine($"Members call deserialised in {sw.GetElapsedAndRestart()}"); // else sw.Restart(); - foreach (var resp in result.Chunk) { + foreach (var resp in result.Chunk ?? []) { if (resp?.Type != "m.room.member") continue; if (joinedOnly && resp.RawContent?["membership"]?.GetValue() != "join") continue; yield return resp; @@ -261,11 +262,12 @@ public class GenericRoom { var result = await JsonSerializer.DeserializeAsync(await res.Content.ReadAsStreamAsync(), new JsonSerializerOptions() { TypeInfoResolver = ChunkedStateEventResponseSerializerContext.Default }); + if (result is null) throw new Exception("Failed to deserialise members response"); // if (sw.ElapsedMilliseconds > 100) // Console.WriteLine($"Members call deserialised in {sw.GetElapsedAndRestart()}"); // else sw.Restart(); var members = new List(); - foreach (var resp in result.Chunk) { + foreach (var resp in result.Chunk ?? []) { if (resp?.Type != "m.room.member") continue; if (joinedOnly && resp.RawContent?["membership"]?.GetValue() != "join") continue; members.Add(resp); @@ -428,7 +430,7 @@ public class GenericRoom { return await res.Content.ReadFromJsonAsync(); } - + public async Task GetRoomAccountDataOrNullAsync(string key) { try { return await GetRoomAccountDataAsync(key); @@ -456,7 +458,8 @@ public class GenericRoom { while (true) { try { return (await (await Homeserver.ClientHttpClient.PutAsJsonAsync(url, data)).Content.ReadFromJsonAsync())!; - } catch (MatrixException e) { + } + catch (MatrixException e) { if (e is { ErrorCode: MatrixException.ErrorCodes.M_FORBIDDEN }) throw; throw; } -- cgit 1.5.1