From 41c5a84dacfd036b8d8f01f72226ac5a519995e3 Mon Sep 17 00:00:00 2001 From: Rory& Date: Tue, 14 May 2024 17:49:09 +0200 Subject: Organise tools somewhat, set proper icons for nav menu --- MatrixUtils.Web/Pages/Rooms/Index2.razor | 87 --------- .../MainTabComponents/MainTabSpaceItem.razor | 56 ------ .../MainTabComponents/MainTabSpaceItem.razor.css | 29 --- .../RoomsIndex2ByRoomTypeTab.razor | 53 ------ .../Rooms/Index2Components/RoomsIndex2DMsTab.razor | 53 ------ .../Index2Components/RoomsIndex2MainTab.razor | 210 --------------------- .../Index2Components/RoomsIndex2MainTab.razor.css | 0 .../RoomsIndex2SyncContainer.razor | 202 -------------------- 8 files changed, 690 deletions(-) delete mode 100644 MatrixUtils.Web/Pages/Rooms/Index2.razor delete mode 100644 MatrixUtils.Web/Pages/Rooms/Index2Components/MainTabComponents/MainTabSpaceItem.razor delete mode 100644 MatrixUtils.Web/Pages/Rooms/Index2Components/MainTabComponents/MainTabSpaceItem.razor.css delete mode 100644 MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2ByRoomTypeTab.razor delete mode 100644 MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2DMsTab.razor delete mode 100644 MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2MainTab.razor delete mode 100644 MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2MainTab.razor.css delete mode 100644 MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2SyncContainer.razor (limited to 'MatrixUtils.Web/Pages/Rooms') diff --git a/MatrixUtils.Web/Pages/Rooms/Index2.razor b/MatrixUtils.Web/Pages/Rooms/Index2.razor deleted file mode 100644 index 98b8a1d..0000000 --- a/MatrixUtils.Web/Pages/Rooms/Index2.razor +++ /dev/null @@ -1,87 +0,0 @@ -@page "/Rooms2" -@using LibMatrix.Responses -@using System.Collections.ObjectModel -@using System.ComponentModel -@using MatrixUtils.Abstractions -@using MatrixUtils.Web.Pages.Rooms.Index2Components -@inject ILogger logger -

Room list

