blob: e3dba30480abab4baf06811d78908467a3e8228d (
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
93
94
95
96
97
98
99
100
101
102
103
104
|
@page "/User/DMSpace/Setup"
@using LibMatrix
@using LibMatrix.Responses
@using MatrixUtils.Abstractions
@using MatrixUtils.LibDMSpace
@using MatrixUtils.LibDMSpace.StateEvents
@using MatrixUtils.Web.Pages.User.DMSpaceStages
@using System.Text.Json.Serialization
<h3>DM Space Management</h3>
<hr/>
<CascadingValue Value="@SetupData">
@switch (Stage) {
case -1:
<p>Initialising...</p>
break;
case 0:
<DMSpaceStage0/>
break;
case 1:
<DMSpaceStage1/>
break;
case 2:
<DMSpaceStage2/>
break;
case 3:
<DMSpaceStage3/>
break;
default:
<p>Stage is unknown value: @Stage!</p>
break;
}
</CascadingValue>
@code {
private int _stage = -1;
[Parameter, SupplyParameterFromQuery(Name = "stage")]
public int Stage {
get => _stage;
set {
_stage = value;
Console.WriteLine($"Stage is now {value}");
StateHasChanged();
}
}
public DMSpace? DMSpaceRootPage { get; set; }
protected override async Task OnInitializedAsync() {
if (NavigationManager.Uri.Contains("?stage=")) {
NavigationManager.NavigateTo("/User/DMSpace/Setup", true);
}
DMSpaceRootPage = this;
SetupData.Homeserver ??= await RMUStorage.GetCurrentSessionOrNavigate();
if (SetupData.Homeserver is null) return;
try {
SetupData.DmSpaceConfiguration = await SetupData.Homeserver.GetAccountDataAsync<DMSpaceConfiguration>("gay.rory.dm_space");
var room = SetupData.Homeserver.GetRoom(SetupData.DmSpaceConfiguration.DMSpaceId);
await room.GetStateAsync<DMSpaceInfo>(DMSpaceInfo.EventId);
Stage = 1;
}
catch (MatrixException e) {
if (e.ErrorCode is "M_NOT_FOUND" or "M_FORBIDDEN") {
Stage = 0;
SetupData.DmSpaceConfiguration = new();
}
else throw;
}
finally {
StateHasChanged();
}
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync() {
StateHasChanged();
await base.OnParametersSetAsync();
}
public DMSpaceSetupData SetupData { get; set; } = new();
public class DMSpaceSetupData {
public AuthenticatedHomeserverGeneric? Homeserver { get; set; }
public DMSpaceConfiguration? DmSpaceConfiguration { get; set; }
public DMSpaceInfo? DmSpaceInfo { get; set; } = new();
public Dictionary<string, RoomInfo>? Spaces;
public Dictionary<UserProfileWithId, List<RoomInfo>>? DMRooms;
public RoomInfo? DMSpaceRoomInfo { get; set; }
public class UserProfileWithId : UserProfileResponse {
[JsonIgnore]
public string Id { get; set; }
}
}
}
|