diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-13 01:49:10 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-06-13 01:49:10 +0200 |
commit | fc749b3e57098740377e6eabd5d010d133256fa5 (patch) | |
tree | cc97267a3d4222c910769e46bdb37c96c7c31531 /MatrixRoomUtils.Core/Room.cs | |
parent | unknown changes (diff) | |
download | MatrixUtils-fc749b3e57098740377e6eabd5d010d133256fa5.tar.xz |
Improved many features
Diffstat (limited to 'MatrixRoomUtils.Core/Room.cs')
-rw-r--r-- | MatrixRoomUtils.Core/Room.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Core/Room.cs b/MatrixRoomUtils.Core/Room.cs index 73a2bc5..f228271 100644 --- a/MatrixRoomUtils.Core/Room.cs +++ b/MatrixRoomUtils.Core/Room.cs @@ -42,6 +42,21 @@ public class Room if (res == null) return default; return res.Value.Deserialize<T>(); } + + public async Task<MessagesResponse> GetMessagesAsync(string from = "", int limit = 10, string dir = "b", string filter = "") + { + var url = $"/_matrix/client/r0/rooms/{RoomId}/messages?from={from}&limit={limit}&dir={dir}"; + if (!string.IsNullOrEmpty(filter)) url += $"&filter={filter}"; + var res = await _httpClient.GetAsync(url); + if (!res.IsSuccessStatusCode) + { + Console.WriteLine($"Failed to get messages for {RoomId} - got status: {res.StatusCode}"); + throw new Exception($"Failed to get messages for {RoomId} - got status: {res.StatusCode}"); + } + + var result = await res.Content.ReadFromJsonAsync<MessagesResponse>(); + return result ?? new MessagesResponse(); + } public async Task<string> GetNameAsync() { @@ -148,6 +163,18 @@ public class Room } } +public class MessagesResponse +{ + [JsonPropertyName("start")] + public string Start { get; set; } + [JsonPropertyName("end")] + public string? End { get; set; } + [JsonPropertyName("chunk")] + public List<StateEventResponse> Chunk { get; set; } = new(); + [JsonPropertyName("state")] + public List<StateEventResponse> State { get; set; } = new(); +} + public class CreateEvent { [JsonPropertyName("creator")] public string Creator { get; set; } |