about summary refs log tree commit diff
path: root/LibMatrix/StateEvent.cs
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2023-12-14 07:20:46 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2023-12-14 07:20:46 +0100
commit5affd9f061e75f6575a2fe6715f9e8757cfe87e8 (patch)
tree13ea35ce981094a960746777a16dff8815c45e55 /LibMatrix/StateEvent.cs
parentTemp state (diff)
downloadLibMatrix-5affd9f061e75f6575a2fe6715f9e8757cfe87e8.tar.xz
Cleanup
Diffstat (limited to '')
-rw-r--r--LibMatrix/StateEvent.cs39
1 files changed, 13 insertions, 26 deletions
diff --git a/LibMatrix/StateEvent.cs b/LibMatrix/StateEvent.cs
index 6ca82f4..cfc7011 100644
--- a/LibMatrix/StateEvent.cs
+++ b/LibMatrix/StateEvent.cs
@@ -1,3 +1,5 @@
+using System.Collections.Frozen;
+using System.Collections.Immutable;
 using System.Diagnostics.CodeAnalysis;
 using System.Reflection;
 using System.Text.Json;
@@ -7,31 +9,23 @@ using ArcaneLibs;
 using ArcaneLibs.Extensions;
 using LibMatrix.EventTypes;
 using LibMatrix.Extensions;
-using LibMatrix.Interfaces;
 
 namespace LibMatrix;
 
 public class StateEvent {
-    public static List<Type> KnownStateEventTypes { get; } = new ClassCollector<EventContent>().ResolveFromAllAccessibleAssemblies();
+    public static FrozenSet<Type> KnownStateEventTypes { get; } = new ClassCollector<EventContent>().ResolveFromAllAccessibleAssemblies().ToFrozenSet();
 
-    public static readonly Dictionary<string, Type> KnownStateEventTypesByName = KnownStateEventTypes.Aggregate(
+    public static FrozenDictionary<string, Type> KnownStateEventTypesByName { get; } = KnownStateEventTypes.Aggregate(
         new Dictionary<string, Type>(),
         (dict, type) => {
             var attrs = type.GetCustomAttributes<MatrixEventAttribute>();
             foreach (var attr in attrs) {
                 dict[attr.EventName] = type;
             }
-
             return dict;
-        });
-
-    public static Type GetStateEventType(string type) {
-        if (type == "m.receipt") {
-            return typeof(Dictionary<string, JsonObject>);
-        }
+        }).ToFrozenDictionary();
 
-        return KnownStateEventTypesByName.GetValueOrDefault(type) ?? typeof(UnknownEventContent);
-    }
+    public static Type GetStateEventType(string type) => KnownStateEventTypesByName.GetValueOrDefault(type) ?? typeof(UnknownEventContent);
 
     private static readonly JsonSerializerOptions TypedContentSerializerOptions = new JsonSerializerOptions() {
         Converters = {
@@ -80,13 +74,7 @@ public class StateEvent {
     [JsonPropertyName("content")]
     public JsonObject? RawContent {
         get => _rawContent;
-        set {
-            _rawContent = value;
-            // if (Type is not null && this is StateEventResponse stateEventResponse) {
-            //     if (File.Exists($"unknown_state_events/{Type}/{stateEventResponse.EventId}.json")) return;
-            //     var x = GetType.Name;
-            // }
-        }
+        set => _rawContent = value;
     }
 
     [JsonIgnore]
@@ -139,22 +127,22 @@ public class StateEvent {
 
 public class StateEventResponse : StateEvent {
     [JsonPropertyName("origin_server_ts")]
-    public ulong OriginServerTs { get; set; }
+    public ulong? OriginServerTs { get; set; }
 
     [JsonPropertyName("room_id")]
-    public string RoomId { get; set; }
+    public string? RoomId { get; set; }
 
     [JsonPropertyName("sender")]
-    public string Sender { get; set; }
+    public string? Sender { get; set; }
 
     [JsonPropertyName("unsigned")]
     public UnsignedData? Unsigned { get; set; }
 
     [JsonPropertyName("event_id")]
-    public string EventId { get; set; }
+    public string? EventId { get; set; }
 
     [JsonPropertyName("replaces_state")]
-    public new string ReplacesState { get; set; }
+    public new string? ReplacesState { get; set; }
 
     public class UnsignedData {
         [JsonPropertyName("age")]
@@ -179,8 +167,7 @@ public class StateEventResponse : StateEvent {
 
 [JsonSourceGenerationOptions(WriteIndented = true)]
 [JsonSerializable(typeof(ChunkedStateEventResponse))]
-internal partial class ChunkedStateEventResponseSerializerContext : JsonSerializerContext {
-}
+internal partial class ChunkedStateEventResponseSerializerContext : JsonSerializerContext;
 
 public class EventList {
     [JsonPropertyName("events")]