diff options
author | Rory& <root@rory.gay> | 2024-01-29 10:15:27 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-01-29 10:15:27 +0100 |
commit | 3e6a73599bb58161c08d8675ea23ee6c82c6675c (patch) | |
tree | f3c0d1e797a77ed5993478d742751d386e004fb7 /MatrixUtils.Web/Pages | |
parent | Room member migrations (diff) | |
download | MatrixUtils-3e6a73599bb58161c08d8675ea23ee6c82c6675c.tar.xz |
Room list fixes, migration fix, update available handler
Diffstat (limited to 'MatrixUtils.Web/Pages')
-rw-r--r-- | MatrixUtils.Web/Pages/Index.razor | 20 | ||||
-rw-r--r-- | MatrixUtils.Web/Pages/Rooms/Index.razor | 51 | ||||
-rw-r--r-- | MatrixUtils.Web/Pages/Tools/Index.razor (renamed from MatrixUtils.Web/Pages/Tools/ToolsIndex.razor) | 2 | ||||
-rw-r--r-- | MatrixUtils.Web/Pages/Tools/LeaveRoom.razor | 56 |
4 files changed, 104 insertions, 25 deletions
diff --git a/MatrixUtils.Web/Pages/Index.razor b/MatrixUtils.Web/Pages/Index.razor index 9c1bab6..e1cb60e 100644 --- a/MatrixUtils.Web/Pages/Index.razor +++ b/MatrixUtils.Web/Pages/Index.razor @@ -20,7 +20,7 @@ Small collection of tools to do not-so-everyday things. var _auth = session.UserAuth; <tr class="user-entry"> <td> - <img class="avatar" src="@session.UserInfo.AvatarUrl"/> + <img class="avatar" src="@session.UserInfo.AvatarUrl" crossorigin="anonymous"/> </td> <td class="user-info"> <p> @@ -108,6 +108,16 @@ Small collection of tools to do not-so-everyday things. _sessions.Clear(); _offlineSessions.Clear(); var tokens = await RMUStorage.GetAllTokens(); + if (tokens is not { Count: > 0 }) { + Console.WriteLine("No tokens found, trying migration from MRU..."); + await RMUStorage.MigrateFromMRU(); + tokens = await RMUStorage.GetAllTokens(); + if (tokens is not { Count: > 0 }) { + Console.WriteLine("No tokens found"); + return; + } + } + var profileTasks = tokens.Select(async token => { UserInfo userInfo = new(); AuthenticatedHomeserverGeneric hs; @@ -119,14 +129,13 @@ Small collection of tools to do not-so-everyday things. if (e.ErrorCode != "M_UNKNOWN_TOKEN") throw; NavigationManager.NavigateTo("/InvalidSession?ctx=" + token.AccessToken); return; - } catch (Exception e) { logger.LogError(e, $"Failed to instantiate AuthenticatedHomeserver for {token.ToJson()}, homeserver may be offline?", token.UserId); _offlineSessions.Add(token); return; } - + Console.WriteLine($"Got hs for {token.ToJson()}"); var roomCountTask = hs.GetJoinedRooms(); @@ -143,8 +152,8 @@ Small collection of tools to do not-so-everyday things. ServerVersion = await (hs.FederationClient?.GetServerVersionAsync() ?? Task.FromResult<ServerVersionResponse?>(null)), Homeserver = hs }); - }); - Console.WriteLine("Waiting for profile tasks"); + }).ToList(); + Console.WriteLine($"Waiting for {profileTasks.Count} profile tasks"); await Task.WhenAll(profileTasks); Console.WriteLine("Done waiting for profile tasks"); await base.OnInitializedAsync(); @@ -177,7 +186,6 @@ Small collection of tools to do not-so-everyday things. await OnInitializedAsync(); } - private async Task SwitchSession(UserAuth auth) { Console.WriteLine($"Switching to {auth.Homeserver} {auth.UserId} via {auth.Proxy}"); await RMUStorage.SetCurrentToken(auth); diff --git a/MatrixUtils.Web/Pages/Rooms/Index.razor b/MatrixUtils.Web/Pages/Rooms/Index.razor index 0ec9487..170f489 100644 --- a/MatrixUtils.Web/Pages/Rooms/Index.razor +++ b/MatrixUtils.Web/Pages/Rooms/Index.razor @@ -18,7 +18,13 @@ <RoomList Rooms="Rooms" GlobalProfile="@GlobalProfile" @bind-StillFetching="RenderContents"></RoomList> @code { - private ObservableCollection<RoomInfo> Rooms { get; } = new(); + + private ObservableCollection<RoomInfo> _rooms = new(); + private ObservableCollection<RoomInfo> Rooms { + get => _rooms; + set => _rooms = value; + } + private UserProfileResponse GlobalProfile { get; set; } private AuthenticatedHomeserverGeneric? Homeserver { get; set; } @@ -97,25 +103,29 @@ if (Homeserver is null) return; var rooms = await Homeserver.GetJoinedRooms(); // SemaphoreSlim _semaphore = new(160, 160); + GlobalProfile = await Homeserver.GetProfileAsync(Homeserver.WhoAmI.UserId); - var roomTasks = rooms.Select(async room => { - RoomInfo ri; - // await _semaphore.WaitAsync(); - ri = new() { Room = room }; - await Task.WhenAll((filter.Room?.State?.Types ?? []).Select(x => ri.GetStateEvent(x))); - return ri; - }).ToAsyncEnumerable(); - - await foreach (var room in roomTasks) { - Rooms.Add(room); - StateHasChanged(); - // await Task.Delay(50); - // _semaphore.Release(); + 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(); } + - if (rooms.Count >= 150) RenderContents = true; - - GlobalProfile = await Homeserver.GetProfileAsync(Homeserver.WhoAmI.UserId); + RenderContents = true; + Status = "Initial fetch done! Starting initial sync..."; + // StateHasChanged(); + await Task.Delay(1000); syncHelper = new SyncHelper(Homeserver, logger) { Timeout = 30000, Filter = filter, @@ -147,7 +157,7 @@ Console.WriteLine($"Queue no longer empty after {renderTimeSw.Elapsed}!"); - int maxUpdates = 10; + int maxUpdates = 50; isInitialSync = false; while (maxUpdates-- > 0 && queue.TryDequeue(out var queueEntry)) { var (roomId, roomData) = queueEntry; @@ -176,6 +186,8 @@ else { Console.WriteLine($"QueueWorker: could not merge state for {room.Room.RoomId} as new data contains no state events!"); } + + 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..."; @@ -212,9 +224,10 @@ } private Queue<KeyValuePair<string, SyncResponse.RoomsDataStructure.JoinedRoomDataStructure>> queue = new(); + private async Task RunSyncLoop(SyncHelper syncHelper) { - Status = "Initial syncing..."; + // Status = "Initial syncing..."; Console.WriteLine("starting sync"); var syncs = syncHelper.EnumerateSyncAsync(); diff --git a/MatrixUtils.Web/Pages/Tools/ToolsIndex.razor b/MatrixUtils.Web/Pages/Tools/Index.razor index f4092d7..f1e04a3 100644 --- a/MatrixUtils.Web/Pages/Tools/ToolsIndex.razor +++ b/MatrixUtils.Web/Pages/Tools/Index.razor @@ -6,3 +6,5 @@ <a href="/Tools/MassRoomJoin">Join room across all session</a><br/> <a href="/Tools/MediaLocator">Locate lost media</a><br/> <a href="/Tools/SpaceDebug">Debug space relationships</a><br/> +<a href="/Tools/MigrateRoom">Migrate users from a split room to a new room</a><br/> +<a href="/Tools/LeaveRoom">Leave room by ID</a><br/> diff --git a/MatrixUtils.Web/Pages/Tools/LeaveRoom.razor b/MatrixUtils.Web/Pages/Tools/LeaveRoom.razor new file mode 100644 index 0000000..b5df05f --- /dev/null +++ b/MatrixUtils.Web/Pages/Tools/LeaveRoom.razor @@ -0,0 +1,56 @@ +@page "/Tools/LeaveRoom" +@using System.Diagnostics +@using ArcaneLibs.Extensions +@using LibMatrix.Homeservers +@using LibMatrix.RoomTypes +@using System.Collections.ObjectModel +<h3>Leave room</h3> +<hr/> +<span>Room ID: </span> +<InputText @bind-Value="@RoomId"></InputText> +<br/> +<LinkButton OnClick="@Leave">Leave</LinkButton> +<br/><br/> +@foreach (var line in Log) { + <p>@line</p> +} +@code { + AuthenticatedHomeserverGeneric? hs { get; set; } + ObservableCollection<string> Log { get; set; } = new ObservableCollection<string>(); + [Parameter, SupplyParameterFromQuery(Name = "roomId")] + public string? RoomId { get; set; } + + protected override async Task OnInitializedAsync() { + hs = await RMUStorage.GetCurrentSessionOrNavigate(); + if (hs is null) return; + Log.CollectionChanged += (sender, args) => StateHasChanged(); + + StateHasChanged(); + Console.WriteLine("Rerendered!"); + await base.OnInitializedAsync(); + } + + private async Task Leave() { + if(string.IsNullOrWhiteSpace(RoomId)) return; + var room = hs.GetRoom(RoomId); + Log.Add("Got room object..."); + try { + await room.LeaveAsync(); + Log.Add("Left room!"); + } + catch (Exception e) { + Log.Add(e.ToString()); + } + + try { + await room.ForgetAsync(); + Log.Add("Forgot room!"); + } + catch (Exception e) { + Log.Add(e.ToString()); + } + + Log.Add("Done!"); + } + +} \ No newline at end of file |