diff options
author | Rory& <root@rory.gay> | 2024-04-19 15:54:30 +0200 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-04-19 15:54:30 +0200 |
commit | 440807e02393410327cd86d5ffa007dee98f8954 (patch) | |
tree | e750b0bab55a9ee7b507cd48eaa4ccb2ddd25fc0 /LibMatrix/RoomTypes | |
parent | Fix homeserver resolution, rewrite homeserver initialisation, HSE work (diff) | |
download | LibMatrix-bak-440807e02393410327cd86d5ffa007dee98f8954.tar.xz |
Partial User-Interactive Authentication, allow skipping homeserver typing
Diffstat (limited to 'LibMatrix/RoomTypes')
-rw-r--r-- | LibMatrix/RoomTypes/GenericRoom.cs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index 36abadc..e4d2b9c 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -160,7 +160,7 @@ public class GenericRoom { Console.WriteLine("End of GetManyAsync"); } - public async Task<string?> GetNameAsync() => (await GetStateAsync<RoomNameEventContent>("m.room.name"))?.Name; + public async Task<string?> GetNameAsync() => (await GetStateOrNullAsync<RoomNameEventContent>("m.room.name"))?.Name; public async Task<RoomIdResponse> JoinAsync(string[]? homeservers = null, string? reason = null, bool checkIfAlreadyMember = true) { if (checkIfAlreadyMember) @@ -406,7 +406,7 @@ public class GenericRoom { } } - public Task<T> GetEventAsync<T>(string eventId) => Homeserver.ClientHttpClient.GetFromJsonAsync<T>($"/_matrix/client/v3/rooms/{RoomId}/event/{eventId}"); + public Task<StateEventResponse> GetEventAsync(string eventId) => Homeserver.ClientHttpClient.GetFromJsonAsync<StateEventResponse>($"/_matrix/client/v3/rooms/{RoomId}/event/{eventId}"); public async Task<EventIdResponse> RedactEventAsync(string eventToRedact, string reason) { var data = new { reason }; @@ -465,6 +465,30 @@ public class GenericRoom { #endregion + public async IAsyncEnumerable<StateEventResponse> GetRelatedEventsAsync(string eventId, string? relationType = null, string? eventType = null, string? dir = "f", + string? from = null, int? chunkLimit = 100, bool? recurse = false, string? to = null) { + var path = $"/_matrix/client/v3/rooms/{RoomId}/relations/{eventId}"; + if (!string.IsNullOrEmpty(relationType)) path += $"/{relationType}"; + if (!string.IsNullOrEmpty(eventType)) path += $"/{eventType}"; + + var uri = new Uri(path, UriKind.Relative); + if (dir == "b" || dir == "f") uri = uri.AddQuery("dir", dir); + if (!string.IsNullOrEmpty(from)) uri = uri.AddQuery("from", from); + if (chunkLimit is not null) uri = uri.AddQuery("limit", chunkLimit.Value.ToString()); + if (recurse is not null) uri = uri.AddQuery("recurse", recurse.Value.ToString()); + if (!string.IsNullOrEmpty(to)) uri = uri.AddQuery("to", to); + + var result = await Homeserver.ClientHttpClient.GetFromJsonAsync<RecursedBatchedChunkedStateEventResponse>(uri); + 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)); + } + } + public readonly SpaceRoom AsSpace; } |