From e5591eef3850a9796cc87386128651a828b70697 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 6 Oct 2023 18:29:15 +0200 Subject: Small refactors --- LibMatrix/Responses/CreateRoomRequest.cs | 1 + LibMatrix/Responses/LoginResponse.cs | 2 +- LibMatrix/Responses/StateEventResponse.cs | 52 ------------- LibMatrix/Responses/SyncResponse.cs | 118 ++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 53 deletions(-) delete mode 100644 LibMatrix/Responses/StateEventResponse.cs create mode 100644 LibMatrix/Responses/SyncResponse.cs (limited to 'LibMatrix/Responses') diff --git a/LibMatrix/Responses/CreateRoomRequest.cs b/LibMatrix/Responses/CreateRoomRequest.cs index 511b3da..1ad590f 100644 --- a/LibMatrix/Responses/CreateRoomRequest.cs +++ b/LibMatrix/Responses/CreateRoomRequest.cs @@ -2,6 +2,7 @@ using System.Reflection; using System.Text.Json.Nodes; using System.Text.Json.Serialization; using System.Text.RegularExpressions; +using LibMatrix.EventTypes; using LibMatrix.EventTypes.Spec.State; using LibMatrix.Helpers; using LibMatrix.Homeservers; diff --git a/LibMatrix/Responses/LoginResponse.cs b/LibMatrix/Responses/LoginResponse.cs index eb53c0a..07b1601 100644 --- a/LibMatrix/Responses/LoginResponse.cs +++ b/LibMatrix/Responses/LoginResponse.cs @@ -23,7 +23,7 @@ public class LoginResponse { public string UserId { get; set; } = null!; public async Task GetAuthenticatedHomeserver(string? proxy = null) { - return new AuthenticatedHomeserverGeneric(proxy ?? await new HomeserverResolverService().ResolveHomeserverFromWellKnown(Homeserver), AccessToken); + return await AuthenticatedHomeserverGeneric.Create(proxy ?? await new HomeserverResolverService().ResolveHomeserverFromWellKnown(Homeserver), AccessToken); } } public class LoginRequest { diff --git a/LibMatrix/Responses/StateEventResponse.cs b/LibMatrix/Responses/StateEventResponse.cs deleted file mode 100644 index 7ca6bab..0000000 --- a/LibMatrix/Responses/StateEventResponse.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Text.Json.Nodes; -using System.Text.Json.Serialization; - -namespace LibMatrix.Responses; - -public class StateEventResponse : StateEvent { - [JsonPropertyName("origin_server_ts")] - public ulong OriginServerTs { get; set; } - - [JsonPropertyName("room_id")] - public string RoomId { get; set; } - - [JsonPropertyName("sender")] - public string Sender { get; set; } - - [JsonPropertyName("unsigned")] - public UnsignedData? Unsigned { get; set; } - - [JsonPropertyName("event_id")] - public string EventId { get; set; } - - [JsonPropertyName("user_id")] - public string UserId { get; set; } - - [JsonPropertyName("replaces_state")] - public new string ReplacesState { get; set; } - - public class UnsignedData { - [JsonPropertyName("age")] - public ulong? Age { get; set; } - - [JsonPropertyName("redacted_because")] - public object? RedactedBecause { get; set; } - - [JsonPropertyName("transaction_id")] - public string? TransactionId { get; set; } - - [JsonPropertyName("replaces_state")] - public string? ReplacesState { get; set; } - - [JsonPropertyName("prev_sender")] - public string? PrevSender { get; set; } - - [JsonPropertyName("prev_content")] - public JsonObject? PrevContent { get; set; } - } -} - -public class ChunkedStateEventResponse { - [JsonPropertyName("chunk")] - public List? Chunk { get; set; } -} diff --git a/LibMatrix/Responses/SyncResponse.cs b/LibMatrix/Responses/SyncResponse.cs new file mode 100644 index 0000000..39cb38f --- /dev/null +++ b/LibMatrix/Responses/SyncResponse.cs @@ -0,0 +1,118 @@ +using System.Text.Json.Serialization; +using LibMatrix.Helpers; + +namespace LibMatrix.Responses; + +public class SyncResponse { + [JsonPropertyName("next_batch")] + public string NextBatch { get; set; } = null!; + + [JsonPropertyName("account_data")] + public EventList? AccountData { get; set; } + + [JsonPropertyName("presence")] + public PresenceDataStructure? Presence { get; set; } + + [JsonPropertyName("device_one_time_keys_count")] + public Dictionary? DeviceOneTimeKeysCount { get; set; } = null!; + + [JsonPropertyName("rooms")] + public RoomsDataStructure? Rooms { get; set; } + + [JsonPropertyName("to_device")] + public EventList? ToDevice { get; set; } + + [JsonPropertyName("device_lists")] + public DeviceListsDataStructure? DeviceLists { get; set; } + + public class DeviceListsDataStructure { + [JsonPropertyName("changed")] + public List? Changed { get; set; } + + [JsonPropertyName("left")] + public List? Left { get; set; } + } + + // supporting classes + public class PresenceDataStructure { + [JsonPropertyName("events")] + public List Events { get; set; } = new(); + } + + public class RoomsDataStructure { + [JsonPropertyName("join")] + public Dictionary? Join { get; set; } + + [JsonPropertyName("invite")] + public Dictionary? Invite { get; set; } + + [JsonPropertyName("leave")] + public Dictionary? Leave { get; set; } + + public class LeftRoomDataStructure { + [JsonPropertyName("account_data")] + public EventList AccountData { get; set; } + + [JsonPropertyName("timeline")] + public JoinedRoomDataStructure.TimelineDataStructure? Timeline { get; set; } + + [JsonPropertyName("state")] + public EventList State { get; set; } + } + + public class JoinedRoomDataStructure { + [JsonPropertyName("timeline")] + public TimelineDataStructure? Timeline { get; set; } + + [JsonPropertyName("state")] + public EventList? State { get; set; } + + [JsonPropertyName("account_data")] + public EventList? AccountData { get; set; } + + [JsonPropertyName("ephemeral")] + public EventList? Ephemeral { get; set; } + + [JsonPropertyName("unread_notifications")] + public UnreadNotificationsDataStructure? UnreadNotifications { get; set; } + + [JsonPropertyName("summary")] + public SummaryDataStructure? Summary { get; set; } + + public class TimelineDataStructure { + [JsonPropertyName("events")] + public List? Events { get; set; } + + [JsonPropertyName("prev_batch")] + public string? PrevBatch { get; set; } + + [JsonPropertyName("limited")] + public bool? Limited { get; set; } + } + + public class UnreadNotificationsDataStructure { + [JsonPropertyName("notification_count")] + public int NotificationCount { get; set; } + + [JsonPropertyName("highlight_count")] + public int HighlightCount { get; set; } + } + + public class SummaryDataStructure { + [JsonPropertyName("m.heroes")] + public List Heroes { get; set; } + + [JsonPropertyName("m.invited_member_count")] + public int InvitedMemberCount { get; set; } + + [JsonPropertyName("m.joined_member_count")] + public int JoinedMemberCount { get; set; } + } + } + + public class InvitedRoomDataStructure { + [JsonPropertyName("invite_state")] + public EventList? InviteState { get; set; } + } + } +} -- cgit 1.4.1