about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-23 08:51:02 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-05-23 08:51:02 +0200
commit3ef3e5caa65458e595e2303358322626c7da1dda (patch)
tree6a60d401da8b5f906a423601ac4c135d44e896d1 /MatrixRoomUtils.Web/Shared
parentLocal changes (diff)
downloadMatrixUtils-3ef3e5caa65458e595e2303358322626c7da1dda.tar.xz
Add numerous new things
Diffstat (limited to 'MatrixRoomUtils.Web/Shared')
-rw-r--r--MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor24
-rw-r--r--MatrixRoomUtils.Web/Shared/LogView.razor26
-rw-r--r--MatrixRoomUtils.Web/Shared/MainLayout.razor14
-rw-r--r--MatrixRoomUtils.Web/Shared/NavMenu.razor9
-rw-r--r--MatrixRoomUtils.Web/Shared/PortableDevTools.razor31
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor33
6 files changed, 111 insertions, 26 deletions
diff --git a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
index 08161b2..87ef831 100644
--- a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
+++ b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
@@ -10,22 +10,30 @@
 
 <div style="margin-bottom: 1em;">
     <img style="border-radius: 50%; height: 3em; width: 3em;" src="@_avatarUrl"/>
-    <span style="margin-left: 1em;"><input type="radio" name="csa" checked="@(RuntimeCache.LastUsedToken == User.AccessToken)" onclick="@SetCurrent" style="text-decoration-line: unset;"/> <b>@User.Profile.DisplayName</b> on <b>@User.LoginResponse.HomeServer</b></span>
-    <a href="#" onclick="@RemoveUser">Remove</a>
+    <p style="margin-left: 1em; margin-top: -0.5em; display: inline-block;">
+        <input type="radio" name="csa" checked="@(RuntimeCache.LastUsedToken == User.AccessToken)" onclick="@SetCurrent" style="text-decoration-line: unset;"/>
+        <b>@User.Profile.DisplayName</b> on <b>@User.LoginResponse.HomeServer</b>
+        <a href="#" onclick="@RemoveUser">Remove</a>
+    </p>
+    <p style="margin-top: -1.5em; margin-left: 4em;">Member of @_roomCount rooms</p>
+
 </div>
 
 @code {
 
     [Parameter]
     public UserInfo User { get; set; } = null!;
-    
+
     private string _avatarUrl { get; set; }
+    private int _roomCount { get; set; } = 0;
 
     protected override async Task OnInitializedAsync()
     {
+        var hs = await new AuthenticatedHomeServer(User.LoginResponse.UserId, User.AccessToken, User.LoginResponse.HomeServer).Configure();
         if (User.Profile.AvatarUrl != null && User.Profile.AvatarUrl != "")
-            _avatarUrl = await (await new AuthenticatedHomeServer(User.LoginResponse.UserId, User.AccessToken, User.LoginResponse.HomeServer).Configure()).ResolveMediaUri(User.Profile.AvatarUrl);
+            _avatarUrl = await hs.ResolveMediaUri(User.Profile.AvatarUrl);
         else _avatarUrl = "https://api.dicebear.com/6.x/identicon/svg?seed=" + User.LoginResponse.UserId;
+        _roomCount = (await hs.GetJoinedRooms()).Count;
         await base.OnInitializedAsync();
     }
 
@@ -34,15 +42,17 @@
         Console.WriteLine(User.ToJson());
         RuntimeCache.LoginSessions.Remove(User.AccessToken);
         await LocalStorageWrapper.ReloadLocalStorage(LocalStorage);
-        
+
         StateHasChanged();
     }
+
     private async Task SetCurrent()
     {
         RuntimeCache.LastUsedToken = User.AccessToken;
-        //RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(LocalStorageWrapper.LoginSessions[Token].LoginResponse.HomeServer);
+    //RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(LocalStorageWrapper.LoginSessions[Token].LoginResponse.HomeServer);
         await LocalStorageWrapper.ReloadLocalStorage(LocalStorage);
-        
+
         StateHasChanged();
     }
