diff options
author | Rory& <root@rory.gay> | 2024-05-16 11:46:45 +0200 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-05-16 11:46:45 +0200 |
commit | e1f99073f3d9788a4b48d2bb7091e3894dcefa1a (patch) | |
tree | 63eaa6ead968ca0fd3f2a85a2b6ae13bab900156 /LibMatrix | |
parent | Add valid room memberhip values as constants (diff) | |
download | LibMatrix-e1f99073f3d9788a4b48d2bb7091e3894dcefa1a.tar.xz |
Dont use refs for proxy
Diffstat (limited to 'LibMatrix')
5 files changed, 18 insertions, 13 deletions
diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs index 5520d3a..c729a44 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs @@ -19,8 +19,8 @@ using Microsoft.Extensions.Logging.Abstractions; namespace LibMatrix.Homeservers; public class AuthenticatedHomeserverGeneric : RemoteHomeserver { - public AuthenticatedHomeserverGeneric(string serverName, HomeserverResolverService.WellKnownUris wellKnownUris, ref string? proxy, string accessToken) : base(serverName, - wellKnownUris, ref proxy) { + public AuthenticatedHomeserverGeneric(string serverName, HomeserverResolverService.WellKnownUris wellKnownUris, string? proxy, string accessToken) : base(serverName, + wellKnownUris, proxy) { AccessToken = accessToken; ClientHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); @@ -42,6 +42,7 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { public string UserLocalpart => UserId.Split(":")[0][1..]; public string ServerName => UserId.Split(":", 2)[1]; + [JsonIgnore] public string AccessToken { get; set; } public HsNamedCaches NamedCaches { get; set; } = null!; diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverMxApiExtended.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverMxApiExtended.cs index f55acb8..64d11f9 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverMxApiExtended.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverMxApiExtended.cs @@ -2,5 +2,5 @@ using LibMatrix.Services; namespace LibMatrix.Homeservers; -public class AuthenticatedHomeserverMxApiExtended(string serverName, HomeserverResolverService.WellKnownUris wellKnownUris, ref string? proxy, string accessToken) - : AuthenticatedHomeserverGeneric(serverName, wellKnownUris, ref proxy, accessToken); \ No newline at end of file +public class AuthenticatedHomeserverMxApiExtended(string serverName, HomeserverResolverService.WellKnownUris wellKnownUris, string? proxy, string accessToken) + : AuthenticatedHomeserverGeneric(serverName, wellKnownUris, proxy, accessToken); \ No newline at end of file diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs index 307a226..83ebf20 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverSynapse.cs @@ -9,8 +9,8 @@ namespace LibMatrix.Homeservers; public class AuthenticatedHomeserverSynapse : AuthenticatedHomeserverGeneric { public readonly SynapseAdminApiClient Admin; - public AuthenticatedHomeserverSynapse(string serverName, HomeserverResolverService.WellKnownUris wellKnownUris, ref string? proxy, string accessToken) : base(serverName, - wellKnownUris, ref proxy, accessToken) { + public AuthenticatedHomeserverSynapse(string serverName, HomeserverResolverService.WellKnownUris wellKnownUris, string? proxy, string accessToken) : base(serverName, + wellKnownUris, proxy, accessToken) { Admin = new(this); } diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs index c29137c..8669ca7 100644 --- a/LibMatrix/Homeservers/RemoteHomeServer.cs +++ b/LibMatrix/Homeservers/RemoteHomeServer.cs @@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging.Abstractions; namespace LibMatrix.Homeservers; public class RemoteHomeserver { - public RemoteHomeserver(string baseUrl, HomeserverResolverService.WellKnownUris wellKnownUris, ref string? proxy) { + public RemoteHomeserver(string baseUrl, HomeserverResolverService.WellKnownUris wellKnownUris, string? proxy) { if (string.IsNullOrWhiteSpace(proxy)) proxy = null; BaseUrl = baseUrl; @@ -31,8 +31,12 @@ public class RemoteHomeserver { private Dictionary<string, object> _profileCache { get; set; } = new(); public string BaseUrl { get; } + [JsonIgnore] public MatrixHttpClient ClientHttpClient { get; set; } + + [JsonIgnore] public FederationClient? FederationClient { get; set; } + public HomeserverResolverService.WellKnownUris WellKnownUris { get; set; } public async Task<UserProfileResponse> GetProfileAsync(string mxid, bool useCache = false) { diff --git a/LibMatrix/Services/HomeserverProviderService.cs b/LibMatrix/Services/HomeserverProviderService.cs index 9867184..3e42c21 100644 --- a/LibMatrix/Services/HomeserverProviderService.cs +++ b/LibMatrix/Services/HomeserverProviderService.cs @@ -19,7 +19,7 @@ public class HomeserverProviderService(ILogger<HomeserverProviderService> logger return await AuthenticatedHomeserverCache.GetOrAdd($"{homeserver}{accessToken}{proxy}{impersonatedMxid}", async () => { var wellKnownUris = await hsResolver.ResolveHomeserverFromWellKnown(homeserver, enableClient, enableServer); - var rhs = new RemoteHomeserver(homeserver, wellKnownUris, ref proxy); + var rhs = new RemoteHomeserver(homeserver, wellKnownUris, proxy); AuthenticatedHomeserverGeneric? hs = null; if (!useGeneric) { @@ -42,10 +42,10 @@ public class HomeserverProviderService(ILogger<HomeserverProviderService> logger try { if (clientVersions.UnstableFeatures.TryGetValue("gay.rory.mxapiextensions.v0", out var a) && a) - hs = new AuthenticatedHomeserverMxApiExtended(homeserver, wellKnownUris, ref proxy, accessToken); + hs = new AuthenticatedHomeserverMxApiExtended(homeserver, wellKnownUris, proxy, accessToken); else { if (serverVersion is { Server.Name: "Synapse" }) - hs = new AuthenticatedHomeserverSynapse(homeserver, wellKnownUris, ref proxy, accessToken); + hs = new AuthenticatedHomeserverSynapse(homeserver, wellKnownUris, proxy, accessToken); } } catch (Exception e) { @@ -54,7 +54,7 @@ public class HomeserverProviderService(ILogger<HomeserverProviderService> logger } } - hs ??= new AuthenticatedHomeserverGeneric(homeserver, wellKnownUris, ref proxy, accessToken); + hs ??= new AuthenticatedHomeserverGeneric(homeserver, wellKnownUris, proxy, accessToken); await hs.Initialise(); @@ -68,8 +68,8 @@ public class HomeserverProviderService(ILogger<HomeserverProviderService> logger public async Task<RemoteHomeserver> GetRemoteHomeserver(string homeserver, string? proxy = null, bool useCache = true, bool enableServer = true) => useCache ? await RemoteHomeserverCache.GetOrAdd($"{homeserver}{proxy}", - async () => { return new RemoteHomeserver(homeserver, await hsResolver.ResolveHomeserverFromWellKnown(homeserver, enableServer: enableServer), ref proxy); }) - : new RemoteHomeserver(homeserver, await hsResolver.ResolveHomeserverFromWellKnown(homeserver, enableServer: enableServer), ref proxy); + async () => { return new RemoteHomeserver(homeserver, await hsResolver.ResolveHomeserverFromWellKnown(homeserver, enableServer: enableServer), proxy); }) + : new RemoteHomeserver(homeserver, await hsResolver.ResolveHomeserverFromWellKnown(homeserver, enableServer: enableServer), proxy); public async Task<FederationClient> GetFederationClient(string homeserver, string keyId, string? proxy = null, bool useCache = true) => useCache |