- - -@if (Data.Homeserver is null || Data.GlobalProfile is null) { -

Creating homeserver instance and fetching global profile...

- return; -} - -
- Main - DMs - By room type -
-
- - @switch (SelectedTab) { - case Tab.Main: -

Main tab

- - break; - case Tab.DMs: -

DMs tab

- - break; - case Tab.ByRoomType: -

By room type tab

- - break; - default: - throw new InvalidEnumArgumentException(); - } -
-
- -@* Create new room *@ - - -@code { - - private Tab SelectedTab { - get => _selectedTab; - set { - _selectedTab = value; - StateHasChanged(); - } - } - - public RoomListViewData Data { get; set; } = new RoomListViewData(); - - protected override async Task OnInitializedAsync() { - Data.Homeserver = await RMUStorage.GetCurrentSessionOrNavigate(); - if (Data.Homeserver is null) return; - var rooms = await Data.Homeserver.GetJoinedRooms(); - Data.GlobalProfile = await Data.Homeserver.GetProfileAsync(Data.Homeserver.WhoAmI.UserId); - - foreach (var room in rooms) { - Data.Rooms.Add(new RoomInfo(room)); - } - StateHasChanged(); - - await base.OnInitializedAsync(); - } - - private Tab _selectedTab = Tab.Main; - - private enum Tab { - Main, - DMs, - ByRoomType - } - - public class RoomListViewData { - public ObservableCollection Rooms { get; } = []; - - public UserProfileResponse? GlobalProfile { get; set; } - - public AuthenticatedHomeserverGeneric? Homeserver { get; set; } - } - -} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/Index2Components/MainTabComponents/MainTabSpaceItem.razor b/MatrixUtils.Web/Pages/Rooms/Index2Components/MainTabComponents/MainTabSpaceItem.razor deleted file mode 100644 index 6483f01..0000000 --- a/MatrixUtils.Web/Pages/Rooms/Index2Components/MainTabComponents/MainTabSpaceItem.razor +++ /dev/null @@ -1,56 +0,0 @@ -@using MatrixUtils.Abstractions -
-
- @if (IsSpaceOpened()) { - - } - else { - - } - - - @Space.RoomName -
- @if (IsSpaceOpened()) { - meow - } -
- -@code { - - [Parameter] - public RoomInfo Space { get; set; } - - [Parameter] - public RoomInfo SelectedSpace { get; set; } - - [Parameter] - public EventCallback SelectedSpaceChanged { get; set; } - - [Parameter] - public List OpenedSpaces { get; set; } - - protected override Task OnInitializedAsync() { - Space.PropertyChanged += (sender, args) => { StateHasChanged(); }; - return base.OnInitializedAsync(); - } - - public void ToggleSpace() { - if (OpenedSpaces.Contains(Space)) { - OpenedSpaces.Remove(Space); - } - else { - OpenedSpaces.Add(Space); - } - } - - public void SelectSpace() { - SelectedSpace = Space; - SelectedSpaceChanged.InvokeAsync(Space); - } - - public bool IsSpaceOpened() { - return OpenedSpaces.Contains(Space); - } - -} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/Index2Components/MainTabComponents/MainTabSpaceItem.razor.css b/MatrixUtils.Web/Pages/Rooms/Index2Components/MainTabComponents/MainTabSpaceItem.razor.css deleted file mode 100644 index d6e413f..0000000 --- a/MatrixUtils.Web/Pages/Rooms/Index2Components/MainTabComponents/MainTabSpaceItem.razor.css +++ /dev/null @@ -1,29 +0,0 @@ -.spaceNameEllipsis { - padding-left: 8px; - display: inline-block; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - vertical-align: middle; - width: calc(100% - 64px); -} - -.spaceListItem { - display: block; - width: 100%; - height: 3em; -} - -.spaceListItemContainer { - display: flex; - align-items: center; - vertical-align: center; - justify-content: space-between; - padding: 0 16px; - width: 100%; - height: 100%; -} - -.spaceListItem > img { - display: inline-block; -} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2ByRoomTypeTab.razor b/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2ByRoomTypeTab.razor deleted file mode 100644 index f4cf849..0000000 --- a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2ByRoomTypeTab.razor +++ /dev/null @@ -1,53 +0,0 @@ -@using MatrixUtils.Abstractions -@using System.Security.Cryptography -@using ArcaneLibs.Extensions -

RoomsIndex2MainTab

- -
-
-
- Uncategorised rooms - @foreach (var space in Data.Rooms.Where(x => x.RoomType == "m.space")) { -
-

@space.RoomName

-
- } -
-
-

omae wa mou shindeiru

