summary refs log tree commit diff
path: root/ModAS.Server/Services/AuthenticatedHomeserverProviderService.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-12-23 12:07:34 +0100
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-12-23 12:07:34 +0100
commita847c172069c27fccd95fc593a1b0c630a620d4f (patch)
tree78fe3f1d20af02738421eb020cedd417b51b8305 /ModAS.Server/Services/AuthenticatedHomeserverProviderService.cs
parentBasic test (diff)
downloadModAS-a847c172069c27fccd95fc593a1b0c630a620d4f.tar.xz
Transactions test
Diffstat (limited to 'ModAS.Server/Services/AuthenticatedHomeserverProviderService.cs')
-rw-r--r--ModAS.Server/Services/AuthenticatedHomeserverProviderService.cs16
1 files changed, 10 insertions, 6 deletions
diff --git a/ModAS.Server/Services/AuthenticatedHomeserverProviderService.cs b/ModAS.Server/Services/AuthenticatedHomeserverProviderService.cs
index fa8e00a..1ceb095 100644
--- a/ModAS.Server/Services/AuthenticatedHomeserverProviderService.cs
+++ b/ModAS.Server/Services/AuthenticatedHomeserverProviderService.cs
@@ -1,3 +1,4 @@
+using System.Collections.Concurrent;
 using ArcaneLibs.Extensions;
 using LibMatrix;
 using LibMatrix.Homeservers;
@@ -14,14 +15,17 @@ public class AuthenticatedHomeserverProviderService(
     AppServiceRegistration asRegistration
     ) {
     public HttpContext? _context = request.HttpContext;
-    public Dictionary<string, AuthenticatedHomeserverGeneric> KnownUsers { get; set; } = new();
+    public ConcurrentDictionary<string, AuthenticatedHomeserverGeneric> KnownUsers { get; set; } = new();
 
     public async Task<AuthenticatedHomeserverGeneric> GetImpersonatedHomeserver(string mxid) {
-        if (KnownUsers.TryGetValue(mxid, out var homeserver)) return homeserver;
-        var hs = await homeserverProviderService.GetAuthenticatedWithToken(config.ServerName, asRegistration.AsToken, config.HomeserverUrl);
-        await hs.SetImpersonate(mxid);
-        KnownUsers.TryAdd(mxid, hs);
-        return hs;
+        if (!KnownUsers.TryGetValue(mxid, out var homeserver)) {
+            homeserver = await homeserverProviderService.GetAuthenticatedWithToken(config.ServerName, asRegistration.AppServiceToken, config.HomeserverUrl);
+            KnownUsers.TryAdd(mxid, homeserver);
+        }
+        //var hs = await homeserverProviderService.GetAuthenticatedWithToken(config.ServerName, asRegistration.AsToken, config.HomeserverUrl);
+        await homeserver.SetImpersonate(mxid);
+        // KnownUsers.TryAdd(mxid, homeserver);
+        return homeserver;
     }
     
     public async Task<AuthenticatedHomeserverGeneric> GetHomeserver() {