From 6bd02248ccfbcb46960a6f39eaad23888d190eb5 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 15 Sep 2023 09:50:45 +0200 Subject: Some refactoring --- LibMatrix/Homeservers/RemoteHomeServer.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'LibMatrix/Homeservers/RemoteHomeServer.cs') 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 _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 GetProfile(string mxid) { + public async Task 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(); + var data = await resp.Content.ReadFromJsonAsync(); if (!resp.IsSuccessStatusCode) Console.WriteLine("Profile: " + data); _profileCache[mxid] = data; -- cgit 1.4.1