From f41b6e5ec431c88bc1d94e4832d8ba49ddc42004 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Tue, 5 Mar 2024 11:19:52 +0100 Subject: HomeserverEmulator work --- LibMatrix/StateEvent.cs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'LibMatrix/StateEvent.cs') diff --git a/LibMatrix/StateEvent.cs b/LibMatrix/StateEvent.cs index 019c428..541fb78 100644 --- a/LibMatrix/StateEvent.cs +++ b/LibMatrix/StateEvent.cs @@ -1,5 +1,6 @@ using System.Collections.Frozen; using System.Collections.Immutable; +using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Text.Json; @@ -25,7 +26,7 @@ public class StateEvent { return dict; }).ToFrozenDictionary(); - public static Type GetStateEventType(string type) => KnownStateEventTypesByName.GetValueOrDefault(type) ?? typeof(UnknownEventContent); + public static Type GetStateEventType(string? type) => string.IsNullOrWhiteSpace(type) ? typeof(UnknownEventContent) : KnownStateEventTypesByName.GetValueOrDefault(type) ?? typeof(UnknownEventContent); [JsonIgnore] public Type MappedType => GetStateEventType(Type); @@ -73,10 +74,10 @@ public class StateEvent { } [JsonPropertyName("state_key")] - public string StateKey { get; set; } = ""; + public string StateKey { get; set; } [JsonPropertyName("type")] - public required string Type { get; set; } + public string Type { get; set; } [JsonPropertyName("replaces_state")] public string? ReplacesState { get; set; } @@ -138,7 +139,7 @@ public class StateEvent { public class StateEventResponse : StateEvent { [JsonPropertyName("origin_server_ts")] - public ulong? OriginServerTs { get; set; } + public long? OriginServerTs { get; set; } [JsonPropertyName("room_id")] public string? RoomId { get; set; } @@ -152,9 +153,6 @@ public class StateEventResponse : StateEvent { [JsonPropertyName("event_id")] public string? EventId { get; set; } - [JsonPropertyName("replaces_state")] - public new string? ReplacesState { get; set; } - public class UnsignedData { [JsonPropertyName("age")] public ulong? Age { get; set; } @@ -181,6 +179,12 @@ public class StateEventResponse : StateEvent { internal partial class ChunkedStateEventResponseSerializerContext : JsonSerializerContext; public class EventList { + public EventList() { } + + public EventList(List? events) { + Events = events; + } + [JsonPropertyName("events")] public List? Events { get; set; } = new(); } @@ -190,6 +194,14 @@ public class ChunkedStateEventResponse { public List? Chunk { get; set; } = new(); } +public class PaginatedChunkedStateEventResponse : ChunkedStateEventResponse { + [JsonPropertyName("start")] + public string? Start { get; set; } + + [JsonPropertyName("end")] + public string? End { get; set; } +} + #region Unused code /* -- cgit 1.4.1