about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-05-20 06:25:52 +0200
committerRory& <root@rory.gay>2024-05-20 06:25:52 +0200
commit136f80a9feae14f2159b03c3fd99d6d12fa7c4f9 (patch)
treef8238cf6fa2532068e0945e650179c7612c31878
parentDont use refs for proxy (diff)
downloadLibMatrix-bak-136f80a9feae14f2159b03c3fd99d6d12fa7c4f9.tar.xz
Log unrecognised types
-rw-r--r--LibMatrix/StateEvent.cs11
1 files changed, 7 insertions, 4 deletions
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; }
 }