diff options
Diffstat (limited to 'MatrixUtils.Web/Shared/RoomList.razor')
-rw-r--r-- | MatrixUtils.Web/Shared/RoomList.razor | 81 |
1 files changed, 26 insertions, 55 deletions
diff --git a/MatrixUtils.Web/Shared/RoomList.razor b/MatrixUtils.Web/Shared/RoomList.razor index ed443dd..2ab3cef 100644 --- a/MatrixUtils.Web/Shared/RoomList.razor +++ b/MatrixUtils.Web/Shared/RoomList.razor @@ -20,9 +20,24 @@ else { } @code { + private ObservableCollection<RoomInfo> _rooms; [Parameter] - public ObservableCollection<RoomInfo> Rooms { get; set; } + public ObservableCollection<RoomInfo> Rooms { + get => _rooms; + set { + if(_rooms != value) + value.CollectionChanged += (_, args) => { + foreach (RoomInfo item in args.NewItems??(object[])[]) { + item.PropertyChanged += (_, args2) => { + if (args2.PropertyName == nameof(item.CreationEventContent)) + StateHasChanged(); + }; + } + }; + _rooms = value; + } + } [Parameter] public UserProfileResponse? GlobalProfile { get; set; } @@ -33,65 +48,21 @@ else { [Parameter] public EventCallback<bool> StillFetchingChanged { get; set; } - private Dictionary<string, List<RoomInfo>> RoomsWithTypes => Rooms is null ? new() : Rooms.GroupBy(x => GetRoomTypeName(x.CreationEventContent?.Type)).ToDictionary(x => x.Key, x => x.ToList()); - - private bool hooked; - protected override async Task OnParametersSetAsync() { - var hs = await RMUStorage.GetCurrentSessionOrNavigate(); - if (hs is null) return; - if (!hooked) { - Rooms.CollectionChanged += (_, args) => { - foreach (RoomInfo item in args.NewItems) { - item.PropertyChanged += (_, args2) => { - // Console.WriteLine(args2); - - if (args2.PropertyName == nameof(item.CreationEventContent)) - StateHasChanged(); - }; - } - }; - hooked = true; - } - - // GlobalProfile ??= await hs.GetProfileAsync(hs.WhoAmI.UserId); - - await base.OnParametersSetAsync(); - } + + private Dictionary<string, List<RoomInfo>> RoomsWithTypes => Rooms is null ? new() : Rooms.GroupBy(x => GetRoomTypeName(x.RoomType)).ToDictionary(x => x.Key, x => x.ToList()); private string GetRoomTypeName(string? roomType) => roomType switch { null => "Room", "m.space" => "Space", "msc3588.stories.stories-room" => "Story room", - "support.feline.policy.lists.msc.v1" => "MSC3784 Policy list (v1)", + "support.feline.policy.lists.msc.v1" => "MSC3784 policy list (v1)", + // custom names + "gay.rory.moderation_bot.policy_room" => "Rory&::ModerationBot policy room", + "gay.rory.moderation_bot.log_room" => "Rory&::ModerationBot log room", + "gay.rory.moderation_bot.control_room" => "Rory&::ModerationBot control room", + // fallback + "gay.rory.rmu.fallback.policy_list" => "\"Legacy\" policy list (unmarked room)", _ => roomType - }; - - // 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(); - // } + }; } \ No newline at end of file |