about summary refs log tree commit diff
path: root/LibMatrix/Services/WellKnownResolvers
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-03-09 17:24:34 +0100
committerRory& <root@rory.gay>2025-03-09 17:24:34 +0100
commitdb835755e01b13dcb8d33a91f57ae8f20b931c57 (patch)
tree9a7bb90b919bef042b4bfc064f603e760a472cc9 /LibMatrix/Services/WellKnownResolvers
parentWell known resolver rewrite work (diff)
downloadLibMatrix-db835755e01b13dcb8d33a91f57ae8f20b931c57.tar.xz
Well known resolver work, synapse admin work
Diffstat (limited to 'LibMatrix/Services/WellKnownResolvers')
-rw-r--r--LibMatrix/Services/WellKnownResolvers/ClientWellKnownResolver.cs53
-rw-r--r--LibMatrix/Services/WellKnownResolvers/SupportWellKnownResolver.cs54
2 files changed, 0 insertions, 107 deletions
diff --git a/LibMatrix/Services/WellKnownResolvers/ClientWellKnownResolver.cs b/LibMatrix/Services/WellKnownResolvers/ClientWellKnownResolver.cs
deleted file mode 100644

index d4d0166..0000000 --- a/LibMatrix/Services/WellKnownResolvers/ClientWellKnownResolver.cs +++ /dev/null
@@ -1,53 +0,0 @@ -using System.Text.Json.Serialization; -using ArcaneLibs.Collections; -using LibMatrix.Extensions; -using Microsoft.Extensions.Logging; - -namespace LibMatrix.Services.WellKnownResolvers; - -public class ClientWellKnownResolver(ILogger<ClientWellKnownResolver> logger) { - private static readonly SemaphoreCache<WellKnownResolutionResult> ClientWellKnownCache = new() { - StoreNulls = false - }; - private static readonly MatrixHttpClient HttpClient = new(); - - public Task<WellKnownResolutionResult> TryResolveClientWellKnown(string homeserver) { - return ClientWellKnownCache.TryGetOrAdd(homeserver, async () => { - logger.LogTrace($"Resolving client well-known: {homeserver}"); - if ((await TryGetClientWellKnownFromHttps(homeserver)) is { } clientWellKnown) - return new() { - Source = WellKnownResolverService.WellKnownSource.Https, - WellKnown = clientWellKnown - }; - - return default!; - }); - } - - private async Task<ClientWellKnown?> TryGetClientWellKnownFromHttps(string homeserver) { - try { - return await HttpClient.TryGetFromJsonAsync<ClientWellKnown>($"https://{homeserver}/.well-known/matrix/client"); - } - catch { - return null; - } - } - - - - public class ClientWellKnown { - [JsonPropertyName("m.homeserver")] - public required WellKnownHomeserver Homeserver { get; set; } - - public class WellKnownHomeserver { - [JsonPropertyName("base_url")] - public required string BaseUrl { get; set; } - } - } - - public struct WellKnownResolutionResult { - public WellKnownResolverService.WellKnownSource Source { get; set; } - public ClientWellKnown WellKnown { get; set; } - public List<WellKnownResolverService.WellKnownResolutionWarning> Warnings { get; set; } - } -} \ No newline at end of file diff --git a/LibMatrix/Services/WellKnownResolvers/SupportWellKnownResolver.cs b/LibMatrix/Services/WellKnownResolvers/SupportWellKnownResolver.cs deleted file mode 100644
index 1d7567a..0000000 --- a/LibMatrix/Services/WellKnownResolvers/SupportWellKnownResolver.cs +++ /dev/null
@@ -1,54 +0,0 @@ -using System.Text.Json.Serialization; -using ArcaneLibs.Collections; -using LibMatrix.Extensions; -using Microsoft.Extensions.Logging; - -namespace LibMatrix.Services.WellKnownResolvers; - -public class SupportWellKnownResolver(ILogger<SupportWellKnownResolver> logger) { - private static readonly SemaphoreCache<WellKnownResolverService.WellKnownResolutionResult<SupportWellKnown>> ClientWellKnownCache = new() { - StoreNulls = false - }; - - private static readonly MatrixHttpClient HttpClient = new(); - - public Task<WellKnownResolverService.WellKnownResolutionResult<SupportWellKnown>> TryResolveClientWellKnown(string homeserver) { - return ClientWellKnownCache.TryGetOrAdd(homeserver, async () => { - logger.LogTrace($"Resolving client well-known: {homeserver}"); - if ((await TryGetClientWellKnownFromHttps(homeserver)) is { } clientWellKnown) - return new() { - Source = WellKnownResolverService.WellKnownSource.Https, - WellKnown = clientWellKnown - }; - return default!; - }); - } - - private async Task<SupportWellKnown?> TryGetClientWellKnownFromHttps(string homeserver) { - try { - return await HttpClient.TryGetFromJsonAsync<SupportWellKnown>($"https://{homeserver}/.well-known/matrix/support"); - } - catch { - return null; - } - } - - public struct SupportWellKnown { - [JsonPropertyName("contacts")] - public List<WellKnownContact>? Contacts { get; set; } - - [JsonPropertyName("support_page")] - public Uri? SupportPage { get; set; } - - public class WellKnownContact { - [JsonPropertyName("email_address")] - public string? EmailAddress { get; set; } - - [JsonPropertyName("matrix_id")] - public string? MatrixId { get; set; } - - [JsonPropertyName("role")] - public required string Role { get; set; } - } - } -} \ No newline at end of file