about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web')
-rw-r--r--MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs3
-rw-r--r--MatrixRoomUtils.Web/Classes/RoomInfo.cs21
-rw-r--r--MatrixRoomUtils.Web/Pages/About.razor2
-rw-r--r--MatrixRoomUtils.Web/Pages/Index.razor2
-rw-r--r--MatrixRoomUtils.Web/Pages/ModerationUtilities/UserRoomHistory.razor3
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/Create.razor7
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/Index.razor2
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor1
-rw-r--r--MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor2
-rw-r--r--MatrixRoomUtils.Web/Pages/User/DMManager.razor3
-rw-r--r--MatrixRoomUtils.Web/Pages/User/DMSpaceStages/DMSpaceStage1.razor2
-rw-r--r--MatrixRoomUtils.Web/Program.cs9
-rw-r--r--MatrixRoomUtils.Web/Shared/MainLayout.razor2
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor23
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor6
15 files changed, 59 insertions, 29 deletions
diff --git a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs
index 44cd988..a6831d4 100644
--- a/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs
+++ b/MatrixRoomUtils.Web/Classes/RoomCreationTemplates/DefaultRoomCreationTemplate.cs
@@ -1,6 +1,7 @@
 using System.Text.Json.Nodes;
 using LibMatrix;
 using LibMatrix.EventTypes.Spec.State;
+using LibMatrix.EventTypes.Spec.State.RoomInfo;
 using LibMatrix.Responses;
 
 namespace MatrixRoomUtils.Web.Classes.RoomCreationTemplates;
