about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared/RoomListItem.razor
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-27 02:23:30 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-27 02:23:30 +0200
commitac7ed016b00941380099d9a0b2601f4bc353f39f (patch)
treea0f9fc1baee763a528aef2cd04a920815ef3906d /MatrixRoomUtils.Web/Shared/RoomListItem.razor
parentBeen a while since I last committed (diff)
downloadMatrixUtils-ac7ed016b00941380099d9a0b2601f4bc353f39f.tar.xz
Remove a bunch of caching, make room listings more reliable
Diffstat (limited to 'MatrixRoomUtils.Web/Shared/RoomListItem.razor')
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor30
1 files changed, 17 insertions, 13 deletions
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