Add more stuff, add unit tests
1 files changed, 23 insertions, 4 deletions
diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs
index caed397..ab3ab51 100644
--- a/LibMatrix/Homeservers/RemoteHomeServer.cs
+++ b/LibMatrix/Homeservers/RemoteHomeServer.cs
@@ -1,7 +1,9 @@
using System.Net.Http.Json;
+using System.Text.Json.Serialization;
+using ArcaneLibs.Extensions;
+using LibMatrix.EventTypes.Spec.State;
using LibMatrix.Extensions;
using LibMatrix.Responses;
-using LibMatrix.StateEventTypes.Spec;
namespace LibMatrix.Homeservers;
@@ -13,12 +15,13 @@ public class RemoteHomeServer(string canonicalHomeServerDomain) {
public string FullHomeServerDomain { get; set; }
public MatrixHttpClient _httpClient { get; set; } = new();
- public async Task<ProfileResponseEventContent> GetProfile(string mxid) {
- if(mxid is null) throw new ArgumentNullException(nameof(mxid));
+ public async Task<ProfileResponseEventContent> GetProfileAsync(string mxid) {
+ if (mxid is null) throw new ArgumentNullException(nameof(mxid));
if (_profileCache.TryGetValue(mxid, out var value)) {
if (value is SemaphoreSlim s) await s.WaitAsync();
if (value is ProfileResponseEventContent p) return p;
}
+
_profileCache[mxid] = new SemaphoreSlim(1);
var resp = await _httpClient.GetAsync($"/_matrix/client/v3/profile/{mxid}");
@@ -29,10 +32,26 @@ public class RemoteHomeServer(string canonicalHomeServerDomain) {
return data;
}
- public async Task<ClientVersionsResponse> GetClientVersions() {
+ public async Task<ClientVersionsResponse> GetClientVersionsAsync() {
var resp = await _httpClient.GetAsync($"/_matrix/client/versions");
var data = await resp.Content.ReadFromJsonAsync<ClientVersionsResponse>();
if (!resp.IsSuccessStatusCode) Console.WriteLine("ClientVersions: " + data);
return data;
}
+
+ public async Task<AliasResult> ResolveRoomAliasAsync(string alias) {
+ var resp = await _httpClient.GetAsync($"/_matrix/client/v3/directory/room/{alias.Replace("#", "%23")}");
+ var data = await resp.Content.ReadFromJsonAsync<AliasResult>();
+ var text = await resp.Content.ReadAsStringAsync();
+ if (!resp.IsSuccessStatusCode) Console.WriteLine("ResolveAlias: " + data.ToJson());
+ return data;
+ }
+}
+
+public class AliasResult {
+ [JsonPropertyName("room_id")]
+ public string RoomId { get; set; } = null!;
+
+ [JsonPropertyName("servers")]
+ public List<string> Servers { get; set; } = null!;
}
|