about summary refs log tree commit diff
path: root/MatrixUtils.Web/Pages/User/DMSpace.razor
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-02-23 13:57:06 +0100
committerRory& <root@rory.gay>2024-02-23 13:57:06 +0100
commitd0d11db2209a8be65c27e15ca9d8a3b594f1a352 (patch)
treeb42b7de4b09888a1439d0939707ba1331becf626 /MatrixUtils.Web/Pages/User/DMSpace.razor
parentHS emulator (diff)
downloadMatrixUtils-d0d11db2209a8be65c27e15ca9d8a3b594f1a352.tar.xz
Add eons of work because I forgot to push
Diffstat (limited to 'MatrixUtils.Web/Pages/User/DMSpace.razor')
-rw-r--r--MatrixUtils.Web/Pages/User/DMSpace.razor55
1 files changed, 37 insertions, 18 deletions
diff --git a/MatrixUtils.Web/Pages/User/DMSpace.razor b/MatrixUtils.Web/Pages/User/DMSpace.razor
index 519cfff..e3dba30 100644
--- a/MatrixUtils.Web/Pages/User/DMSpace.razor
+++ b/MatrixUtils.Web/Pages/User/DMSpace.razor
@@ -1,11 +1,14 @@
 @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="@DmSpace">
+<CascadingValue Value="@SetupData">
     @switch (Stage) {
         case -1:
             <p>Initialising...</p>
@@ -41,36 +44,29 @@
         }
     }
 
-    public AuthenticatedHomeserverGeneric? Homeserver { get; set; }
 
-    public DMSpaceConfiguration? DmSpaceConfiguration { get; set; }
-
-    [Parameter]
-    public DMSpace? DmSpace { get; set; }
+    public DMSpace? DMSpaceRootPage { get; set; }
 
     protected override async Task OnInitializedAsync() {
         if (NavigationManager.Uri.Contains("?stage=")) {
-            NavigationManager.NavigateTo("/User/DMSpace", true);
+            NavigationManager.NavigateTo("/User/DMSpace/Setup", true);
         }
-        DmSpace = this;
-        Homeserver ??= await RMUStorage.GetCurrentSessionOrNavigate();
-        if (Homeserver is null) return;
+        DMSpaceRootPage = this;
+        SetupData.Homeserver ??= await RMUStorage.GetCurrentSessionOrNavigate();
+        if (SetupData.Homeserver is null) return;
         try {
-            DmSpaceConfiguration = await Homeserver.GetAccountDataAsync<DMSpaceConfiguration>("gay.rory.dm_space");
-            var room = Homeserver.GetRoom(DmSpaceConfiguration.DMSpaceId);
-            await room.GetStateAsync<object>(DMSpaceInfo.EventId);
+            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 == "M_NOT_FOUND") {
+            if (e.ErrorCode is "M_NOT_FOUND" or "M_FORBIDDEN") {
                 Stage = 0;
-                DmSpaceConfiguration = new();
+                SetupData.DmSpaceConfiguration = new();
             }
             else throw;
         }
-        catch (Exception e) {
-            throw;
-        }
         finally {
             StateHasChanged();
         }
@@ -82,4 +78,27 @@
         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; }
+        }
+    }
+
 }
\ No newline at end of file