From 0640eba992f95cc45873330b76fadf123202d1cd Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 11 Jan 2026 16:16:21 +0100 Subject: More federation work --- .../FederationTypes/FederationBackfillResponse.cs | 14 +++++++++ .../FederationTypes/FederationEvent.cs | 30 +++++++++++++++++++ .../FederationGetMissingEventsRequest.cs | 34 ++++++++++++++++++++++ .../FederationTypes/FederationTransaction.cs | 26 +++++++++++++++++ LibMatrix.Federation/FederationTypes/RoomInvite.cs | 14 +++++++++ 5 files changed, 118 insertions(+) create mode 100644 LibMatrix.Federation/FederationTypes/FederationBackfillResponse.cs create mode 100644 LibMatrix.Federation/FederationTypes/FederationEvent.cs create mode 100644 LibMatrix.Federation/FederationTypes/FederationGetMissingEventsRequest.cs create mode 100644 LibMatrix.Federation/FederationTypes/FederationTransaction.cs create mode 100644 LibMatrix.Federation/FederationTypes/RoomInvite.cs (limited to 'LibMatrix.Federation/FederationTypes') diff --git a/LibMatrix.Federation/FederationTypes/FederationBackfillResponse.cs b/LibMatrix.Federation/FederationTypes/FederationBackfillResponse.cs new file mode 100644 index 0000000..0fe72bd --- /dev/null +++ b/LibMatrix.Federation/FederationTypes/FederationBackfillResponse.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.Federation.FederationTypes; + +public class FederationBackfillResponse { + [JsonPropertyName("origin")] + public required string Origin { get; set; } + + [JsonPropertyName("origin_server_ts")] + public required long OriginServerTs { get; set; } + + [JsonPropertyName("pdus")] + public required List Pdus { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.Federation/FederationTypes/FederationEvent.cs b/LibMatrix.Federation/FederationTypes/FederationEvent.cs new file mode 100644 index 0000000..05bdcc9 --- /dev/null +++ b/LibMatrix.Federation/FederationTypes/FederationEvent.cs @@ -0,0 +1,30 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.Federation.FederationTypes; + +public class FederationEvent : MatrixEventResponse { + [JsonPropertyName("auth_events")] + public required List AuthEvents { get; set; } = []; + + [JsonPropertyName("prev_events")] + public required List PrevEvents { get; set; } = []; + + [JsonPropertyName("depth")] + public required int Depth { get; set; } +} + +public class SignedFederationEvent : FederationEvent { + [JsonPropertyName("signatures")] + public required Dictionary> Signatures { get; set; } = new(); + + [JsonPropertyName("hashes")] + public required Dictionary Hashes { get; set; } = new(); +} + +public class FederationEphemeralEvent { + [JsonPropertyName("edu_type")] + public required string Type { get; set; } + + [JsonPropertyName("content")] + public required Dictionary Content { get; set; } = new(); +} \ No newline at end of file diff --git a/LibMatrix.Federation/FederationTypes/FederationGetMissingEventsRequest.cs b/LibMatrix.Federation/FederationTypes/FederationGetMissingEventsRequest.cs new file mode 100644 index 0000000..f43dd49 --- /dev/null +++ b/LibMatrix.Federation/FederationTypes/FederationGetMissingEventsRequest.cs @@ -0,0 +1,34 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.Federation.FederationTypes; + +public class FederationGetMissingEventsRequest { + /// + /// Latest event IDs we already have (aka earliest to return) + /// + [JsonPropertyName("earliest_events")] + public required List EarliestEvents { get; set; } + + /// + /// Events we want to get events before + /// + [JsonPropertyName("latest_events")] + public required List LatestEvents { get; set; } + + /// + /// 10 by default + /// + [JsonPropertyName("limit")] + public int Limit { get; set; } + + /// + /// 0 by default + /// + [JsonPropertyName("min_depth")] + public long MinDepth { get; set; } +} + +public class FederationGetMissingEventsResponse { + [JsonPropertyName("events")] + public required List Events { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.Federation/FederationTypes/FederationTransaction.cs b/LibMatrix.Federation/FederationTypes/FederationTransaction.cs new file mode 100644 index 0000000..0581a08 --- /dev/null +++ b/LibMatrix.Federation/FederationTypes/FederationTransaction.cs @@ -0,0 +1,26 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.Federation.FederationTypes; + +/// +/// This only covers v12 rooms for now? +/// +public class FederationTransaction { + /// + /// Up to 100 EDUs per transaction + /// + [JsonPropertyName("edus")] + public List? EphemeralEvents { get; set; } + + [JsonPropertyName("origin")] + public required string Origin { get; set; } + + [JsonPropertyName("origin_server_ts")] + public required long OriginServerTs { get; set; } + + /// + /// Up to 50 PDUs per transaction + /// + [JsonPropertyName("pdus")] + public List? PersistentEvents { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.Federation/FederationTypes/RoomInvite.cs b/LibMatrix.Federation/FederationTypes/RoomInvite.cs new file mode 100644 index 0000000..dc550f3 --- /dev/null +++ b/LibMatrix.Federation/FederationTypes/RoomInvite.cs @@ -0,0 +1,14 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.Federation.FederationTypes; + +public class RoomInvite { + [JsonPropertyName("event")] + public required SignedFederationEvent Event { get; set; } + + [JsonPropertyName("invite_room_state")] + public required List InviteRoomState { get; set; } = []; + + [JsonPropertyName("room_version")] + public required string RoomVersion { get; set; } +} \ No newline at end of file -- cgit 1.5.1