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;
}
diff --git a/LibMatrix/RoomTypes/SpaceRoom.cs b/LibMatrix/RoomTypes/SpaceRoom.cs
index 5393ee7..017a123 100644
--- a/LibMatrix/RoomTypes/SpaceRoom.cs
+++ b/LibMatrix/RoomTypes/SpaceRoom.cs
@@ -1,13 +1,17 @@
+using System.Collections.Generic;
+using System.Threading;
+using ArcaneLibs.Extensions;
using LibMatrix.Extensions;
+using LibMatrix.Homeservers;
namespace LibMatrix.RoomTypes;
public class SpaceRoom : GenericRoom {
- private new readonly AuthenticatedHomeServer _homeServer;
+ private new readonly AuthenticatedHomeserverGeneric _homeserver;
private readonly GenericRoom _room;
- public SpaceRoom(AuthenticatedHomeServer homeServer, string roomId) : base(homeServer, roomId) {
- _homeServer = homeServer;
+ public SpaceRoom(AuthenticatedHomeserverGeneric homeserver, string roomId) : base(homeserver, roomId) {
+ _homeserver = homeserver;
}
private static SemaphoreSlim _semaphore = new(1, 1);
@@ -18,7 +22,7 @@ public class SpaceRoom : GenericRoom {
await foreach (var stateEvent in state) {
if (stateEvent.Type != "m.space.child") continue;
if (stateEvent.RawContent.ToJson() != "{}" || includeRemoved)
- yield return await _homeServer.GetRoom(stateEvent.StateKey);
+ yield return await _homeserver.GetRoom(stateEvent.StateKey);
}
_semaphore.Release();
}
|