diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-09-04 02:17:10 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-09-04 02:17:10 +0200 |
commit | 21da6cde79ccd0cb7f895a29e3d8cab959ef11ba (patch) | |
tree | fb0b89566b64ae907d7ca3ea8a29adcf0c0361d0 /LibMatrix/RoomTypes/GenericRoom.cs | |
parent | Clean up some extension functions (diff) | |
download | LibMatrix-21da6cde79ccd0cb7f895a29e3d8cab959ef11ba.tar.xz |
Too many changes to name...
Diffstat (limited to 'LibMatrix/RoomTypes/GenericRoom.cs')
-rw-r--r-- | LibMatrix/RoomTypes/GenericRoom.cs | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index df1eb52..3ba965b 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -1,22 +1,28 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; using System.Net.Http.Json; using System.Text.Json; +using System.Threading.Tasks; using System.Web; using LibMatrix.Extensions; +using LibMatrix.Homeservers; using LibMatrix.Responses; using LibMatrix.StateEventTypes.Spec; namespace LibMatrix.RoomTypes; public class GenericRoom { - internal readonly AuthenticatedHomeServer _homeServer; + internal readonly AuthenticatedHomeserverGeneric Homeserver; internal readonly MatrixHttpClient _httpClient; - public GenericRoom(AuthenticatedHomeServer homeServer, string roomId) { - _homeServer = homeServer; - _httpClient = homeServer._httpClient; + public GenericRoom(AuthenticatedHomeserverGeneric homeserver, string roomId) { + Homeserver = homeserver; + _httpClient = homeserver._httpClient; RoomId = roomId; if (GetType() != typeof(SpaceRoom)) - AsSpace = new SpaceRoom(homeServer, RoomId); + AsSpace = new SpaceRoom(homeserver, RoomId); } public string RoomId { get; set; } @@ -182,5 +188,23 @@ public class GenericRoom { return res; } + public async Task<T> GetRoomAccountData<T>(string key) { + var res = await _httpClient.GetAsync($"/_matrix/client/v3/user/{Homeserver.UserId}/rooms/{RoomId}/account_data/{key}"); + if (!res.IsSuccessStatusCode) { + Console.WriteLine($"Failed to get room account data: {await res.Content.ReadAsStringAsync()}"); + throw new InvalidDataException($"Failed to get room account data: {await res.Content.ReadAsStringAsync()}"); + } + + return await res.Content.ReadFromJsonAsync<T>(); + } + + public async Task SetRoomAccountData(string key, object data) { + var res = await _httpClient.PutAsJsonAsync($"/_matrix/client/v3/user/{Homeserver.UserId}/rooms/{RoomId}/account_data/{key}", data); + if (!res.IsSuccessStatusCode) { + Console.WriteLine($"Failed to set room account data: {await res.Content.ReadAsStringAsync()}"); + throw new InvalidDataException($"Failed to set room account data: {await res.Content.ReadAsStringAsync()}"); + } + } + public readonly SpaceRoom AsSpace; } |