about summary refs log tree commit diff
path: root/LibMatrix/Homeservers/RemoteHomeServer.cs
diff options
context:
space:
mode:
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;