@@ -28,7 +29,7 @@ public class DefaultRoomCreationTemplate : IRoomCreationTemplate {
                 new() {
                     Type = "m.room.join_rules",
                     TypedContent = new RoomJoinRulesEventContent {
-                        JoinRule = "public"
+                        JoinRule = RoomJoinRulesEventContent.JoinRules.Public
                     }
                 },
                 new() {
diff --git a/MatrixRoomUtils.Web/Classes/RoomInfo.cs b/MatrixRoomUtils.Web/Classes/RoomInfo.cs
index a8c3848..9d0cd59 100644
--- a/MatrixRoomUtils.Web/Classes/RoomInfo.cs
+++ b/MatrixRoomUtils.Web/Classes/RoomInfo.cs
@@ -3,13 +3,14 @@ using System.Text.Json.Nodes;
 using ArcaneLibs;
 using LibMatrix;
 using LibMatrix.EventTypes.Spec.State;
+using LibMatrix.EventTypes.Spec.State.RoomInfo;
 using LibMatrix.Interfaces;
 using LibMatrix.RoomTypes;
 
 namespace MatrixRoomUtils.Web.Classes;
 
 public class RoomInfo : NotifyPropertyChanged {
-    public GenericRoom? Room { get; set; }
+    public required GenericRoom Room { get; set; }
     public ObservableCollection<StateEventResponse?> StateEvents { get; } = new();
 
     public async Task<StateEventResponse?> GetStateEvent(string type, string stateKey = "") {
@@ -18,9 +19,11 @@ public class RoomInfo : NotifyPropertyChanged {
         @event = new StateEventResponse {
             RoomId = Room.RoomId,
             Type = type,
-            StateKey = stateKey
+            StateKey = stateKey,
+            Sender = null, //TODO implement
+            EventId = null
         };
-        if (Room is null) return null;
+        // if (Room is null) return null;
         try {
             @event.RawContent = await Room.GetStateAsync<JsonObject>(type, stateKey);
         }
@@ -32,7 +35,11 @@ public class RoomInfo : NotifyPropertyChanged {
                         StateKey = stateKey,
                         TypedContent = new RoomNameEventContent() {
                             Name = await Room.GetNameOrFallbackAsync()
-                        }
+                        },
+                        //TODO implement
+                        RoomId = null,
+                        Sender = null,
+                        EventId = null
                     };
                 else
                     @event.RawContent = default!;
@@ -78,11 +85,11 @@ public class RoomInfo : NotifyPropertyChanged {
         StateEvents.CollectionChanged += (_, args) => {
             if (args.NewItems is { Count: > 0 })
                 foreach (StateEventResponse newState in args.NewItems) {
-                    if (newState.TypedContent is RoomNameEventContent roomNameContent)
+                    if (newState.GetType == typeof(RoomNameEventContent) && newState.TypedContent is RoomNameEventContent roomNameContent)
                         RoomName = roomNameContent.Name;
-                    else if (newState.TypedContent is RoomAvatarEventContent roomAvatarContent)
+                    else if (newState.GetType == typeof(RoomAvatarEventContent) && newState.TypedContent is RoomAvatarEventContent roomAvatarContent)
                         RoomIcon = roomAvatarContent.Url;
-                    else if (newState.TypedContent is RoomCreateEventContent roomCreateContent) {
+                    else if (newState.GetType == typeof(RoomCreateEventContent) && newState.TypedContent is RoomCreateEventContent roomCreateContent) {
                         CreationEventContent = roomCreateContent;
                         RoomCreator = newState.Sender;
                     }
diff --git a/MatrixRoomUtils.Web/Pages/About.razor b/MatrixRoomUtils.Web/Pages/About.razor
index df6e6c2..a5864ab 100644
--- a/MatrixRoomUtils.Web/Pages/About.razor
+++ b/MatrixRoomUtils.Web/Pages/About.razor
@@ -11,7 +11,7 @@
 <p>These range from joining rooms on dead homeservers, to managing your accounts and rooms, and creating rooms based on templates.</p>
 
 <br/><br/>
-<p>You can find the source code on <a href="https://git.rory.gay/MatrixRoomUtils.git/">my git server</a>.<br/></p>
+<p>You can find the source code on <a href="https://cgit.rory.gay/MatrixRoomUtils.git/">my git server</a>.<br/></p>
 <p>You can also join the <a href="https://matrix.to/#/%23mru%3Arory.gay?via=rory.gay&via=matrix.org&via=feline.support">Matrix room</a> for this project.</p>
 @if (ShowBinDownload) {
     <p>This deployment also serves a copy of the compiled, hosting-ready binaries at <a href="MRU-BIN.tar.xz">/MRU-BIN.tar.xz</a>!</p>
diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor
index 68a4f26..2d1d6c0 100644
--- a/MatrixRoomUtils.Web/Pages/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Index.razor
@@ -92,7 +92,7 @@ Small collection of tools to do not-so-everyday things.
                 throw;
             }
             catch (HttpRequestException e) {
-                logger.LogError(e, $"Failed to instantiate AuthenticatedHomeserver for {_auth}, homeserver may be offline?", token.UserId);
+                logger.LogError(e, $"Failed to instantiate AuthenticatedHomeserver for {token.ToJson()}, homeserver may be offline?", token.UserId);
                 return;
             }
             var roomCountTask = hs.GetJoinedRooms();
diff --git a/MatrixRoomUtils.Web/Pages/ModerationUtilities/UserRoomHistory.razor b/MatrixRoomUtils.Web/Pages/ModerationUtilities/UserRoomHistory.razor
index 02dfe44..d33756b 100644
--- a/MatrixRoomUtils.Web/Pages/ModerationUtilities/UserRoomHistory.razor
+++ b/MatrixRoomUtils.Web/Pages/ModerationUtilities/UserRoomHistory.razor
@@ -91,7 +91,8 @@ else {
                     Type = RoomNameEventContent.EventId,
                     TypedContent = new RoomNameEventContent() {
                         Name = await room.GetNameOrFallbackAsync(4)
-                    }
+                    },
+                    RoomId = null, Sender = null, EventId = null //TODO implement
                 });
                 StateHasChanged();
                 if (mxid != UserId) {
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor
index 08b21dd..e477f4c 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor
@@ -4,6 +4,7 @@
 @using ArcaneLibs.Extensions
 @using LibMatrix
 @using LibMatrix.EventTypes.Spec.State
+@using LibMatrix.EventTypes.Spec.State.RoomInfo
 @using LibMatrix.Homeservers
 @using LibMatrix.Responses
 @using MatrixRoomUtils.Web.Classes.RoomCreationTemplates
@@ -49,15 +50,15 @@
         <tr>
             <td>Room type:</td>
             <td>
-                @if (creationEvent._creationContentBaseType is null) {
+                @if (creationEvent.CreationContentBaseType is null) {
                     <p style="color: red;">creationEvent._creationContentBaseType is null!</p>
                 }
                 else {
-                    <InputSelect @bind-Value="@creationEvent._creationContentBaseType.Type">
+                    <InputSelect @bind-Value="@creationEvent.CreationContentBaseType.Type">
                         <option value="">Room</option>
                         <option value="m.space">Space</option>
                     </InputSelect>
-                    <FancyTextBox @bind-Value="@creationEvent._creationContentBaseType.Type"></FancyTextBox>
+                    <FancyTextBox @bind-Value="@creationEvent.CreationContentBaseType.Type"></FancyTextBox>
                 }
             </td>
         </tr>
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
index e137b6c..fb44337 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
@@ -161,7 +161,7 @@
                     }
                     RenderContents |= queue.Count == 0;
                     if (queue.Count > 10) RenderContents = false;
-                    await Task.Delay(RenderContents ? 25 : 25);
+                    await Task.Delay(RenderContents ? 25 : 12);
                 }
                 // else {
                     // Console.WriteLine("Failed to dequeue item");
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
index adedbd3..846d1cb 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
@@ -3,6 +3,7 @@
 @using LibMatrix.Homeservers
 @using ArcaneLibs.Extensions
 @using LibMatrix.EventTypes.Spec.State
+@using LibMatrix.EventTypes.Spec.State.Policy
 <h3>Policy list editor - Editing @RoomId</h3>
 <hr/>
 
diff --git a/MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor b/MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor
index bcf8095..816b7db 100644
--- a/MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor
+++ b/MatrixRoomUtils.Web/Pages/Tools/MassJoinRoom.razor
@@ -69,7 +69,7 @@
         try {
             try {
                 var joinRule = await room.GetJoinRuleAsync();
-                if (joinRule.JoinRule == "public") return "Room is public, no invite needed";
+                if (joinRule.JoinRule == RoomJoinRulesEventContent.JoinRules.Public) return "Room is public, no invite needed";
             }
             catch { }
             var pls = await room.GetPowerLevelsAsync();
diff --git a/MatrixRoomUtils.Web/Pages/User/DMManager.razor b/MatrixRoomUtils.Web/Pages/User/DMManager.razor
index f753f18..1b28516 100644
--- a/MatrixRoomUtils.Web/Pages/User/DMManager.razor
+++ b/MatrixRoomUtils.Web/Pages/User/DMManager.razor
@@ -46,7 +46,8 @@
                     Type = RoomNameEventContent.EventId,
                     TypedContent = new RoomNameEventContent() {
                         Name = await Homeserver.GetRoom(room).GetNameOrFallbackAsync(4)
-                    }
+                    },
+                    RoomId = room, Sender = null, EventId = null
                 });
             }
             StateHasChanged();
diff --git a/MatrixRoomUtils.Web/Pages/User/DMSpaceStages/DMSpaceStage1.razor b/MatrixRoomUtils.Web/Pages/User/DMSpaceStages/DMSpaceStage1.razor
index f953f76..5958fc5 100644
--- a/MatrixRoomUtils.Web/Pages/User/DMSpaceStages/DMSpaceStage1.razor
+++ b/MatrixRoomUtils.Web/Pages/User/DMSpaceStages/DMSpaceStage1.razor
@@ -84,7 +84,7 @@ else {
     private async Task Execute() {
         if (string.IsNullOrWhiteSpace(DmSpace.DmSpaceConfiguration.DMSpaceId)) {
             var crr = CreateRoomRequest.CreatePrivate(DmSpace.Homeserver, "Direct Messages");
-            crr._creationContentBaseType.Type = "m.space";
+            crr.CreationContentBaseType.Type = "m.space";
             DmSpace.DmSpaceConfiguration.DMSpaceId = (await DmSpace.Homeserver.CreateRoom(crr)).RoomId;
         }
         await DmSpace.Homeserver!.SetAccountDataAsync(DMSpaceConfiguration.EventId, DmSpace.DmSpaceConfiguration);
diff --git a/MatrixRoomUtils.Web/Program.cs b/MatrixRoomUtils.Web/Program.cs
index a7a0105..277e4d1 100644
--- a/MatrixRoomUtils.Web/Program.cs
+++ b/MatrixRoomUtils.Web/Program.cs
@@ -16,10 +16,15 @@ builder.RootComponents.Add<HeadOutlet>("head::after");
 
 builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
 
-builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.json"));
+try {
+    builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.json"));
 #if DEBUG
-builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.Development.json"));
+    builder.Configuration.AddJsonStream(await new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }.GetStreamAsync("/appsettings.Development.json"));
 #endif
+}
+catch (Exception e) {
+    Console.WriteLine("Could not load appsettings: " + e);
+}
 
 builder.Services.AddBlazoredLocalStorage(config => {
     config.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
diff --git a/MatrixRoomUtils.Web/Shared/MainLayout.razor b/MatrixRoomUtils.Web/Shared/MainLayout.razor
index 691acbb..74db805 100644
--- a/MatrixRoomUtils.Web/Shared/MainLayout.razor
+++ b/MatrixRoomUtils.Web/Shared/MainLayout.razor
@@ -9,7 +9,7 @@
     <main>
         <div class="top-row px-4">
             <PortableDevTools></PortableDevTools>
-            <a href="https://git.rory.gay/MatrixRoomUtils.git/" target="_blank">Git</a>
+            <a href="https://cgit.rory.gay/MatrixRoomUtils.git/" target="_blank">Git</a>
             <a href="https://matrix.to/#/%23mru%3Arory.gay?via=rory.gay&via=matrix.org&via=feline.support" target="_blank">Matrix</a>
             @if (showDownload) {
                 <a href="/MRU.tar.xz" target="_blank">Download</a>
diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
index cbe542a..55ffc1e 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
@@ -4,10 +4,10 @@
 @using LibMatrix.Homeservers
 @using LibMatrix.Responses
 <details>
-    <summary>@roomType (@rooms.Count)</summary>
-    @foreach (var room in rooms) {
+    <summary>@RoomType (@Rooms.Count)</summary>
+    @foreach (var room in Rooms) {
         <div class="room-list-item">
-            <RoomListItem RoomInfo="@room" ShowOwnProfile="@(roomType == "Room")"></RoomListItem>
+            <RoomListItem RoomInfo="@room" ShowOwnProfile="@(RoomType == "Room")"></RoomListItem>
             @* @if (RoomVersionDangerLevel(room) != 0 && *@
             @*      (room.StateEvents.FirstOrDefault(x=>x.Type == "m.room.power_levels")?.TypedContent is RoomPowerLevelEventContent powerLevels && powerLevels.UserHasPermission(Homeserver.UserId, "m.room.tombstone"))) { *@
             @*     <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton Color="@(RoomVersionDangerLevel(room) == 2 ? "#ff0000" : "#ff8800")" href="@($"/Rooms/Create?Import={room.Room.RoomId}")">Upgrade room</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton> *@
@@ -16,9 +16,12 @@
             <LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/View")">View state</LinkButton>
             <LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/Edit")">Edit state</LinkButton>
 
-            @if (roomType == "Space") {
+            @if (room.CreationEventContent?.Type == "m.space") {
                 <RoomListSpace Space="@room"></RoomListSpace>
             }
+            else if (room.CreationEventContent?.Type == "support.feline.policy.lists.msc.v1" || RoomType == "org.matrix.mjolnir.policy") {
+                <LinkButton href="@($"/Rooms/{room.Room.RoomId}/Policies")">Manage policies</LinkButton>
+            }
         </div>
     }
 </details>
@@ -35,8 +38,8 @@
     [CascadingParameter]
     public AuthenticatedHomeserverGeneric Homeserver { get; set; } = null!;
 
-    private string roomType => Category.Key;
-    private List<RoomInfo> rooms => Category.Value;
+    private string RoomType => Category.Key;
+    private List<RoomInfo> Rooms => Category.Value;
 
     private int RoomVersionDangerLevel(RoomInfo room) {
         var roomVersion = room.StateEvents.FirstOrDefault(x => x.Type == "m.room.create");
@@ -45,5 +48,13 @@
             : RoomConstants.DangerousRoomVersions.Contains(roomVersionContent.RoomVersion) ? 2
                 : roomVersionContent.RoomVersion != RoomConstants.RecommendedRoomVersion ? 1 : 0;
     }
+    
+    public static string GetRoomTypeName(string roomType) {
+        return roomType switch {
+            "Room" => "Rooms",
+            "org.matrix.mjolnir.policy" => "Policies",
+            _ => roomType
+        };
+    }
 
 }
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index c5c3cfe..3aa28e6 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -91,13 +91,15 @@ else {
                         LoadData = false;
                         RoomInfo.StateEvents.Add(new() {
                             Type = "m.room.create",
-                            TypedContent = new RoomCreateEventContent() { RoomVersion = "0" }
+                            TypedContent = new RoomCreateEventContent() { RoomVersion = "0" }, 
+                            RoomId = null, Sender = null, EventId = null //TODO: implement
                         });
                         RoomInfo.StateEvents.Add(new() {
                             Type = "m.room.name",
                             TypedContent = new RoomNameEventContent() {
                                 Name = "M_FORBIDDEN: Are you a member of this room? " + RoomInfo.Room.RoomId
-                            }
+                            },
+                            RoomId = null, Sender = null, EventId = null //TODO: implement
                         });
                     }
                 }