about summary refs log tree commit diff
path: root/LibMatrix/Homeservers/RemoteHomeServer.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-09-15 09:50:45 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-09-15 09:50:45 +0200
commit6bd02248ccfbcb46960a6f39eaad23888d190eb5 (patch)
tree110578f31b6f9f70a7a1edab32fb3a34d6ad4f1a /LibMatrix/Homeservers/RemoteHomeServer.cs
parentMedia moderator PoC works, abstract command handling to library (diff)
downloadLibMatrix-6bd02248ccfbcb46960a6f39eaad23888d190eb5.tar.xz
Some refactoring
Diffstat (limited to 'LibMatrix/Homeservers/RemoteHomeServer.cs')
-rw-r--r--LibMatrix/Homeservers/RemoteHomeServer.cs18
1 files changed, 7 insertions, 11 deletions
diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs
index 923986d..caed397 100644
--- a/LibMatrix/Homeservers/RemoteHomeServer.cs
+++ b/LibMatrix/Homeservers/RemoteHomeServer.cs
@@ -5,28 +5,24 @@ using LibMatrix.StateEventTypes.Spec;
 
 namespace LibMatrix.Homeservers;
 
-public class RemoteHomeServer {
-    public RemoteHomeServer(string canonicalHomeServerDomain) {
-        HomeServerDomain = canonicalHomeServerDomain;
-        _httpClient = new MatrixHttpClient();
-        _httpClient.Timeout = TimeSpan.FromSeconds(5);
-    }
+public class RemoteHomeServer(string canonicalHomeServerDomain) {
+    // _httpClient.Timeout = TimeSpan.FromSeconds(5);
 
     private Dictionary<string, object> _profileCache { get; set; } = new();
-    public string HomeServerDomain { get; set; }
+    public string HomeServerDomain { get; } = canonicalHomeServerDomain.Trim();
     public string FullHomeServerDomain { get; set; }
-    public MatrixHttpClient _httpClient { get; set; }
+    public MatrixHttpClient _httpClient { get; set; } = new();
 
-    public async Task<ProfileResponseEventData> GetProfile(string mxid) {
+    public async Task<ProfileResponseEventContent> GetProfile(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 ProfileResponseEventData p) return p;
+            if (value is ProfileResponseEventContent p) return p;
         }
         _profileCache[mxid] = new SemaphoreSlim(1);
 
         var resp = await _httpClient.GetAsync($"/_matrix/client/v3/profile/{mxid}");
-        var data = await resp.Content.ReadFromJsonAsync<ProfileResponseEventData>();
+        var data = await resp.Content.ReadFromJsonAsync<ProfileResponseEventContent>();
         if (!resp.IsSuccessStatusCode) Console.WriteLine("Profile: " + data);
         _profileCache[mxid] = data;