From 21da6cde79ccd0cb7f895a29e3d8cab959ef11ba Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 4 Sep 2023 02:17:10 +0200 Subject: Too many changes to name... --- LibMatrix/RoomTypes/GenericRoom.cs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'LibMatrix/RoomTypes/GenericRoom.cs') 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 GetRoomAccountData(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(); + } + + 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; } -- cgit 1.4.1