about summary refs log tree commit diff
path: root/LibMatrix/RoomTypes
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-11-14 10:48:26 +0100
committerRory& <root@rory.gay>2025-11-14 10:48:26 +0100
commit3558ba25896876b0c546f4c2decbb0671187745b (patch)
tree4e1a21a109726bbd7768e8a63b36f720c36f97f9 /LibMatrix/RoomTypes
parentHandle some non-browser network errors, clean up some well known resolver stuff (diff)
downloadLibMatrix-3558ba25896876b0c546f4c2decbb0671187745b.tar.xz
StateEvent -> MatrixEvent
Diffstat (limited to 'LibMatrix/RoomTypes')
-rw-r--r--LibMatrix/RoomTypes/GenericRoom.cs46
-rw-r--r--LibMatrix/RoomTypes/PolicyRoom.cs10
2 files changed, 28 insertions, 28 deletions
diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs

index 37f301e..6d9a499 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs
@@ -27,13 +27,13 @@ public class GenericRoom { public string RoomId { get; set; } - public async IAsyncEnumerable<StateEventResponse?> GetFullStateAsync() { - var result = Homeserver.ClientHttpClient.GetAsyncEnumerableFromJsonAsync<StateEventResponse>($"/_matrix/client/v3/rooms/{RoomId}/state"); + public async IAsyncEnumerable<MatrixEventResponse?> GetFullStateAsync() { + var result = Homeserver.ClientHttpClient.GetAsyncEnumerableFromJsonAsync<MatrixEventResponse>($"/_matrix/client/v3/rooms/{RoomId}/state"); await foreach (var resp in result) yield return resp; } - public Task<List<StateEventResponse>> GetFullStateAsListAsync() => - Homeserver.ClientHttpClient.GetFromJsonAsync<List<StateEventResponse>>($"/_matrix/client/v3/rooms/{RoomId}/state"); + public Task<List<MatrixEventResponse>> GetFullStateAsListAsync() => + Homeserver.ClientHttpClient.GetFromJsonAsync<List<MatrixEventResponse>>($"/_matrix/client/v3/rooms/{RoomId}/state"); public async Task<T?> GetStateAsync<T>(string type, string stateKey = "") { if (string.IsNullOrEmpty(type)) throw new ArgumentNullException(nameof(type), "Event type must be specified"); @@ -63,7 +63,7 @@ public class GenericRoom { } } - public async Task<StateEventResponse> GetStateEventAsync(string type, string stateKey = "") { + public async Task<MatrixEventResponse> GetStateEventAsync(string type, string stateKey = "") { if (string.IsNullOrEmpty(type)) throw new ArgumentNullException(nameof(type), "Event type must be specified"); var url = $"/_matrix/client/v3/rooms/{RoomId}/state/{type}"; if (!string.IsNullOrEmpty(stateKey)) url += $"/{stateKey}"; @@ -76,7 +76,7 @@ public class GenericRoom { ErrorCode = LibMatrixException.ErrorCodes.M_UNSUPPORTED }; // throw new InvalidDataException("Returned event type does not match requested type, or server does not support passing `format`."); - return resp.Deserialize<StateEventResponse>(); + return resp.Deserialize<MatrixEventResponse>(); } catch (MatrixException e) { // if (e is not { ErrorCodode: "M_NOT_FOUND" }) { @@ -128,7 +128,7 @@ public class GenericRoom { } } - public async Task<StateEventResponse?> GetStateEventOrNullAsync(string type, string stateKey = "") { + public async Task<MatrixEventResponse?> GetStateEventOrNullAsync(string type, string stateKey = "") { try { return await GetStateEventAsync(type, stateKey); } @@ -241,13 +241,13 @@ public class GenericRoom { return await res.Content.ReadFromJsonAsync<RoomIdResponse>() ?? throw new Exception("Failed to join room?"); } - public async IAsyncEnumerable<StateEventResponse> GetMembersEnumerableAsync(string? membership = null) { + public async IAsyncEnumerable<MatrixEventResponse> GetMembersEnumerableAsync(string? membership = null) { var url = $"/_matrix/client/v3/rooms/{RoomId}/members"; var isMembershipSet = !string.IsNullOrWhiteSpace(membership); if (isMembershipSet) url += $"?membership={membership}"; var res = await Homeserver.ClientHttpClient.GetAsync(url); - var result = await JsonSerializer.DeserializeAsync<ChunkedStateEventResponse>(await res.Content.ReadAsStreamAsync(), new JsonSerializerOptions() { - TypeInfoResolver = ChunkedStateEventResponseSerializerContext.Default + var result = await JsonSerializer.DeserializeAsync<ChunkedMatrixEventResponse>(await res.Content.ReadAsStreamAsync(), new JsonSerializerOptions() { + TypeInfoResolver = ChunkedMatrixEventResponseSerializerContext.Default }); if (result is null) throw new Exception("Failed to deserialise members response"); @@ -259,18 +259,18 @@ public class GenericRoom { } } - public async Task<FrozenSet<StateEventResponse>> GetMembersListAsync(string? membership = null) { + public async Task<FrozenSet<MatrixEventResponse>> GetMembersListAsync(string? membership = null) { var url = $"/_matrix/client/v3/rooms/{RoomId}/members"; var isMembershipSet = !string.IsNullOrWhiteSpace(membership); if (isMembershipSet) url += $"?membership={membership}"; var res = await Homeserver.ClientHttpClient.GetAsync(url); - var result = await JsonSerializer.DeserializeAsync<ChunkedStateEventResponse>(await res.Content.ReadAsStreamAsync(), new JsonSerializerOptions() { - TypeInfoResolver = ChunkedStateEventResponseSerializerContext.Default + var result = await JsonSerializer.DeserializeAsync<ChunkedMatrixEventResponse>(await res.Content.ReadAsStreamAsync(), new JsonSerializerOptions() { + TypeInfoResolver = ChunkedMatrixEventResponseSerializerContext.Default }); if (result is null) throw new Exception("Failed to deserialise members response"); - var members = new List<StateEventResponse>(); + var members = new List<MatrixEventResponse>(); foreach (var resp in result.Chunk ?? []) { if (resp.Type != "m.room.member") continue; if (isMembershipSet && resp.RawContent?["membership"]?.GetValue<string>() != membership) continue; @@ -478,8 +478,8 @@ public class GenericRoom { } } - public Task<StateEventResponse> GetEventAsync(string eventId, bool includeUnredactedContent = false) => - Homeserver.ClientHttpClient.GetFromJsonAsync<StateEventResponse>( + public Task<MatrixEventResponse> GetEventAsync(string eventId, bool includeUnredactedContent = false) => + Homeserver.ClientHttpClient.GetFromJsonAsync<MatrixEventResponse>( // .ToLower() on boolean here because this query param specifically on synapse is checked as a string rather than a boolean $"/_matrix/client/v3/rooms/{RoomId}/event/{eventId}?fi.mau.msc2815.include_unredacted_content={includeUnredactedContent.ToString().ToLower()}"); @@ -597,7 +597,7 @@ public class GenericRoom { #endregion - public async IAsyncEnumerable<StateEventResponse> GetRelatedEventsAsync(string eventId, string? relationType = null, string? eventType = null, string? dir = "f", + public async IAsyncEnumerable<MatrixEventResponse> GetRelatedEventsAsync(string eventId, string? relationType = null, string? eventType = null, string? dir = "f", string? from = null, int? chunkLimit = 100, bool? recurse = null, string? to = null) { var path = $"/_matrix/client/v1/rooms/{RoomId}/relations/{HttpUtility.UrlEncode(eventId)}"; if (!string.IsNullOrEmpty(relationType)) path += $"/{relationType}"; @@ -612,18 +612,18 @@ public class GenericRoom { if (!string.IsNullOrEmpty(to)) uri = uri.AddQuery("to", to); // Console.WriteLine($"Getting related events from {uri}"); - var result = await Homeserver.ClientHttpClient.GetFromJsonAsync<RecursedBatchedChunkedStateEventResponse>(uri.ToString()); + var result = await Homeserver.ClientHttpClient.GetFromJsonAsync<RecursedBatchedChunkedMatrixEventResponse>(uri.ToString()); while (result!.Chunk.Count > 0) { foreach (var resp in result.Chunk) { yield return resp; } if (result.NextBatch is null) break; - result = await Homeserver.ClientHttpClient.GetFromJsonAsync<RecursedBatchedChunkedStateEventResponse>(uri.AddQuery("from", result.NextBatch).ToString()); + result = await Homeserver.ClientHttpClient.GetFromJsonAsync<RecursedBatchedChunkedMatrixEventResponse>(uri.AddQuery("from", result.NextBatch).ToString()); } } - public async Task BulkSendEventsAsync(IEnumerable<StateEvent> events, int? forceSyncInterval = null) { + public async Task BulkSendEventsAsync(IEnumerable<MatrixEvent> events, int? forceSyncInterval = null) { if ((await Homeserver.GetCapabilitiesAsync()).Capabilities.BulkSendEvents?.Enabled == true) { var uri = $"/_matrix/client/unstable/gay.rory.bulk_send_events/rooms/{RoomId}/bulk_send_events?_libmatrix_txn_id={Guid.NewGuid()}"; if (forceSyncInterval is not null) uri += $"&force_sync_interval={forceSyncInterval}"; @@ -640,7 +640,7 @@ public class GenericRoom { } } - public async Task BulkSendEventsAsync(IAsyncEnumerable<StateEvent> events, int? forceSyncInterval = null) { + public async Task BulkSendEventsAsync(IAsyncEnumerable<MatrixEvent> events, int? forceSyncInterval = null) { if ((await Homeserver.GetCapabilitiesAsync()).Capabilities.BulkSendEvents?.Enabled == true) { var uri = $"/_matrix/client/unstable/gay.rory.bulk_send_events/rooms/{RoomId}/bulk_send_events?_libmatrix_txn_id={Guid.NewGuid()}"; if (forceSyncInterval is not null) uri += $"&force_sync_interval={forceSyncInterval}"; @@ -670,7 +670,7 @@ public class GenericRoom { /// </summary> /// <returns>A list of size 1 for v11 rooms and older, all creators for v12+</returns> public async Task<List<string>> GetRoomCreatorsAsync() { - StateEventResponse createEvent; + MatrixEventResponse createEvent; if (IsV12PlusRoomId) { createEvent = await GetEventAsync('$' + RoomId[1..]); } @@ -721,4 +721,4 @@ public class GenericRoom { public class RoomIdResponse { [JsonPropertyName("room_id")] public string RoomId { get; set; } -} +} \ No newline at end of file diff --git a/LibMatrix/RoomTypes/PolicyRoom.cs b/LibMatrix/RoomTypes/PolicyRoom.cs
index c6eec63..e4fa6ae 100644 --- a/LibMatrix/RoomTypes/PolicyRoom.cs +++ b/LibMatrix/RoomTypes/PolicyRoom.cs
@@ -7,13 +7,13 @@ namespace LibMatrix.RoomTypes; public class PolicyRoom(AuthenticatedHomeserverGeneric homeserver, string roomId) : GenericRoom(homeserver, roomId) { public const string TypeName = "support.feline.policy.lists.msc.v1"; - + public static readonly FrozenSet<string> UserPolicyEventTypes = EventContent.GetMatchingEventTypes<UserPolicyRuleEventContent>().ToFrozenSet(); public static readonly FrozenSet<string> ServerPolicyEventTypes = EventContent.GetMatchingEventTypes<ServerPolicyRuleEventContent>().ToFrozenSet(); public static readonly FrozenSet<string> RoomPolicyEventTypes = EventContent.GetMatchingEventTypes<RoomPolicyRuleEventContent>().ToFrozenSet(); public static readonly FrozenSet<string> SpecPolicyEventTypes = [..UserPolicyEventTypes, ..ServerPolicyEventTypes, ..RoomPolicyEventTypes]; - public async IAsyncEnumerable<StateEventResponse> GetPoliciesAsync() { + public async IAsyncEnumerable<MatrixEventResponse> GetPoliciesAsync() { var fullRoomState = GetFullStateAsync(); await foreach (var eventResponse in fullRoomState) { if (SpecPolicyEventTypes.Contains(eventResponse!.Type)) { @@ -22,7 +22,7 @@ public class PolicyRoom(AuthenticatedHomeserverGeneric homeserver, string roomId } } - public async IAsyncEnumerable<StateEventResponse> GetUserPoliciesAsync() { + public async IAsyncEnumerable<MatrixEventResponse> GetUserPoliciesAsync() { var fullRoomState = GetPoliciesAsync(); await foreach (var eventResponse in fullRoomState) { if (UserPolicyEventTypes.Contains(eventResponse!.Type)) { @@ -31,7 +31,7 @@ public class PolicyRoom(AuthenticatedHomeserverGeneric homeserver, string roomId } } - public async IAsyncEnumerable<StateEventResponse> GetServerPoliciesAsync() { + public async IAsyncEnumerable<MatrixEventResponse> GetServerPoliciesAsync() { var fullRoomState = GetPoliciesAsync(); await foreach (var eventResponse in fullRoomState) { if (ServerPolicyEventTypes.Contains(eventResponse!.Type)) { @@ -40,7 +40,7 @@ public class PolicyRoom(AuthenticatedHomeserverGeneric homeserver, string roomId } } - public async IAsyncEnumerable<StateEventResponse> GetRoomPoliciesAsync() { + public async IAsyncEnumerable<MatrixEventResponse> GetRoomPoliciesAsync() { var fullRoomState = GetPoliciesAsync(); await foreach (var eventResponse in fullRoomState) { if (RoomPolicyEventTypes.Contains(eventResponse!.Type)) {