about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages/Rooms
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/Rooms')
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/Create.razor13
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/Index.razor46
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor2
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/Space.razor32
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor14
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor12
-rw-r--r--MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor2
7 files changed, 60 insertions, 61 deletions
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor
index ebf6444..3b7d000 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/Create.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/Create.razor
@@ -131,7 +131,7 @@
             <td>
                 @if (serverAcl?.Allow is null) {
                     <p>No allow rules exist!</p>
-                    <button @onclick="@(() => { serverAcl.Allow = new() { "*" }; })">Create sane defaults</button>
+                    <button @onclick="@(() => { serverAcl.Allow = new List<string> { "*" }; })">Create sane defaults</button>
                 }
                 else {
                     <details>
@@ -141,7 +141,7 @@
                 }
                 @if (serverAcl?.Deny is null) {
                     <p>No deny rules exist!</p>
-                    <button @onclick="@(() => { serverAcl.Allow = new(); })">Create sane defaults</button>
+                    <button @onclick="@(() => { serverAcl.Allow = new List<string>(); })">Create sane defaults</button>
                 }
                 else {
                     <details>
@@ -240,12 +240,7 @@
 @code {
 
     private string RoomPreset {
-        get {
-            if (Presets.ContainsValue(creationEvent)) {
-                return Presets.First(x => x.Value == creationEvent).Key;
-            }
-            return "Not a preset";
-        }
+        get => Presets.ContainsValue(creationEvent) ? Presets.First(x => x.Value == creationEvent).Key : "Not a preset";
         set {
             creationEvent = Presets[value];
             JsonChanged();
@@ -310,7 +305,7 @@
             creationEvent.InitialState.Add(new StateEvent {
                 Type = "m.room.member",
                 StateKey = mxid,
-                TypedContent = new RoomMemberEventData() {
+                TypedContent = new RoomMemberEventData {
                     Membership = "invite",
                     Reason = "Automatically invited at room creation time."
                 }
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
index 89ededf..ad3a714 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/Index.razor
@@ -19,25 +19,25 @@
     private ProfileResponseEventData GlobalProfile { get; set; }
 
     private SyncFilter filter = new() {
-        AccountData = new() {
-            NotTypes = new() { "*" },
+        AccountData = new SyncFilter.EventFilter {
+            NotTypes = new List<string> { "*" },
             Limit = 1
         },
-        Presence = new() {
-            NotTypes = new() { "*" },
+        Presence = new SyncFilter.EventFilter {
+            NotTypes = new List<string> { "*" },
             Limit = 1
         },
-        Room = new() {
-            AccountData = new() {
-                NotTypes = new() { "*" },
+        Room = new SyncFilter.RoomFilter {
+            AccountData = new SyncFilter.RoomFilter.StateFilter {
+                NotTypes = new List<string> { "*" },
                 Limit = 1
             },
-            Ephemeral = new() {
-                NotTypes = new() { "*" },
+            Ephemeral = new SyncFilter.RoomFilter.StateFilter {
+                NotTypes = new List<string> { "*" },
                 Limit = 1
             },
-            State = new() {
-                Types = new List<string>() {
+            State = new SyncFilter.RoomFilter.StateFilter {
+                Types = new List<string> {
                     "m.room.name",
                     "m.room.avatar",
                     "m.room.create",
@@ -45,8 +45,8 @@
                     "m.room.power_levels"
                 }
             },
-            Timeline = new() {
-                NotTypes = new() { "*" },
+            Timeline = new SyncFilter.RoomFilter.StateFilter {
+                NotTypes = new List<string> { "*" },
                 Limit = 1
             }
         }
@@ -74,9 +74,9 @@
                     room = Rooms.First(x => x.Room.RoomId == roomId);
                 }
                 else {
-                    room = new RoomInfo() {
+                    room = new RoomInfo {
                         Room = await hs.GetRoom(roomId),
-                        StateEvents = new()
+                        StateEvents = new List<StateEventResponse?>()
                     };
                     Rooms.Add(room);
                     KnownRooms.Add(room);
@@ -91,23 +91,23 @@
         Status = "Sync complete!";
         foreach (var roomInfo in Rooms) {
             if (!roomInfo.StateEvents.Any(x => x.Type == "m.room.name")) {
-                roomInfo.StateEvents.Add(new StateEventResponse() {
+                roomInfo.StateEvents.Add(new StateEventResponse {
                     Type = "m.room.name",
-                    TypedContent = new RoomNameEventData() {
+                    TypedContent = new RoomNameEventData {
                         Name = roomInfo.Room.RoomId
                     }
                 });
             }
             if (!roomInfo.StateEvents.Any(x => x.Type == "m.room.avatar")) {
-                roomInfo.StateEvents.Add(new StateEventResponse() {
+                roomInfo.StateEvents.Add(new StateEventResponse {
                     Type = "m.room.avatar",
-                    TypedContent = new RoomAvatarEventData() {
+                    TypedContent = new RoomAvatarEventData {
 
                     }
                 });
             }
             if (!roomInfo.StateEvents.Any(x => x.Type == "org.matrix.mjolnir.shortcode")) {
-                roomInfo.StateEvents.Add(new StateEventResponse() {
+                roomInfo.StateEvents.Add(new StateEventResponse {
                     Type = "org.matrix.mjolnir.shortcode"
                 });
             }
@@ -118,10 +118,10 @@
         var memberTasks = Rooms.Select(async roomInfo => {
             if (!roomInfo.StateEvents.Any(x => x.Type == "m.room.member" && x.StateKey == hs.WhoAmI.UserId)) {
                 await semaphore.WaitAsync();
-                roomInfo.StateEvents.Add(new StateEventResponse() {
+                roomInfo.StateEvents.Add(new StateEventResponse {
                     Type = "m.room.member",
                     StateKey = hs.WhoAmI.UserId,
-                    TypedContent = await roomInfo.Room.GetStateAsync<RoomMemberEventData>("m.room.member", hs.WhoAmI.UserId) ?? new RoomMemberEventData() {
+                    TypedContent = await roomInfo.Room.GetStateAsync<RoomMemberEventData>("m.room.member", hs.WhoAmI.UserId) ?? new RoomMemberEventData {
                         Membership = "unknown"
                     }
                 });
@@ -148,7 +148,7 @@
         await base.OnInitializedAsync();
     }
 
-    private bool RenderContents { get; set; } = false;
+    private bool RenderContents { get; set; }
 
     private string _status;
 
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
index 3297bcb..2b31389 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/PolicyList.razor
@@ -114,7 +114,7 @@ else {
             @foreach (var policyEvent in PolicyEvents.Where(x => x.Type == "m.policy.rule.room" && (x.TypedContent as PolicyRuleStateEventData).Entity == null)) {
                 <tr>
                     <td>@policyEvent.StateKey</td>
-                    <td>@policyEvent.RawContent.ToJson(false, true)</td>
+                    <td>@policyEvent.RawContent!.ToJson(false, true)</td>
                 </tr>
             }
             </tbody>
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Space.razor b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor
index 15c7c70..c37b8ab 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/Space.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/Space.razor
@@ -39,17 +39,21 @@
 
         var state = Room.GetFullStateAsync();
         await foreach (var stateEvent in state) {
-            if (stateEvent.Type == "m.space.child") {
-                var roomId = stateEvent.StateKey;
-                var room = await hs.GetRoom(roomId);
-                if (room is not null) {
-                    Rooms.Add(room);
+            switch (stateEvent.Type) {
+                case "m.space.child": {
+                    var roomId = stateEvent.StateKey;
+                    var room = await hs.GetRoom(roomId);
+                    if (room is not null) {
+                        Rooms.Add(room);
+                    }
+                    break;
                 }
-            }
-            else if (stateEvent.Type == "m.room.member") {
-                var serverName = stateEvent.StateKey.Split(':').Last();
-                if (!ServersInSpace.Contains(serverName)) {
-                    ServersInSpace.Add(serverName);
+                case "m.room.member": {
+                    var serverName = stateEvent.StateKey.Split(':').Last();
+                    if (!ServersInSpace.Contains(serverName)) {
+                        ServersInSpace.Add(serverName);
+                    }
+                    break;
                 }
             }
         }
@@ -89,10 +93,10 @@
     // await base.OnInitializedAsync();
     }
 
-    private async Task JoinAllRooms() {
-        foreach (var room in Rooms) {
-            room.JoinAsync(ServersInSpace.ToArray());
-        }
+    private Task JoinAllRooms() {
+        List<Task> tasks = Rooms.Select(room => room.JoinAsync(ServersInSpace.ToArray())).ToList();
+        Task.WaitAll(tasks.ToArray());
+        return Task.CompletedTask;
     }
 
 }
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor
index e01fca8..ef7cd51 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/StateEditor.razor
@@ -73,12 +73,12 @@
                 FilteredEvents.Add(_ev);
             }
             StateLoaded++;
-            if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) {
-                _lastUpdate = DateTime.Now;
-                status = $"Loaded {StateLoaded} state events";
-                StateHasChanged();
-                await Task.Delay(0);
-            }
+
+            if (!((DateTime.Now - _lastUpdate).TotalMilliseconds > 100)) continue;
+            _lastUpdate = DateTime.Now;
+            status = $"Loaded {StateLoaded} state events";
+            StateHasChanged();
+            await Task.Delay(0);
         }
 
         StateHasChanged();
@@ -98,7 +98,7 @@
         FilteredEvents = _FilteredEvents;
 
         if (_shownType is not null)
-            shownEventJson = _FilteredEvents.Where(x => x.Type == _shownType).First().RawContent.ToJson(indent: true, ignoreNull: true);
+            shownEventJson = _FilteredEvents.First(x => x.Type == _shownType).RawContent.ToJson(indent: true, ignoreNull: true);
 
         StateHasChanged();
     }
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor
index cf23c36..5a48b32 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/StateViewer.razor
@@ -91,12 +91,12 @@
                 FilteredEvents.Add(_ev);
             }
             StateLoaded++;
-            if ((DateTime.Now - _lastUpdate).TotalMilliseconds > 100) {
-                _lastUpdate = DateTime.Now;
-                status = $"Loaded {StateLoaded} state events";
-                StateHasChanged();
-                await Task.Delay(0);
-            }
+
+            if (!((DateTime.Now - _lastUpdate).TotalMilliseconds > 100)) continue;
+            _lastUpdate = DateTime.Now;
+            status = $"Loaded {StateLoaded} state events";
+            StateHasChanged();
+            await Task.Delay(0);
         }
 
         StateHasChanged();
diff --git a/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor b/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor
index 7fe89cc..4a5298b 100644
--- a/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor
+++ b/MatrixRoomUtils.Web/Pages/Rooms/Timeline.razor
@@ -45,7 +45,7 @@
 
     private StateEventResponse GetProfileEventBefore(StateEventResponse Event) => Events.TakeWhile(x => x != Event).Last(e => e.Type == "m.room.member" && e.StateKey == Event.Sender);
 
-    private Type ComponentType(StateEventResponse Event) => Event.TypedContent switch {
+    private Type ComponentType(StateEvent Event) => Event.TypedContent switch {
         RoomMessageEventData => typeof(TimelineMessageItem),
         RoomMemberEventData => typeof(TimelineMemberItem),
         _ => typeof(TimelineUnknownItem)