about summary refs log tree commit diff
path: root/MatrixUtils.Web/Shared/RoomList.razor
blob: 2ab3cef4c5bb0662ddcb8eea6e6c225fd21fab93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@using MatrixUtils.Web.Shared.RoomListComponents;
@using LibMatrix
@using LibMatrix.Extensions
@using ArcaneLibs.Extensions
@using LibMatrix.EventTypes.Spec.State
@using System.Collections.ObjectModel
@using LibMatrix.Responses
@using MatrixUtils.Abstractions
@using _Imports = MatrixUtils.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>
    }
}
else {
    @foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) {
        <RoomListCategory Category="@category" GlobalProfile="@GlobalProfile"></RoomListCategory>
    }
}

@code {
    private ObservableCollection<RoomInfo> _rooms;

    [Parameter]
    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; }

    [Parameter]
    public bool StillFetching { get; set; } = true;

    [Parameter]
    public EventCallback<bool> StillFetchingChanged { get; set; }

    
    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)",
        // 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
    };

}