about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixRoomUtils.Web/Shared')
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomList.razor14
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor17
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor4
-rw-r--r--MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor7
4 files changed, 24 insertions, 18 deletions
diff --git a/MatrixRoomUtils.Web/Shared/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor
index db2d059..fadec1c 100644
--- a/MatrixRoomUtils.Web/Shared/RoomList.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomList.razor
@@ -2,9 +2,8 @@
 @using MatrixRoomUtils.Core.StateEventTypes
 @using MatrixRoomUtils.Core.StateEventTypes.Common
 @using MatrixRoomUtils.Core.StateEventTypes.Spec
-<p>@Rooms.Count rooms total, @RoomsWithTypes.Sum(x=>x.Value.Count) fetched so far...</p>
 @if(Rooms.Count != RoomsWithTypes.Sum(x=>x.Value.Count)) {
-    <p>Fetching more rooms...</p>
+    <p>Fetching room details... @RoomsWithTypes.Sum(x=>x.Value.Count) out of @Rooms.Count done!</p>
     @foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) {
         <p>@category.Key (@category.Value.Count)</p>
     }
@@ -28,7 +27,7 @@ else {
         GlobalProfile ??= await (await MRUStorage.GetCurrentSession())!.GetProfile((await MRUStorage.GetCurrentSession())!.WhoAmI.UserId);
         if (RoomsWithTypes.Any()) return;
 
-        var tasks = Rooms.Select(AddRoom);
+        var tasks = Rooms.Select(ProcessRoom);
         await Task.WhenAll(tasks);
 
         await base.OnInitializedAsync();
@@ -44,7 +43,7 @@ else {
 
     
     private static SemaphoreSlim _semaphoreSlim = new(8, 8);
-    private async Task AddRoom(RoomInfo room) {
+    private async Task ProcessRoom(RoomInfo room) {
         await _semaphoreSlim.WaitAsync();
         string roomType;
         try {
@@ -56,11 +55,6 @@ else {
                 if(mjolnirData?.RawContent?.ToJson(ignoreNull: true) is not null and not "{}")
                     roomType = "Legacy policy room";
             }
-            //prefetch some stuff
-            await Task.WhenAll(
-                room.GetStateEvent("m.room.name"),
-                room.GetStateEvent("m.room.name")
-                );
         }
         catch (MatrixException e) {
             roomType = $"Error: {e.ErrorCode}";
@@ -71,9 +65,7 @@ else {
         }
         RoomsWithTypes[roomType].Add(room);
         
-        // if (RoomsWithTypes[roomType].Count % 10 == 0)
             StateHasChanged();
-        // await Task.Delay(100);
         _semaphoreSlim.Release();
     }
 
diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
index 4be3c1f..709f2d7 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
@@ -1,12 +1,13 @@
 @using MatrixRoomUtils.Core.StateEventTypes
 @using MatrixRoomUtils.Core.StateEventTypes.Spec
+@using MatrixRoomUtils.Web.Classes.Constants
 <details>
     <summary>@roomType (@rooms.Count)</summary>
     @foreach (var room in rooms) {
         <div class="room-list-item">
             <RoomListItem RoomInfo="@room" ShowOwnProfile="@(roomType == "Room")"></RoomListItem>
-            @if (room.StateEvents.Any(x => x.Type == "m.room.create")) {
-                
+            @if (RoomVersionDangerLevel(room) != 0) {
+                <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>
             }
             <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.Room.RoomId}/Timeline")">View timeline</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton>
             <MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/View")">View state</MatrixRoomUtils.Web.Shared.SimpleComponents.LinkButton>
@@ -30,5 +31,15 @@
 
     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");
+        if (roomVersion is null) return 0;
+        var roomVersionContent = roomVersion.TypedContent as RoomCreateEventData;
+        if (roomVersionContent is null) return 0;
+        if (RoomConstants.DangerousRoomVersions.Contains(roomVersionContent.RoomVersion)) return 2;
+        if (roomVersionContent.RoomVersion != RoomConstants.RecommendedRoomVersion) return 1;
+        return 0;
+    }
+
 }
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index d35c9ab..b89fb18 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -3,6 +3,7 @@
 @using MatrixRoomUtils.Core.Helpers
 @using MatrixRoomUtils.Core.StateEventTypes
 @using MatrixRoomUtils.Core.StateEventTypes.Spec
+@using MatrixRoomUtils.Web.Classes.Constants
 <div class="roomListItem" id="@RoomId" style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-Content; @(hasDangerousRoomVersion ? "border: red 4px solid;" : hasOldRoomVersion ? "border: #FF0 1px solid;" : "")">
     @if (OwnMemberState != null) {
         <img class="imageUnloaded @(string.IsNullOrWhiteSpace(OwnMemberState?.AvatarUrl ?? GlobalProfile?.AvatarUrl) ? "" : "imageLoaded")"
@@ -56,7 +57,6 @@
 
     private static SemaphoreSlim _semaphoreSlim = new(8);
     private static AuthenticatedHomeServer? hs { get; set; }
-    private static readonly string[] DangerousRoomVersions = { "1", "8" };
 
     protected override async Task OnInitializedAsync() {
         await base.OnInitializedAsync();
@@ -113,7 +113,7 @@
             else // treat unstable room versions as dangerous
                 hasDangerousRoomVersion = true;
 
-            if (DangerousRoomVersions.Contains(ce.RoomVersion)) {
+            if (RoomConstants.DangerousRoomVersions.Contains(ce.RoomVersion)) {
                 hasDangerousRoomVersion = true;
                 roomName = "Dangerous room: " + roomName;
             }
diff --git a/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor b/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor
index 8c9e73b..09b5c32 100644
--- a/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor
+++ b/MatrixRoomUtils.Web/Shared/SimpleComponents/LinkButton.razor
@@ -1,4 +1,4 @@
-<a href="@href" class="btn btn-primary">
+<a href="@href" class="btn btn-primary" style="background-color: @(Color ?? "#1b6ec2");">
     @ChildContent
 </a>
 
@@ -9,5 +9,8 @@
     
     [Parameter]
     public RenderFragment ChildContent { get; set; }
-    
+
+    [Parameter]
+    public string? Color { get; set; }
+
 }
\ No newline at end of file