blob: 841552eba21dc837e7bc0ef0305cbccd985ae059 (
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
|
@page "/Tools/LeaveRoom"
@using System.Collections.ObjectModel
<h3>Leave room</h3>
<hr/>
<span>Room ID: </span>
<InputText @bind-Value="@RoomId"></InputText>
<br/>
<LinkButton OnClick="@Leave">Leave</LinkButton>
<br/><br/>
@foreach (var line in Log) {
<p>@line</p>
}
@code {
AuthenticatedHomeserverGeneric? hs { get; set; }
ObservableCollection<string> Log { get; set; } = new ObservableCollection<string>();
[Parameter, SupplyParameterFromQuery(Name = "roomId")]
public string? RoomId { get; set; }
protected override async Task OnInitializedAsync() {
hs = await RMUStorage.GetCurrentSessionOrNavigate();
if (hs is null) return;
Log.CollectionChanged += (sender, args) => StateHasChanged();
StateHasChanged();
Console.WriteLine("Rerendered!");
await base.OnInitializedAsync();
}
private async Task Leave() {
if(string.IsNullOrWhiteSpace(RoomId)) return;
var room = hs.GetRoom(RoomId);
Log.Add("Got room object...");
try {
await room.LeaveAsync();
Log.Add("Left room!");
}
catch (Exception e) {
Log.Add(e.ToString());
}
try {
await room.ForgetAsync();
Log.Add("Forgot room!");
}
catch (Exception e) {
Log.Add(e.ToString());
}
Log.Add("Done!");
}
}
|