From 4ef9ae4b396b0eb37036d4008e8cb40e468dbe73 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Fri, 9 Feb 2024 16:32:46 +0100 Subject: Apply syntax style to LibMatrix --- LibMatrix/Services/HomeserverProviderService.cs | 18 +++++++++++------- LibMatrix/Services/HomeserverResolverService.cs | 6 +++--- LibMatrix/Services/ServiceInstaller.cs | 11 ++++------- LibMatrix/Services/TieredStorageService.cs | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) (limited to 'LibMatrix/Services') diff --git a/LibMatrix/Services/HomeserverProviderService.cs b/LibMatrix/Services/HomeserverProviderService.cs index 5ac47f1..7a13816 100644 --- a/LibMatrix/Services/HomeserverProviderService.cs +++ b/LibMatrix/Services/HomeserverProviderService.cs @@ -47,9 +47,9 @@ public class HomeserverProviderService(ILogger logger sem.Release(); throw; } - + try { - if (clientVersions.UnstableFeatures.TryGetValue("gay.rory.mxapiextensions.v0", out bool a) && a) + if (clientVersions.UnstableFeatures.TryGetValue("gay.rory.mxapiextensions.v0", out var a) && a) hs = await AuthenticatedHomeserverGeneric.Create(homeserver, accessToken, proxy); else { if (serverVersion is { Server.Name: "Synapse" }) @@ -64,11 +64,13 @@ public class HomeserverProviderService(ILogger logger throw; } - if(impersonatedMxid is not null) + if (impersonatedMxid is not null) await hs.SetImpersonate(impersonatedMxid); - - lock (AuthenticatedHomeserverCache) + + lock (AuthenticatedHomeserverCache) { AuthenticatedHomeserverCache[cacheKey] = hs; + } + sem.Release(); return hs; @@ -88,10 +90,12 @@ public class HomeserverProviderService(ILogger logger hs = await RemoteHomeserver.Create(homeserver, proxy); - lock (RemoteHomeserverCache) + lock (RemoteHomeserverCache) { RemoteHomeserverCache[cacheKey] = hs; + } + sem.Release(); - + return hs; } diff --git a/LibMatrix/Services/HomeserverResolverService.cs b/LibMatrix/Services/HomeserverResolverService.cs index 9f937c5..a4a18e5 100644 --- a/LibMatrix/Services/HomeserverResolverService.cs +++ b/LibMatrix/Services/HomeserverResolverService.cs @@ -16,7 +16,7 @@ public class HomeserverResolverService(ILogger? logge public async Task ResolveHomeserverFromWellKnown(string homeserver) { if (homeserver is null) throw new ArgumentNullException(nameof(homeserver)); - WellKnownSemaphores.TryAdd(homeserver, new(1, 1)); + WellKnownSemaphores.TryAdd(homeserver, new SemaphoreSlim(1, 1)); await WellKnownSemaphores[homeserver].WaitAsync(); if (WellKnownCache.TryGetValue(homeserver, out var known)) { WellKnownSemaphores[homeserver].Release(); @@ -53,7 +53,7 @@ public class HomeserverResolverService(ILogger? logge try { var resp = await _httpClient.GetFromJsonAsync($"{homeserver}/.well-known/matrix/server"); var hs = resp.GetProperty("m.server").GetString(); - if(hs is null) throw new InvalidDataException("m.server is null"); + if (hs is null) throw new InvalidDataException("m.server is null"); if (!hs.StartsWithAnyOf("http://", "https://")) hs = $"https://{hs}"; return hs; @@ -83,4 +83,4 @@ public class HomeserverResolverService(ILogger? logge public string? Client { get; set; } public string? Server { get; set; } } -} +} \ No newline at end of file diff --git a/LibMatrix/Services/ServiceInstaller.cs b/LibMatrix/Services/ServiceInstaller.cs index 358dc2a..0f07b61 100644 --- a/LibMatrix/Services/ServiceInstaller.cs +++ b/LibMatrix/Services/ServiceInstaller.cs @@ -3,11 +3,10 @@ using Microsoft.Extensions.DependencyInjection; namespace LibMatrix.Services; public static class ServiceInstaller { - public static IServiceCollection AddRoryLibMatrixServices(this IServiceCollection services, RoryLibMatrixConfiguration? config = null) { //Check required services // if (!services.Any(x => x.ServiceType == typeof(TieredStorageService))) - // throw new Exception("[RMUCore/DI] No TieredStorageService has been registered!"); + // throw new Exception("[RMUCore/DI] No TieredStorageService has been registered!"); //Add config services.AddSingleton(config ?? new RoryLibMatrixConfiguration()); @@ -15,19 +14,17 @@ public static class ServiceInstaller { services.AddSingleton(); // if (services.First(x => x.ServiceType == typeof(TieredStorageService)).Lifetime == ServiceLifetime.Singleton) { - services.AddSingleton(); + services.AddSingleton(); // } // else { - // services.AddScoped(); + // services.AddScoped(); // } // services.AddScoped(); return services; } - - } public class RoryLibMatrixConfiguration { public string AppName { get; set; } = "Rory&::LibMatrix"; -} +} \ No newline at end of file diff --git a/LibMatrix/Services/TieredStorageService.cs b/LibMatrix/Services/TieredStorageService.cs index 280340e..9e411de 100644 --- a/LibMatrix/Services/TieredStorageService.cs +++ b/LibMatrix/Services/TieredStorageService.cs @@ -5,4 +5,4 @@ namespace LibMatrix.Services; public class TieredStorageService(IStorageProvider? cacheStorageProvider, IStorageProvider? dataStorageProvider) { public IStorageProvider? CacheStorageProvider { get; } = cacheStorageProvider; public IStorageProvider? DataStorageProvider { get; } = dataStorageProvider; -} +} \ No newline at end of file -- cgit 1.4.1