+
 }
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/LogView.razor b/MatrixRoomUtils.Web/Shared/LogView.razor
index f60f271..80fd355 100644
--- a/MatrixRoomUtils.Web/Shared/LogView.razor
+++ b/MatrixRoomUtils.Web/Shared/LogView.razor
@@ -1,13 +1,27 @@
 @using System.Text
-<u>Logs</u><br/>
-<pre>
-    @_stringBuilder
-</pre>
+@if (LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers)
+{
+    <u>Logs</u>
+    <br/>
+    <pre>
+        @_stringBuilder
+    </pre>
+}
 
 @code {
     StringBuilder _stringBuilder = new();
-    protected override void OnInitialized()
+    protected override async Task OnInitializedAsync()
     {
+        await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+        if (!LocalStorageWrapper.Settings.DeveloperSettings.EnableConsoleLogging)
+        {
+            Console.WriteLine("Console logging disabled!");
+            var _sw = new StringWriter();
+            Console.SetOut(_sw);
+            Console.SetError(_sw);
+            return;
+        }
+        if (!LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers) return;
         //intecept stdout with textwriter to get logs
         var sw = new StringWriter(_stringBuilder);
         Console.SetOut(sw);
@@ -27,6 +41,6 @@
             }
     // ReSharper disable once FunctionNeverReturns - This is intentional behavior
         });
-        base.OnInitialized();
+        await base.OnInitializedAsync();
     }
 }
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/MainLayout.razor b/MatrixRoomUtils.Web/Shared/MainLayout.razor
index da27978..b1b0b53 100644
--- a/MatrixRoomUtils.Web/Shared/MainLayout.razor
+++ b/MatrixRoomUtils.Web/Shared/MainLayout.razor
@@ -1,5 +1,4 @@
-@using MatrixRoomUtils.Core.Extensions
-@using System.Net
+@using System.Net
 @inherits LayoutComponentBase
 
 <div class="page">
@@ -9,6 +8,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://matrix.to/#/%23mru%3Arory.gay?via=rory.gay&via=matrix.org&via=feline.support" target="_blank">Matrix</a>
             @if (showDownload)
@@ -31,6 +31,16 @@
         using var hc = new HttpClient();
         var hr = await hc.SendAsync(new(HttpMethod.Head, NavigationManager.ToAbsoluteUri("/MRU-BIN.tar.xz").AbsoluteUri));
         showDownload = hr.StatusCode == HttpStatusCode.OK;
+
+        await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+        if (!LocalStorageWrapper.Settings.DeveloperSettings.EnableConsoleLogging)
+        {
+            Console.WriteLine("Console logging disabled!");
+            var sw = new StringWriter();
+            Console.SetOut(sw);
+            Console.SetError(sw);
+        }
+        
         await base.OnInitializedAsync();
 
     }
diff --git a/MatrixRoomUtils.Web/Shared/NavMenu.razor b/MatrixRoomUtils.Web/Shared/NavMenu.razor
index b77935d..8136715 100644
--- a/MatrixRoomUtils.Web/Shared/NavMenu.razor
+++ b/MatrixRoomUtils.Web/Shared/NavMenu.razor
@@ -52,10 +52,15 @@
             <hr style="margin-bottom: 0em;"/>
         </div>
         <div class="nav-item px-3">
-            <NavLink class="nav-link" href="MediaLocator">
-                <span class="oi oi-plus" aria-hidden="true"></span> Media locator
+            <NavLink class="nav-link" href="KnownHomeserverList">
+                <span class="oi oi-plus" aria-hidden="true"></span> Known homeserver list
             </NavLink>
         </div>
