diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-06 18:29:15 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-06 18:29:15 +0200 |
commit | e5591eef3850a9796cc87386128651a828b70697 (patch) | |
tree | 7e501ec749229a3d96838265289266bb6f6ce208 /LibMatrix/Homeservers/RemoteHomeServer.cs | |
parent | Unit tests, small refactors (diff) | |
download | LibMatrix-e5591eef3850a9796cc87386128651a828b70697.tar.xz |
Small refactors
Diffstat (limited to 'LibMatrix/Homeservers/RemoteHomeServer.cs')
-rw-r--r-- | LibMatrix/Homeservers/RemoteHomeServer.cs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs index d10c837..798349a 100644 --- a/LibMatrix/Homeservers/RemoteHomeServer.cs +++ b/LibMatrix/Homeservers/RemoteHomeServer.cs @@ -1,3 +1,4 @@ +using System.Net.Http.Headers; using System.Net.Http.Json; using System.Text.Json; using System.Text.Json.Serialization; @@ -10,13 +11,18 @@ using LibMatrix.Services; namespace LibMatrix.Homeservers; public class RemoteHomeServer(string baseUrl) { + public static async Task<RemoteHomeServer> Create(string baseUrl) => + new(baseUrl) { + _httpClient = new() { + BaseAddress = new Uri(await new HomeserverResolverService().ResolveHomeserverFromWellKnown(baseUrl) + ?? throw new InvalidOperationException("Failed to resolve homeserver")), + Timeout = TimeSpan.FromSeconds(120) + } + }; private Dictionary<string, object> _profileCache { get; set; } = new(); - public string BaseUrl { get; } = baseUrl.Trim(); - public MatrixHttpClient _httpClient { get; set; } = new() { - BaseAddress = new Uri(new HomeserverResolverService().ResolveHomeserverFromWellKnown(baseUrl).Result ?? throw new InvalidOperationException("Failed to resolve homeserver")), - Timeout = TimeSpan.FromSeconds(120) - }; + public string BaseUrl { get; } = baseUrl; + public MatrixHttpClient _httpClient { get; set; } public async Task<ProfileResponseEventContent> GetProfileAsync(string mxid) { if (mxid is null) throw new ArgumentNullException(nameof(mxid)); |