From 136f80a9feae14f2159b03c3fd99d6d12fa7c4f9 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 20 May 2024 06:25:52 +0200 Subject: Log unrecognised types --- LibMatrix/StateEvent.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'LibMatrix/StateEvent.cs') diff --git a/LibMatrix/StateEvent.cs b/LibMatrix/StateEvent.cs index f504c99..e3de7e6 100644 --- a/LibMatrix/StateEvent.cs +++ b/LibMatrix/StateEvent.cs @@ -22,7 +22,7 @@ public class StateEvent { foreach (var attr in attrs) dict[attr.EventName] = type; return dict; - }).ToFrozenDictionary(); + }).OrderBy(x => x.Key).ToFrozenDictionary(); public static Type GetStateEventType(string? type) => string.IsNullOrWhiteSpace(type) ? typeof(UnknownEventContent) : KnownStateEventTypesByName.GetValueOrDefault(type) ?? typeof(UnknownEventContent); @@ -55,8 +55,11 @@ public class StateEvent { // return null; // } try { - var c = (EventContent)RawContent.Deserialize(GetStateEventType(Type), TypedContentSerializerOptions)!; - return c; + var mappedType = GetStateEventType(Type); + if (mappedType == typeof(UnknownEventContent)) + Console.WriteLine($"Warning: unknown event type '{Type}'"); + var deserialisedContent = (EventContent)RawContent.Deserialize(mappedType, TypedContentSerializerOptions)!; + return deserialisedContent; } catch (JsonException e) { Console.WriteLine(e); @@ -206,7 +209,7 @@ public class PaginatedChunkedStateEventResponse : ChunkedStateEventResponse { public class BatchedChunkedStateEventResponse : ChunkedStateEventResponse { [JsonPropertyName("next_batch")] public string? NextBatch { get; set; } - + [JsonPropertyName("prev_batch")] public string? PrevBatch { get; set; } } -- cgit 1.4.1