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/MainLayout.razor16
-rw-r--r--MatrixRoomUtils.Web/Shared/NavMenu.razor7
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor48
3 files changed, 69 insertions, 2 deletions
diff --git a/MatrixRoomUtils.Web/Shared/MainLayout.razor b/MatrixRoomUtils.Web/Shared/MainLayout.razor
index 4aa01c6..87442d8 100644
--- a/MatrixRoomUtils.Web/Shared/MainLayout.razor
+++ b/MatrixRoomUtils.Web/Shared/MainLayout.razor
@@ -1,4 +1,6 @@
-@inherits LayoutComponentBase
+@using MatrixRoomUtils.Core.Extensions
+@using System.Net
+@inherits LayoutComponentBase
 
 <div class="page">
     <div class="sidebar">
@@ -9,6 +11,10 @@
         <div class="top-row px-4">
             <a href="https://git.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>
+            }
         </div>
 
         <article class="content px-4">
@@ -18,6 +24,14 @@
 </div>
 
 @code {
+    private bool showDownload { get; set; } = false;
 
+    protected override async Task OnInitializedAsync()
+    {
+        using var hc = new HttpClient();
+        var hr = await hc.SendAsync(new(HttpMethod.Head, NavigationManager.ToAbsoluteUri("/MRU.tar.xz").AbsoluteUri));
+        showDownload = hr.StatusCode == HttpStatusCode.OK;
+        await base.OnInitializedAsync();
 
+    }
 }
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/NavMenu.razor b/MatrixRoomUtils.Web/Shared/NavMenu.razor
index 5d80154..18ea33d 100644
--- a/MatrixRoomUtils.Web/Shared/NavMenu.razor
+++ b/MatrixRoomUtils.Web/Shared/NavMenu.razor
@@ -15,11 +15,16 @@
             </NavLink>
         </div>
         <div class="nav-item px-3">
-            <NavLink class="nav-link" href="export">
+            <NavLink class="nav-link" href="Export">
                 <span class="oi oi-plus" aria-hidden="true"></span> Export data
             </NavLink>
         </div>
         <div class="nav-item px-3">
+            <NavLink class="nav-link" href="RoomManager">
+                <span class="oi oi-plus" aria-hidden="true"></span> Manage Rooms
+            </NavLink>
+        </div>
+        <div class="nav-item px-3">
             <NavLink class="nav-link" href="PolicyListEditor">
                 <span class="oi oi-plus" aria-hidden="true"></span> Policy list editor
             </NavLink>
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index 31fca4c..d2c844d 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -1,17 +1,35 @@
+@using MatrixRoomUtils.Core.Authentication
+@using System.Text.Json
 <div style="background-color: #ffffff11; border-radius: 25px; margin: 8px; width: fit-content;">
+    @if (ShowOwnProfile)
+    {
+        <img style="width: 32px; height:  32px; border-radius: 50%; @(hasCustomProfileAvatar ? "border-color: red; border-width: 3px; border-style: dashed;" : "")" src="@profileAvatar"/>
+        <span style="vertical-align: middle; margin-right: 8px; border-radius: 75px; @(hasCustomProfileName ? "background-color: red;" : "")">@profileName</span>
+        <span style="vertical-align: middle; padding-right: 8px; padding-left: 0px;">-></span>
+    }
     <img style="width: 32px; height:  32px; border-radius: 50%;" src="@roomIcon"/>
     <span style="vertical-align: middle; padding-right: 8px;">@roomName</span>
 </div>
 
 @code {
+
     [Parameter]
     public Room Room { get; set; }
+
     [Parameter]
     public string RoomId { get; set; }
 
+    [Parameter]
+    public bool ShowOwnProfile { get; set; } = false;
+
     private string roomName { get; set; } = "Loading...";
     private string roomIcon { get; set; } = "/icon-192.png";
 
+    private string profileAvatar { get; set; } = "/icon-192.png";
+    private string profileName { get; set; } = "Loading...";
+    private bool hasCustomProfileAvatar { get; set; } = false;
+    private bool hasCustomProfileName { get; set; } = false;
+
     protected override async Task OnInitializedAsync()
     {
         await base.OnInitializedAsync();
@@ -40,6 +58,36 @@
             }
         }
 
+        if (ShowOwnProfile)
+        {
+            var profile = await RuntimeCache.CurrentHomeServer.GetProfile(RuntimeCache.CurrentHomeServer.UserId, debounce: true); 
+                
+            var memberState = await Room.GetStateAsync("m.room.member", RuntimeCache.CurrentHomeServer.UserId);
+            if (memberState.HasValue)
+            {
+                memberState.Value.TryGetProperty("avatar_url", out var _avatar);
+                if (_avatar.ValueKind == JsonValueKind.String)
+                {
+                    hasCustomProfileAvatar = _avatar.GetString() != profile.AvatarUrl;
+                    profileAvatar = await RuntimeCache.CurrentHomeServer.ResolveMediaUri(_avatar.GetString());
+                }
+                else
+                {
+                    profileAvatar = "/icon-192.png";
+                }
+                memberState.Value.TryGetProperty("displayname", out var _name);
+                if (_name.ValueKind == JsonValueKind.String)
+                {
+                    hasCustomProfileName = _name.GetString() != profile.DisplayName;
+                    profileName = _name.GetString();
+                    Console.WriteLine($"{profile.DisplayName} - {_name.GetString()}: {hasCustomProfileName}");
+                }
+                else
+                {
+                    profileName = "Unnamed user";
+                }
+            }
+        }
     }
 
 }
\ No newline at end of file