about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Rooms/RoomCreateComponents/RoomCreateCreateOptions.razor
blob: 3f4a73d2627ccb621195f17b6687ccc1e0ac61f8 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@using Blazored.LocalStorage
@using LibMatrix.Helpers
@inject ILocalStorageService LocalStorage
<tr>
    <td>Room type:</td>
    <td>
        @if (RoomTypes.ContainsKey(roomBuilder.Type ?? "")) {
            <InputSelect @bind-Value="@roomBuilder.Type">
                @foreach (var type in RoomTypes) {
                    <option value="@type.Key">@type.Value</option>
                }
                <option value="custom">Custom ...</option>
            </InputSelect>
        }
        else {
            <FancyTextBox @bind-Value="@roomBuilder.Type"></FancyTextBox>
        }

        <span> version </span>
        @if (Capabilities is null) {
            <span style="color: #888;">Loading...</span>
        }
        else {
            <InputSelect @bind-Value="@roomBuilder.Version">
                @foreach (var version in Capabilities.Capabilities.RoomVersions!.Available!) {
                    <option value="@version.Key">@version.Key (@version.Value)</option>
                }
            </InputSelect>
        }
    </td>
</tr>
<tr>
    <td style="vertical-align: top;">Allow attribution:</td>
    <td>
        <InputCheckbox @bind-Value="@AllowAttribution"/>
        <span>Allow attribution to Rory&::MatrixUtils</span>
        <LinkButton InlineText="true" OnClick="@(() => ShowAttributionInfo = true)">?</LinkButton>
    </td>
</tr>

@if (ShowAttributionInfo) {
    <ModalWindow Title="Allow attribution to Rory&::MatrixUtils"
                 OnCloseClicked="@(() => ShowAttributionInfo = false)">
        <span>This will add the following to the room creation content:</span>
        <br/>
        <pre>{ "gay.rory.created_using": "Rory&::MatrixUtils (https://mru.rory.gay)" }</pre>
        <span>This is not visible to users unless they manually inspect the room's create event source.</span>
    </ModalWindow>
}

@code {

    [Parameter]
    public required RoomBuilder roomBuilder { get; set; }

    [Parameter]
    public required Action PageStateHasChanged { get; set; }

    [Parameter]
    public AuthenticatedHomeserverGeneric Homeserver { get; set; }

    private AuthenticatedHomeserverGeneric.CapabilitiesResponse? Capabilities { get; set; }

    private bool ShowAttributionInfo {
        get;
        set {
            field = value;
            StateHasChanged();
        }
    }

    private bool AllowAttribution {
        get;
        set {
            field = value;
            _ = LocalStorage.SetItemAsync("rmu.room_create.allow_attribution", value);
        }
    } = true;

    protected override async Task OnInitializedAsync() {
        Capabilities = await Homeserver.GetCapabilitiesAsync();
        roomBuilder.Version = Capabilities.Capabilities.RoomVersions!.Default;
        AllowAttribution = await LocalStorage.GetItemAsync<bool?>("rmu.room_create.allow_attribution") ?? true;
    }

    private static Dictionary<string, string> RoomTypes { get; } = new() {
        { "", "Room" },
        { "m.space", "Space" },
        { "support.feline.policy.lists.msc.v1", "Policy list" }
    };

}