diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-19 07:21:41 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-19 07:21:41 +0200 |
commit | 063fb6f12aea3a5b71c05beea22e7f6482c2f1cf (patch) | |
tree | 064aa9edd5a27017f95ed0a6b19ac69499005778 /MatrixRoomUtils.Web/Shared/RoomList.razor | |
parent | Add user management page (diff) | |
download | MatrixUtils-063fb6f12aea3a5b71c05beea22e7f6482c2f1cf.tar.xz |
Refactor, fix stuff
Diffstat (limited to 'MatrixRoomUtils.Web/Shared/RoomList.razor')
-rw-r--r-- | MatrixRoomUtils.Web/Shared/RoomList.razor | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor index 91ebb0b..705f68c 100644 --- a/MatrixRoomUtils.Web/Shared/RoomList.razor +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor @@ -3,8 +3,10 @@ @using LibMatrix.Extensions @using ArcaneLibs.Extensions @using LibMatrix.EventTypes.Spec.State -@if(Rooms.Count != RoomsWithTypes.Sum(x=>x.Value.Count)) { - <p>Fetching room details... @RoomsWithTypes.Sum(x=>x.Value.Count) out of @Rooms.Count done!</p> +@using System.Collections.ObjectModel +@using _Imports = MatrixRoomUtils.Web._Imports +@if (!StillFetching) { + <p>Fetching room details... @RoomsWithTypes.Sum(x => x.Value.Count) out of @Rooms.Count done!</p> @foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) { <p>@category.Key (@category.Value.Count)</p> } @@ -18,23 +20,35 @@ else { @code { [Parameter] - public List<RoomInfo> Rooms { get; set; } + public ObservableCollection<RoomInfo> Rooms { get; set; } + [Parameter] public ProfileResponseEventContent? GlobalProfile { get; set; } - Dictionary<string, List<RoomInfo>> RoomsWithTypes = new(); + [Parameter] + public bool StillFetching { get; set; } = true; + + [Parameter] + public EventCallback<bool> StillFetchingChanged { get; set; } - protected override async Task OnInitializedAsync() { + private Dictionary<string, List<RoomInfo>> RoomsWithTypes => Rooms is null ? new() : Rooms.GroupBy(x => GetRoomTypeName(x.CreationEventContent?.Type)).ToDictionary(x => x.Key, x => x.ToList()); + + protected override async Task OnParametersSetAsync() { var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; + Rooms.CollectionChanged += (_, args) => { + foreach (RoomInfo item in args.NewItems) { + item.PropertyChanged += (_, args2) => { + Console.WriteLine(args2); + if(args2.PropertyName == nameof(item.CreationEventContent)) + StateHasChanged(); + }; + } + }; - GlobalProfile ??= await hs.GetProfileAsync(hs.WhoAmI.UserId); - if (RoomsWithTypes.Any()) return; - - var tasks = Rooms.Select(ProcessRoom); - await Task.WhenAll(tasks); + // GlobalProfile ??= await hs.GetProfileAsync(hs.WhoAmI.UserId); - await base.OnInitializedAsync(); + await base.OnParametersSetAsync(); } private string GetRoomTypeName(string? roomType) => roomType switch { @@ -45,32 +59,33 @@ else { _ => roomType }; + // private static SemaphoreSlim _semaphoreSlim = new(8, 8); - private static SemaphoreSlim _semaphoreSlim = new(8, 8); - private async Task ProcessRoom(RoomInfo room) { - await _semaphoreSlim.WaitAsync(); - string roomType; - try { - var createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventContent; - roomType = GetRoomTypeName(createEvent.Type); - - if (roomType == "Room") { - var mjolnirData = await room.GetStateEvent("org.matrix.mjolnir.shortcode"); - if(mjolnirData?.RawContent?.ToJson(ignoreNull: true) is not null and not "{}") - roomType = "Legacy policy room"; - } - } - catch (MatrixException e) { - roomType = $"Error: {e.ErrorCode}"; - } - - if (!RoomsWithTypes.ContainsKey(roomType)) { - RoomsWithTypes.Add(roomType, new List<RoomInfo>()); - } - RoomsWithTypes[roomType].Add(room); - - StateHasChanged(); - _semaphoreSlim.Release(); - } + // private async Task ProcessRoom(RoomInfo room) { + // await _semaphoreSlim.WaitAsync(); + // string roomType; + // try { + // var createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventContent; + // roomType = GetRoomTypeName(createEvent.Type); + // + // if (roomType == "Room") { + // var mjolnirData = await room.GetStateEvent("org.matrix.mjolnir.shortcode"); + // if (mjolnirData?.RawContent?.ToJson(ignoreNull: true) is not null and not "{}") + // roomType = "Legacy policy room"; + // } + // } + // catch (MatrixException e) { + // roomType = $"Error: {e.ErrorCode}"; + // } + // + // // if (!RoomsWithTypes.ContainsKey(roomType)) { + // // RoomsWithTypes.Add(roomType, new List<RoomInfo>()); + // // } + // // RoomsWithTypes[roomType].Add(room); + // + // StateHasChanged(); + // _semaphoreSlim.Release(); + // } } + |