about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Rooms/Index.razor
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixUtils.Web/Pages/Rooms/Index.razor')
-rw-r--r--MatrixUtils.Web/Pages/Rooms/Index.razor80
1 files changed, 27 insertions, 53 deletions
diff --git a/MatrixUtils.Web/Pages/Rooms/Index.razor b/MatrixUtils.Web/Pages/Rooms/Index.razor
index 170f489..c3deb40 100644
--- a/MatrixUtils.Web/Pages/Rooms/Index.razor
+++ b/MatrixUtils.Web/Pages/Rooms/Index.razor
@@ -6,6 +6,7 @@
 @using System.Collections.ObjectModel
 @using System.Diagnostics
 @using ArcaneLibs.Extensions
+@using LibMatrix.Utilities
 @using MatrixUtils.Abstractions
 @inject ILogger<Index> logger
 <h3>Room list</h3>
@@ -18,8 +19,9 @@
 <RoomList Rooms="Rooms" GlobalProfile="@GlobalProfile" @bind-StillFetching="RenderContents"></RoomList>
 
 @code {
-    
+
     private ObservableCollection<RoomInfo> _rooms = new();
+
     private ObservableCollection<RoomInfo> Rooms {
         get => _rooms;
         set => _rooms = value;
@@ -29,39 +31,7 @@
 
     private AuthenticatedHomeserverGeneric? Homeserver { get; set; }
 
-    private static SyncFilter filter = new() {
-        AccountData = new SyncFilter.EventFilter {
-            NotTypes = new List<string> { "*" },
-            Limit = 1
-        },
-        Presence = new SyncFilter.EventFilter {
-            NotTypes = new List<string> { "*" },
-            Limit = 1
-        },
-        Room = new SyncFilter.RoomFilter {
-            AccountData = new SyncFilter.RoomFilter.StateFilter {
-                NotTypes = new List<string> { "*" },
-                Limit = 1
-            },
-            Ephemeral = new SyncFilter.RoomFilter.StateFilter {
-                NotTypes = new List<string> { "*" },
-                Limit = 1
-            },
-            State = new SyncFilter.RoomFilter.StateFilter {
-                Types = new List<string> {
-                    "m.room.create",
-                    "m.room.name",
-                    "m.room.avatar",
-                    "org.matrix.mjolnir.shortcode",
-                    "m.room.power_levels",
-                }
-            },
-            Timeline = new SyncFilter.RoomFilter.StateFilter {
-                NotTypes = new List<string> { "*" },
-                Limit = 1
-            }
-        }
-    };
+    // private static SyncFilter filter = 
 
     // private static SyncFilter profileUpdateFilter = new() {
     //     AccountData = new SyncFilter.EventFilter {
@@ -105,22 +75,23 @@
         // SemaphoreSlim _semaphore = new(160, 160);
         GlobalProfile = await Homeserver.GetProfileAsync(Homeserver.WhoAmI.UserId);
 
-        Rooms = new ObservableCollection<RoomInfo>(rooms.Select(x => new RoomInfo() { Room = x }));
-        foreach (var stateType in filter.Room?.State?.Types ?? []) {
-            var tasks = Rooms.Select(async room => {
-                try {
-                    
-                    await room.GetStateEvent(stateType);
-                }
-                catch (Exception e) {
-                    Console.WriteLine($"Failed to get state event {stateType} for room {room.Room.RoomId}: {e}");
-                }
-            });
-            await Task.WhenAll(tasks);
-            Status = $"Fetched all {stateType} events...";
-            // StateHasChanged();
-        }
+        var filter = await Homeserver.GetOrUploadNamedFilterIdAsync(CommonSyncFilters.GetBasicRoomInfo);
+        var filterData = await Homeserver.GetFilterAsync(filter);
         
+        Rooms = new ObservableCollection<RoomInfo>(rooms.Select(x => new RoomInfo() { Room = x }));
+        // foreach (var stateType in filterData.Room?.State?.Types ?? []) {
+        //     var tasks = Rooms.Select(async room => {
+        //         try {
+        //             await room.GetStateEvent(stateType);
+        //         }
+        //         catch (Exception e) {
+        //             Console.WriteLine($"Failed to get state event {stateType} for room {room.Room.RoomId}: {e}");
+        //         }
+        //     });
+        //     await Task.WhenAll(tasks);
+        //     Status = $"Fetched all {stateType} events...";
+        //     // StateHasChanged();
+        // }
 
         RenderContents = true;
         Status = "Initial fetch done! Starting initial sync...";
@@ -128,7 +99,7 @@
         await Task.Delay(1000);
         syncHelper = new SyncHelper(Homeserver, logger) {
             Timeout = 30000,
-            Filter = filter,
+            FilterId = filter,
             MinimumDelay = TimeSpan.FromMilliseconds(5000)
         };
         //  profileSyncHelper = new SyncHelper(Homeserver, logger) {
@@ -189,8 +160,9 @@
 
                     await Task.Delay(100);
                 }
+
                 Console.WriteLine($"QueueWorker: {queue.Count} entries left in queue, {maxUpdates} maxUpdates left, RenderContents: {RenderContents}");
-                    Status = $"Got {Rooms.Count} rooms so far! {queue.Count} entries in processing queue...";
+                Status = $"Got {Rooms.Count} rooms so far! {queue.Count} entries in processing queue...";
 
                 RenderContents |= queue.Count == 0;
                 await Task.Delay(Rooms.Count);
@@ -224,7 +196,6 @@
     }
 
     private Queue<KeyValuePair<string, SyncResponse.RoomsDataStructure.JoinedRoomDataStructure>> queue = new();
-    
 
     private async Task RunSyncLoop(SyncHelper syncHelper) {
         // Status = "Initial syncing...";
@@ -235,6 +206,8 @@
             Console.WriteLine("trying sync");
             if (sync is null) continue;
 
+            var filter = await Homeserver.GetFilterAsync(syncHelper.FilterId);
+            
             Status = $"Got sync with {sync.Rooms?.Join?.Count ?? 0} room updates, next batch: {sync.NextBatch}!";
             if (sync?.Rooms?.Join != null)
                 foreach (var joinedRoom in sync.Rooms.Join)
@@ -248,7 +221,8 @@
 
                         queue.Enqueue(joinedRoom);
                     }
-            if (sync.Rooms.Leave is {Count: > 0})
+
+            if (sync.Rooms.Leave is { Count: > 0 })
                 foreach (var leftRoom in sync.Rooms.Leave)
                     if (Rooms.Any(x => x.Room.RoomId == leftRoom.Key))
                         Rooms.Remove(Rooms.First(x => x.Room.RoomId == leftRoom.Key));