about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Shared')
-rw-r--r--MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor6
-rw-r--r--MatrixRoomUtils.Web/Shared/NavMenu.razor10
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor30
3 files changed, 24 insertions, 22 deletions
diff --git a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
index 016b993..42f2c09 100644
--- a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
+++ b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
@@ -41,7 +41,6 @@
     {
         Console.WriteLine(User.ToJson());
         RuntimeCache.LoginSessions.Remove(User.AccessToken);
-        await LocalStorageWrapper.ReloadLocalStorage(LocalStorage);
 
         StateHasChanged();
     }
@@ -50,9 +49,8 @@
     {
         RuntimeCache.LastUsedToken = User.AccessToken;
     //RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(LocalStorageWrapper.LoginSessions[Token].LoginResponse.HomeServer);
-        await LocalStorageWrapper.ReloadLocalStorage(LocalStorage);
-
+        await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
+        await LocalStorageWrapper.InitialiseRuntimeVariables(LocalStorage);
         StateHasChanged();
     }
-
 }
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/NavMenu.razor b/MatrixRoomUtils.Web/Shared/NavMenu.razor
index 8136715..44dd9df 100644
--- a/MatrixRoomUtils.Web/Shared/NavMenu.razor
+++ b/MatrixRoomUtils.Web/Shared/NavMenu.razor
@@ -51,11 +51,11 @@
             <h5 style="margin-left: 1em;">Extra tools</h5>
             <hr style="margin-bottom: 0em;"/>
         </div>
-        <div class="nav-item px-3">
-            <NavLink class="nav-link" href="KnownHomeserverList">
-                <span class="oi oi-plus" aria-hidden="true"></span> Known homeserver list
-            </NavLink>
-        </div>
+        @* <div class="nav-item px-3"> *@
+        @*     <NavLink class="nav-link" href="KnownHomeserverList"> *@
+        @*         <span class="oi oi-plus" aria-hidden="true"></span> Known homeserver list *@
+        @*     </NavLink> *@
+        @* </div> *@
         @* <div class="nav-item px-3"> *@
         @*     <NavLink class="nav-link" href="MediaLocator"> *@
         @*         <span class="oi oi-plus" aria-hidden="true"></span> Media locator *@
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index b7394c1..4990b3c 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -43,24 +43,26 @@
     
     private bool hasOldRoomVersion { get; set; } = false;
     private bool hasDangerousRoomVersion { get; set; } = false;
+    
+    
+    private static SemaphoreSlim _semaphoreSlim = new(128);
 
     protected override async Task OnInitializedAsync()
     {
         await base.OnInitializedAsync();
-
-        if (!RuntimeCache.WasLoaded)
-        {
-            Console.WriteLine("Loading from local storage");
-            await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
-        }
-
+        await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+        
+        await _semaphoreSlim.WaitAsync();
+        
+        var hs = await new AuthenticatedHomeServer(RuntimeCache.CurrentHomeServer.UserId, RuntimeCache.CurrentHomeServer.AccessToken, RuntimeCache.CurrentHomeServer.HomeServerDomain).Configure();
+        
         if (Room == null)
         {
             if (RoomId == null)
             {
                 throw new ArgumentNullException(nameof(RoomId));
             }
-            Room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId);
+            Room = await hs.GetRoom(RoomId);
         }
         else
         {
@@ -96,7 +98,8 @@
                 var url = state.Value.GetProperty("url").GetString();
                 if (url != null)
                 {
-                    roomIcon = RuntimeCache.CurrentHomeServer.ResolveMediaUri(url);
+                    roomIcon = hs.ResolveMediaUri(url);
+                    Console.WriteLine($"Got avatar for room {RoomId}: {roomIcon} ({url})");
                 }
             }
             catch (InvalidOperationException e)
@@ -107,16 +110,16 @@
 
         if (ShowOwnProfile)
         {
-            var profile = await RuntimeCache.CurrentHomeServer.GetProfile(RuntimeCache.CurrentHomeServer.UserId, debounce: true);
+            var profile = await hs.GetProfile(hs.UserId, debounce: true);
 
-            var memberState = await Room.GetStateAsync("m.room.member", RuntimeCache.CurrentHomeServer.UserId);
+            var memberState = await Room.GetStateAsync("m.room.member", hs.UserId);
             if (memberState.HasValue)
             {
                 memberState.Value.TryGetProperty("avatar_url", out var _avatar);
                 if (_avatar.ValueKind == JsonValueKind.String)
                 {
                     hasCustomProfileAvatar = _avatar.GetString() != profile.AvatarUrl;
-                    profileAvatar = RuntimeCache.CurrentHomeServer.ResolveMediaUri(_avatar.GetString());
+                    profileAvatar = hs.ResolveMediaUri(_avatar.GetString());
                 }
                 else
                 {
@@ -135,8 +138,9 @@
                 }
             }
         }
+        _semaphoreSlim.Release();
         if (Random.Shared.Next(100) == 1)
-            await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
+            await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage);
     }
 
 }
\ No newline at end of file