about summary refs log tree commit diff
path: root/LibMatrix/Services/HomeserverProviderService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix/Services/HomeserverProviderService.cs')
-rw-r--r--LibMatrix/Services/HomeserverProviderService.cs7
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();