+        @* <div class="nav-item px-3"> *@
+        @*     <NavLink class="nav-link" href="MediaLocator"> *@
+        @*         <span class="oi oi-plus" aria-hidden="true"></span> Media locator *@
+        @*     </NavLink> *@
+        @* </div> *@
         <div class="nav-item px-3">
             <h5 style="margin-left: 1em;">MRU</h5>
             <hr style="margin-bottom: 0em;"/>
diff --git a/MatrixRoomUtils.Web/Shared/PortableDevTools.razor b/MatrixRoomUtils.Web/Shared/PortableDevTools.razor
new file mode 100644
index 0000000..84e7791
--- /dev/null
+++ b/MatrixRoomUtils.Web/Shared/PortableDevTools.razor
@@ -0,0 +1,31 @@
+
+@if (Enabled)
+{
+    <a href="/DevOptions">Portable devtools (enabled)</a>
+    <div id="PortableDevTools" style="position: fixed; bottom: 0; right: 0; min-width: 200px; min-height: 100px; background: #0002;" draggable>
+        <p>Cache size: @RuntimeCache.GenericResponseCache.Sum(x=>x.Value.Cache.Count)</p>
+    </div>
+}
+else {
+    <a href="/DevOptions">Portable devtools (disabled)</a>
+}
+
+@code {
+    private bool Enabled { get; set; } = LocalStorageWrapper.Settings.DeveloperSettings.EnablePortableDevtools;
+
+    protected override async Task OnInitializedAsync()
+    {
+        // if(!RuntimeCache.WasLoaded)
+            // await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
+        // StateHasChanged();
+        Task.Run(async () =>
+        {
+            while (true)
+            {
+                await Task.Delay(100);
+                Enabled = LocalStorageWrapper.Settings.DeveloperSettings.EnablePortableDevtools;
+                StateHasChanged();
+            }
+        });
+    }
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index 15ca5c0..16ced75 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -3,17 +3,27 @@
 <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"/>
+        <img style="@(ChildContent != null ? "vertical-align: baseline;":"") 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>
+    <img style="@(ChildContent != null ? "vertical-align: baseline;":"") width: 32px; height:  32px; border-radius: 50%;" src="@roomIcon"/>
+    <div style="display: inline-block;">
+        <span style="vertical-align: middle; padding-right: 8px;">@roomName</span>
+        @if (ChildContent != null)
+        {
+            @ChildContent
+        }
+    </div>
+
 </div>
 
 @code {
 
     [Parameter]
+    public RenderFragment? ChildContent { get; set; }
+
+    [Parameter]
     public Room Room { get; set; }
 
     [Parameter]
@@ -33,8 +43,9 @@
     protected override async Task OnInitializedAsync()
     {
         await base.OnInitializedAsync();
-        
-        if(!RuntimeCache.WasLoaded) {
+
+        if (!RuntimeCache.WasLoaded)
+        {
             Console.WriteLine("Loading from local storage");
             await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage);
         }
@@ -47,6 +58,10 @@
             }
             Room = await RuntimeCache.CurrentHomeServer.GetRoom(RoomId);
         }
+        else
+        {
+            RoomId = Room.RoomId;
+        }
 
         roomName = await Room.GetNameAsync();
         if (roomName == null)
@@ -66,8 +81,8 @@
 
         if (ShowOwnProfile)
         {
-            var profile = await RuntimeCache.CurrentHomeServer.GetProfile(RuntimeCache.CurrentHomeServer.UserId, debounce: true); 
-                
+            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)
             {
@@ -86,7 +101,7 @@
                 {
                     hasCustomProfileName = _name.GetString() != profile.DisplayName;
                     profileName = _name.GetString();
-                    // Console.WriteLine($"{profile.DisplayName} - {_name.GetString()}: {hasCustomProfileName}");
+    // Console.WriteLine($"{profile.DisplayName} - {_name.GetString()}: {hasCustomProfileName}");
                 }
                 else
                 {
@@ -94,7 +109,7 @@
                 }
             }
         }
-        if(Random.Shared.Next(100) == 1)
+        if (Random.Shared.Next(100) == 1)
             await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
     }