about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/Tools/LeaveRoom.razor
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-01-29 10:15:27 +0100
committerRory& <root@rory.gay>2024-01-29 10:15:27 +0100
commit3e6a73599bb58161c08d8675ea23ee6c82c6675c (patch)
treef3c0d1e797a77ed5993478d742751d386e004fb7 /MatrixUtils.Web/Pages/Tools/LeaveRoom.razor
parentRoom member migrations (diff)
downloadMatrixUtils-3e6a73599bb58161c08d8675ea23ee6c82c6675c.tar.xz
Room list fixes, migration fix, update available handler
Diffstat (limited to 'MatrixUtils.Web/Pages/Tools/LeaveRoom.razor')
-rw-r--r--MatrixUtils.Web/Pages/Tools/LeaveRoom.razor56
1 files changed, 56 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Pages/Tools/LeaveRoom.razor b/MatrixUtils.Web/Pages/Tools/LeaveRoom.razor
new file mode 100644
index 0000000..b5df05f
--- /dev/null
+++ b/MatrixUtils.Web/Pages/Tools/LeaveRoom.razor
@@ -0,0 +1,56 @@
+@page "/Tools/LeaveRoom"
+@using System.Diagnostics
+@using ArcaneLibs.Extensions
+@using LibMatrix.Homeservers
+@using LibMatrix.RoomTypes
+@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!");
+    }
+
+}
\ No newline at end of file