about summary refs log tree commit diff
path: root/MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
blob: 1f5ce8920fbf9c6b1defb5386e6a59a51fa791ca (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
@using MatrixUtils.Web.Classes.Constants
@using LibMatrix.EventTypes.Spec.State
@using LibMatrix.Responses
@using MatrixUtils.Abstractions
<details open>
    <summary>@RoomType (@Rooms.Count)</summary>
    @foreach (var room in Rooms) {
        <div class="room-list-item">
            <RoomListItem RoomInfo="@room" ShowOwnProfile="@(RoomType == "Room")"></RoomListItem>
            @* @if (RoomVersionDangerLevel(room) != 0 && *@
            @*      (room.StateEvents.FirstOrDefault(x=>x.Type == "m.room.power_levels")?.TypedContent is RoomPowerLevelEventContent powerLevels && powerLevels.UserHasPermission(Homeserver.UserId, "m.room.tombstone"))) { *@
            @*     <MatrixUtils.Web.Shared.SimpleComponents.LinkButton Color="@(RoomVersionDangerLevel(room) == 2 ? "#ff0000" : "#ff8800")" href="@($"/Rooms/Create?Import={room.Room.RoomId}")">Upgrade room</MatrixUtils.Web.Shared.SimpleComponents.LinkButton> *@
            @* } *@
            <LinkButton href="@($"/Rooms/{room.Room.RoomId}/Timeline")">View timeline</LinkButton>
            <LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/View")">View state</LinkButton>
            <LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/Edit")">Edit state</LinkButton>
            <LinkButton href="@($"/Tools/LeaveRoom?roomId={room.Room.RoomId}")" Color="#FF0000">Leave room</LinkButton>

            @if (room.CreationEventContent?.Type == "m.space") {
                <RoomListSpace Space="@room"></RoomListSpace>
            }
            else if (room.CreationEventContent?.Type == "support.feline.policy.lists.msc.v1" || RoomType == "org.matrix.mjolnir.policy") {
                <LinkButton href="@($"/Rooms/{room.Room.RoomId}/Policies")">Manage policies</LinkButton>
            }
        </div>
    }
</details>
<br/>

@code {

    [Parameter]
    public KeyValuePair<string, List<RoomInfo>> Category { get; set; }

    [Parameter]
    public UserProfileResponse? GlobalProfile { get; set; }

    [CascadingParameter]
    public AuthenticatedHomeserverGeneric Homeserver { get; set; } = null!;

    private string RoomType => Category.Key;
    private List<RoomInfo> Rooms => Category.Value;

    private int RoomVersionDangerLevel(RoomInfo room) {
        var creationEvent = room.StateEvents.FirstOrDefault(x => x?.Type == "m.room.create");
        if (creationEvent is null) return 0;
        return creationEvent.TypedContent is not RoomCreateEventContent roomVersionContent ? 0
            : RoomConstants.DangerousRoomVersions.Contains(roomVersionContent.RoomVersion) ? 2
                : roomVersionContent.RoomVersion != RoomConstants.RecommendedRoomVersion ? 1 : 0;
    }

}