diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-12-27 19:45:22 +0100 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-12-27 19:45:22 +0100 |
commit | 94b83d4de5e435796da9cc14667c1023a09df8eb (patch) | |
tree | 359f0d41431d4f647dddd213ab44f20780531ccd /LibMatrix/Services | |
parent | SetImpersonate optimisation (dont execute if already set), cleanup (diff) | |
download | LibMatrix-94b83d4de5e435796da9cc14667c1023a09df8eb.tar.xz |
Cleanup
Diffstat (limited to 'LibMatrix/Services')
-rw-r--r-- | LibMatrix/Services/HomeserverProviderService.cs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/LibMatrix/Services/HomeserverProviderService.cs b/LibMatrix/Services/HomeserverProviderService.cs index 983f469..dc4acb1 100644 --- a/LibMatrix/Services/HomeserverProviderService.cs +++ b/LibMatrix/Services/HomeserverProviderService.cs @@ -13,8 +13,8 @@ public class HomeserverProviderService(ILogger<HomeserverProviderService> logger private static readonly Dictionary<string, SemaphoreSlim> RemoteHomeserverSemaphore = new(); private static readonly Dictionary<string, RemoteHomeserver> RemoteHomeserverCache = new(); - public async Task<AuthenticatedHomeserverGeneric> GetAuthenticatedWithToken(string homeserver, string accessToken, string? proxy = null) { - var cacheKey = homeserver + accessToken + proxy; + public async Task<AuthenticatedHomeserverGeneric> GetAuthenticatedWithToken(string homeserver, string accessToken, string? proxy = null, string? impersonatedMxid = null) { + var cacheKey = homeserver + accessToken + proxy + impersonatedMxid; var sem = AuthenticatedHomeserverSemaphore.GetOrCreate(cacheKey, _ => new SemaphoreSlim(1, 1)); await sem.WaitAsync(); AuthenticatedHomeserverGeneric? hs; @@ -43,6 +43,9 @@ public class HomeserverProviderService(ILogger<HomeserverProviderService> logger hs = await AuthenticatedHomeserverGeneric.Create<AuthenticatedHomeserverGeneric>(homeserver, accessToken, proxy); } + if(impersonatedMxid is not null) + await hs.SetImpersonate(impersonatedMxid); + lock (AuthenticatedHomeserverCache) AuthenticatedHomeserverCache[cacheKey] = hs; sem.Release(); |