From 440807e02393410327cd86d5ffa007dee98f8954 Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 19 Apr 2024 15:54:30 +0200 Subject: Partial User-Interactive Authentication, allow skipping homeserver typing --- LibMatrix/RoomTypes/GenericRoom.cs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'LibMatrix/RoomTypes') 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 GetNameAsync() => (await GetStateAsync("m.room.name"))?.Name; + public async Task GetNameAsync() => (await GetStateOrNullAsync("m.room.name"))?.Name; public async Task JoinAsync(string[]? homeservers = null, string? reason = null, bool checkIfAlreadyMember = true) { if (checkIfAlreadyMember) @@ -406,7 +406,7 @@ public class GenericRoom { } } - public Task GetEventAsync(string eventId) => Homeserver.ClientHttpClient.GetFromJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/event/{eventId}"); + public Task GetEventAsync(string eventId) => Homeserver.ClientHttpClient.GetFromJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/event/{eventId}"); public async Task RedactEventAsync(string eventToRedact, string reason) { var data = new { reason }; @@ -465,6 +465,30 @@ public class GenericRoom { #endregion + public async IAsyncEnumerable 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(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(uri.AddQuery("from", result.NextBatch)); + } + } + public readonly SpaceRoom AsSpace; } -- cgit 1.4.1