-
-
-
- -@code { - - [CascadingParameter] - public Index2.RoomListViewData Data { get; set; } = null!; - - protected override async Task OnInitializedAsync() { - Data.Rooms.CollectionChanged += (sender, args) => { - DebouncedStateHasChanged(); - if (args.NewItems is { Count: > 0 }) - foreach (var newItem in args.NewItems) { - (newItem as RoomInfo).PropertyChanged += (sender, args) => { DebouncedStateHasChanged(); }; - } - }; - await base.OnInitializedAsync(); - } - - //debounce StateHasChanged, we dont want to reredner on every key stroke - - private CancellationTokenSource _debounceCts = new CancellationTokenSource(); - - private async Task DebouncedStateHasChanged() { - _debounceCts.Cancel(); - _debounceCts = new CancellationTokenSource(); - try { - await Task.Delay(100, _debounceCts.Token); - Console.WriteLine("DebouncedStateHasChanged - Calling StateHasChanged!"); - StateHasChanged(); - } - catch (TaskCanceledException) { } - } - -} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2DMsTab.razor b/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2DMsTab.razor deleted file mode 100644 index f4cf849..0000000 --- a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2DMsTab.razor +++ /dev/null @@ -1,53 +0,0 @@ -@using MatrixUtils.Abstractions -@using System.Security.Cryptography -@using ArcaneLibs.Extensions -

RoomsIndex2MainTab

- -
-
-
- Uncategorised rooms - @foreach (var space in Data.Rooms.Where(x => x.RoomType == "m.space")) { -
-

@space.RoomName

-
- } -
-
-

omae wa mou shindeiru

-
-
-
- -@code { - - [CascadingParameter] - public Index2.RoomListViewData Data { get; set; } = null!; - - protected override async Task OnInitializedAsync() { - Data.Rooms.CollectionChanged += (sender, args) => { - DebouncedStateHasChanged(); - if (args.NewItems is { Count: > 0 }) - foreach (var newItem in args.NewItems) { - (newItem as RoomInfo).PropertyChanged += (sender, args) => { DebouncedStateHasChanged(); }; - } - }; - await base.OnInitializedAsync(); - } - - //debounce StateHasChanged, we dont want to reredner on every key stroke - - private CancellationTokenSource _debounceCts = new CancellationTokenSource(); - - private async Task DebouncedStateHasChanged() { - _debounceCts.Cancel(); - _debounceCts = new CancellationTokenSource(); - try { - await Task.Delay(100, _debounceCts.Token); - Console.WriteLine("DebouncedStateHasChanged - Calling StateHasChanged!"); - StateHasChanged(); - } - catch (TaskCanceledException) { } - } - -} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2MainTab.razor b/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2MainTab.razor deleted file mode 100644 index b163a52..0000000 --- a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2MainTab.razor +++ /dev/null @@ -1,210 +0,0 @@ -@using MatrixUtils.Abstractions -@using System.Security.Cryptography -@using ArcaneLibs.Extensions -@using System.ComponentModel -@using System.Diagnostics -@using LibMatrix.EventTypes.Spec.State -@using MatrixUtils.Web.Pages.Rooms.Index2Components.MainTabComponents -@using Microsoft.AspNetCore.Components.Rendering -

RoomsIndex2MainTab

- -@*
*@ -@*
*@ -@*
*@ -@* Uncategorised rooms *@ -@* @foreach (var space in GetTopLevelSpaces()) { *@ -@* *@ -@*
*@ -@*
@space.RoomName
*@ -@*
*@ -@*
*@ -@* } *@ -@*
*@ -@*
*@ -@*

Placeholder for rooms list...

*@ -@*
*@ -@*
*@ -@*
*@ - -
-
-
- Uncategorised rooms - @foreach (var space in GetTopLevelSpaces()) { - @* @RecursingSpaceChildren(space) *@ - - } -
-
-

Placeholder for rooms list...

- @if (SelectedSpace != null) { - foreach (var room in GetSpaceChildRooms(SelectedSpace)) { -

@room.RoomName

- } - } -
-
-
- - -@code { - - [CascadingParameter] - public Index2.RoomListViewData Data { get; set; } = null!; - - protected override async Task OnInitializedAsync() { - Data.Rooms.CollectionChanged += (sender, args) => { - DebouncedStateHasChanged(); - if (args.NewItems is { Count: > 0 }) - foreach (var newItem in args.NewItems) { - (newItem as RoomInfo).PropertyChanged += OnRoomListChanged; - (newItem as RoomInfo).StateEvents.CollectionChanged += (sender, args) => { DebouncedStateHasChanged(); }; - } - }; - foreach (var newItem in Data.Rooms) { - newItem.PropertyChanged += OnRoomListChanged; - newItem.StateEvents.CollectionChanged += (sender, args) => { DebouncedStateHasChanged(); }; - } - - await base.OnInitializedAsync(); - StateHasChanged(); - } - - private void OnRoomListChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName == "RoomName" || e.PropertyName == "RoomType") - DebouncedStateHasChanged(); - } - - private CancellationTokenSource _debounceCts = new CancellationTokenSource(); - - private async Task DebouncedStateHasChanged() { - _debounceCts.Cancel(); - _debounceCts = new CancellationTokenSource(); - try { - Console.WriteLine("DebouncedStateHasChanged - Waiting 50ms..."); - await Task.Delay(50, _debounceCts.Token); - Console.WriteLine("DebouncedStateHasChanged - Calling StateHasChanged!"); - StateHasChanged(); - } - catch (TaskCanceledException) { } - } - - private List GetTopLevelSpaces() { - var spaces = Data.Rooms.Where(x => x.RoomType == "m.space").OrderBy(x => x.RoomName).ToList(); - var allSpaceChildEvents = spaces.SelectMany(x => x.StateEvents.Where(y => - y.Type == SpaceChildEventContent.EventId && - y.RawContent!.Count > 0 - )).ToList(); - - Console.WriteLine($"Child count: {allSpaceChildEvents.Count}"); - - spaces.RemoveAll(x => allSpaceChildEvents.Any(y => y.StateKey == x.Room.RoomId)); - - if (allSpaceChildEvents.Count == 0) { - Console.WriteLine("No space children found, returning nothing..."); - return []; - } - - return spaces.ToList(); - } - - private List GetSpaceChildren(RoomInfo space) { - var childEvents = space.StateEvents.Where(x => - x.Type == SpaceChildEventContent.EventId && - x.RawContent!.Count > 0 - ).ToList(); - var children = childEvents.Select(x => Data.Rooms.FirstOrDefault(y => y.Room.RoomId == x.StateKey)).Where(x => x is not null).ToList(); - return children; - } - - private List GetSpaceChildSpaces(RoomInfo space) { - var children = GetSpaceChildren(space); - var childSpaces = children.Where(x => x.RoomType == "m.space").ToList(); - return childSpaces; - } - - private List GetSpaceChildRooms(RoomInfo space) { - var children = GetSpaceChildren(space); - var childRooms = children.Where(x => x.RoomType != "m.space").ToList(); - return childRooms; - } - - private RoomInfo? SelectedSpace { get; set; } - private List OpenedSpaces { get; set; } = new List(); - - // private RenderFragment RecursingSpaceChildren(RoomInfo space, List? parents = null, int depth = 0) { - // parents ??= []; - // var totalSw = Stopwatch.StartNew(); - // var children = GetSpaceChildSpaces(space); - // - // var randomColor = RandomNumberGenerator.GetBytes(3).Append((byte)0x33).ToArray().AsHexString().Replace(" ", ""); - // var isExpanded = OpenedSpaces.Contains(space); - // - // // Console.WriteLine($"RecursingSpaceChildren::FetchData - Depth: {depth}, Space: {space.RoomName}, Children: {children.Count} - {totalSw.Elapsed}"); - // - // // var renderSw = Stopwatch.StartNew(); - // var rf = new RenderFragment(builder => { - // builder.OpenElement(0, "div"); - // //space list entry render fragment - // // builder.AddContent(1, SpaceListEntry(space)); - // builder.OpenComponent(1); - // builder.AddAttribute(2, "Space", space); - // builder.AddAttribute(2, "OpenedSpaces", OpenedSpaces); - // builder.CloseComponent(); - // builder.CloseElement(); - // //space children render fragment - // if (isExpanded) { - // builder.OpenElement(2, "div"); - // builder.AddAttribute(3, "style", "padding-left: 10px;"); - // foreach (var child in children) { - // builder.AddContent(4, RecursingSpaceChildren(child, parents.Append(space).ToList(), depth + 1)); - // } - // - // builder.CloseElement(); - // } - // }); - // - // // Console.WriteLine($"RecursingSpaceChildren::Render - Depth: {depth}, Space: {space.RoomName}, Children: {children.Count} - {renderSw.Elapsed}"); - // if (totalSw.ElapsedMilliseconds > 20) - // Console.WriteLine($"RecursingSpaceChildren::Total - Depth: {depth}, Space: {space.RoomName}, Children: {children.Count} - {totalSw.Elapsed}"); - // // Console.WriteLine($"RecursingSpaceChildren::Total - Depth: {depth}, Space: {space.RoomName}, Children: {children.Count} - {totalSw.Elapsed}"); - // return rf; - // } - - // private RenderFragment SpaceListEntry(RoomInfo space) { - // return builder => { - // { - // builder.OpenElement(0, "div"); - // builder.AddAttribute(1, "style", "display: block; width: 100%; height: 50px;"); - // builder.AddAttribute(2, "onclick", EventCallback.Factory.Create(this, () => { - // if (OpenedSpaces.Contains(space)) { - // OpenedSpaces.Remove(space); - // } - // else { - // OpenedSpaces.Add(space); - // } - // - // StateHasChanged(); - // })); - // { - // builder.OpenComponent(5); - // builder.AddAttribute(6, "Homeserver", Data.Homeserver); - // builder.AddAttribute(7, "MxcUri", space.RoomIcon); - // builder.AddAttribute(8, "Circular", true); - // builder.AddAttribute(9, "Width", 32); - // builder.AddAttribute(10, "Height", 32); - // builder.CloseComponent(); - // } - // { - // // room name, ellipsized - // builder.OpenElement(11, "span"); - // builder.AddAttribute(12, "class", "spaceNameEllipsis"); - // builder.AddContent(13, space.RoomName); - // builder.CloseElement(); - // } - // builder.CloseElement(); - // } - // }; - // } - -} \ No newline at end of file diff --git a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2MainTab.razor.css b/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2MainTab.razor.css deleted file mode 100644 index e69de29..0000000 diff --git a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2SyncContainer.razor b/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2SyncContainer.razor deleted file mode 100644 index 418ee02..0000000 --- a/MatrixUtils.Web/Pages/Rooms/Index2Components/RoomsIndex2SyncContainer.razor +++ /dev/null @@ -1,202 +0,0 @@ -@using LibMatrix.Helpers -@using LibMatrix.Responses -@using MatrixUtils.Abstractions -@using System.Diagnostics -@using System.Diagnostics.CodeAnalysis -@using LibMatrix.EventTypes.Spec.State -@using LibMatrix.Extensions -@using LibMatrix.Utilities -@using System.Collections.ObjectModel -@using ArcaneLibs -@inject ILogger logger -
RoomsIndex2SyncContainer
-@foreach (var (name, value) in _statusList) { -
[@name] @value.Status
-} - -@code { - - [Parameter] - public Index2.RoomListViewData Data { get; set; } = null!; - - private SyncHelper syncHelper; - - private Queue> queue = new(); - - private ObservableCollection<(string name, ObservableStatus value)> _statusList = new(); - - protected override async Task OnInitializedAsync() { - _statusList.CollectionChanged += (sender, args) => { - StateHasChanged(); - if (args.NewItems is { Count: > 0 }) - foreach (var item in args.NewItems) { - if (item is not (string name, ObservableStatus value)) continue; - value.PropertyChanged += (sender, args) => { - if(value.Show) StateHasChanged(); - }; - } - }; - - while (Data.Homeserver is null) { - await Task.Delay(100); - } - - await SetUpSync(); - } - - private async Task SetUpSync() { - var status = await GetOrAddStatus("Main"); - var syncHelpers = new Dictionary() { - ["Main"] = new SyncHelper(Data.Homeserver, logger) { - Timeout = 30000, - FilterId = await Data.Homeserver.NamedCaches.FilterCache.GetOrSetValueAsync(CommonSyncFilters.GetBasicRoomInfo), - // MinimumDelay = TimeSpan.FromMilliseconds(5000) - } - }; - status.Status = "Initial sync... Checking server filter capability..."; - var syncRes = await syncHelpers["Main"].SyncAsync(); - if (!syncRes.Rooms?.Join?.Any(x => x.Value.State?.Events?.Any(y => y.Type == SpaceChildEventContent.EventId) ?? false) ?? true) { - status.Status = "Initial sync indicates that server supports filters, starting helpers!"; - syncHelpers.Add("SpaceRelations", new SyncHelper(Data.Homeserver, logger) { - Timeout = 30000, - FilterId = await Data.Homeserver.NamedCaches.FilterCache.GetOrSetValueAsync(CommonSyncFilters.GetSpaceRelations), - // MinimumDelay = TimeSpan.FromMilliseconds(5000) - }); - - syncHelpers.Add("Profile", new SyncHelper(Data.Homeserver, logger) { - Timeout = 30000, - FilterId = await Data.Homeserver.NamedCaches.FilterCache.GetOrSetValueAsync(CommonSyncFilters.GetOwnMemberEvents), - // MinimumDelay = TimeSpan.FromMilliseconds(5000) - }); - } - else status.Status = "Initial sync indicates that server does not support filters, continuing without extra filters!"; - - await HandleSyncResponse(syncRes); - - // profileSyncHelper = new SyncHelper(Homeserver, logger) { - // Timeout = 10000, - // Filter = profileUpdateFilter, - // MinimumDelay = TimeSpan.FromMilliseconds(5000) - // }; - // profileUpdateFilter.Room.State.Senders.Add(Homeserver.WhoAmI.UserId); - RunQueueProcessor(); - foreach (var helper in syncHelpers) { - Console.WriteLine($"Starting sync loop for {helper.Key}"); - RunSyncLoop(helper.Value, helper.Key); - } - } - - private async Task RunQueueProcessor() { - var status = await GetOrAddStatus("QueueProcessor"); - var statusd = await GetOrAddStatus("QueueProcessor/D", show: false); - while (true) { - await Task.Delay(1000); - try { - var renderTimeSw = Stopwatch.StartNew(); - while (queue.Count == 0) { - var delay = 1000; - Console.WriteLine("Queue is empty, waiting..."); - // Status2 = $"Queue is empty, waiting for {delay}ms..."; - await Task.Delay(delay); - } - - status.Status = $"Queue no longer empty after {renderTimeSw.Elapsed}!"; - renderTimeSw.Restart(); - - int maxUpdates = 5000; - while (maxUpdates-- > 0 && queue.TryDequeue(out var queueEntry)) { - var (roomId, roomData) = queueEntry; - statusd.Status = $"Dequeued room {roomId}"; - RoomInfo room; - - if (Data.Rooms.Any(x => x.Room.RoomId == roomId)) { - room = Data.Rooms.First(x => x.Room.RoomId == roomId); - statusd.Status = $"{roomId} already known with {room.StateEvents?.Count ?? 0} state events"; - } - else { - statusd.Status = $"Eencountered new room {roomId}!"; - room = new RoomInfo(Data.Homeserver!.GetRoom(roomId), roomData.State?.Events); - Data.Rooms.Add(room); - } - - if (roomData.State?.Events is { Count: > 0 }) - room.StateEvents!.MergeStateEventLists(roomData.State.Events); - else { - statusd.Status = $"Could not merge state for {room.Room.RoomId} as new data contains no state events!"; - } - - // await Task.Delay(10); - } - - status.Status = $"Got {Data.Rooms.Count} rooms so far! {queue.Count} entries left in processing queue... Parsed last response in {renderTimeSw.Elapsed}"; - - // RenderContents |= queue.Count == 0; - // await Task.Delay(Data.Rooms.Count); - } - catch (Exception e) { - Console.WriteLine("QueueWorker exception: " + e); - } - } - } - - private async Task RunSyncLoop(SyncHelper syncHelper, string name = "Unknown") { - var status = await GetOrAddStatus($"SYNC/{name}"); - status.Status = $"Initial syncing..."; - - var syncs = syncHelper.EnumerateSyncAsync(); - await foreach (var sync in syncs) { - var sw = Stopwatch.StartNew(); - status.Status = $"[{DateTime.Now}] Got {Data.Rooms.Count} rooms so far! {sync.Rooms?.Join?.Count ?? 0} new updates!"; - - await HandleSyncResponse(sync); - status.Status += $"\nProcessed sync in {sw.ElapsedMilliseconds}ms, queue length: {queue.Count}"; - } - } - - private async Task HandleSyncResponse(SyncResponse? sync) { - if (sync?.Rooms?.Join is { Count: > 0 }) - foreach (var joinedRoom in sync.Rooms.Join) - queue.Enqueue(joinedRoom); - - if (sync.Rooms.Leave is { Count: > 0 }) - foreach (var leftRoom in sync.Rooms.Leave) - if (Data.Rooms.Any(x => x.Room.RoomId == leftRoom.Key)) - Data.Rooms.Remove(Data.Rooms.First(x => x.Room.RoomId == leftRoom.Key)); - } - - private SemaphoreSlim _syncLock = new(1, 1); - - private async Task GetOrAddStatus(string name, bool show = true, bool log = true) { - await _syncLock.WaitAsync(); - try { - if (_statusList.Any(x => x.name == name)) - return _statusList.First(x => x.name == name).value; - var status = new ObservableStatus() { - Name = name, - Log = log, - Show = show - }; - _statusList.Add((name, status)); - return status; - } - finally { - _syncLock.Release(); - } - } - - private class ObservableStatus : NotifyPropertyChanged { - private string _status = "Initialising..."; - public string Name { get; set; } = "Unknown"; - public bool Show { get; set; } = true; - public bool Log { get; set; } = true; - - public string Status { - get => _status; - set { - if(SetField(ref _status, value) && Log) - Console.WriteLine($"[{Name}]: {value}"); - } - } - } - -} \ No newline at end of file -- cgit 1.4.1