From bb8c2637af3b7982e7a4b2fd15e2fbec613d0848 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 30 Jun 2023 03:36:58 +0200 Subject: Todays progress --- .../Shared/IndexComponents/IndexUserItem.razor | 54 -------------- MatrixRoomUtils.Web/Shared/InlineUserItem.razor | 24 +++---- MatrixRoomUtils.Web/Shared/LogView.razor | 83 +++++++++++----------- MatrixRoomUtils.Web/Shared/MainLayout.razor | 16 ++--- MatrixRoomUtils.Web/Shared/NavMenu.razor | 5 -- MatrixRoomUtils.Web/Shared/PortableDevTools.razor | 52 +++++++------- MatrixRoomUtils.Web/Shared/RoomList.razor | 17 +++-- .../RoomListComponents/RoomListCategory.razor | 4 +- .../Shared/RoomListComponents/RoomListSpace.razor | 4 +- MatrixRoomUtils.Web/Shared/RoomListItem.razor | 60 +++++++--------- .../TimelineComponents/TimelineMemberItem.razor | 23 +++--- .../TimelineComponents/TimelineMessageItem.razor | 2 +- MatrixRoomUtils.Web/Shared/UserListItem.razor | 15 ++-- 13 files changed, 146 insertions(+), 213 deletions(-) delete mode 100644 MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor (limited to 'MatrixRoomUtils.Web/Shared') diff --git a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor b/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor deleted file mode 100644 index 975da43..0000000 --- a/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor +++ /dev/null @@ -1,54 +0,0 @@ -@using MatrixRoomUtils.Core.Extensions -@inject ILocalStorageService LocalStorage -@inject NavigationManager NavigationManager - -
- -

- - @User.Profile.DisplayName on @User.LoginResponse.HomeServer - Remove -

-

Member of @_roomCount rooms

- -
- -@code { - - [Parameter] - public UserInfo User { get; set; } = null!; - - private string? _avatarUrl { get; set; } - private int _roomCount { get; set; } = 0; - - protected override async Task OnInitializedAsync() { - await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); - - if (User.Profile.AvatarUrl != null && User.Profile.AvatarUrl != "") - _avatarUrl = RuntimeCache.CurrentHomeServer.ResolveMediaUri(User.Profile.AvatarUrl); - else _avatarUrl = "https://api.dicebear.com/6.x/identicon/svg?seed=" + User.LoginResponse.UserId; - try { - _roomCount = (await RuntimeCache.CurrentHomeServer.GetJoinedRooms()).Count; - } - catch { - _roomCount = -1; - } - await base.OnInitializedAsync(); - } - - private async Task RemoveUser() { - Console.WriteLine(User.ToJson()); - RuntimeCache.LoginSessions.Remove(User.AccessToken); - - StateHasChanged(); - } - - private async Task SetCurrent() { - RuntimeCache.LastUsedToken = User.AccessToken; - //RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(LocalStorageWrapper.LoginSessions[Token].LoginResponse.HomeServer); - await LocalStorageWrapper.SaveToLocalStorage(LocalStorage); - await LocalStorageWrapper.InitialiseRuntimeVariables(LocalStorage); - StateHasChanged(); - } - -} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor index 44f3b0a..a498c70 100644 --- a/MatrixRoomUtils.Web/Shared/InlineUserItem.razor +++ b/MatrixRoomUtils.Web/Shared/InlineUserItem.razor @@ -1,11 +1,12 @@ @using MatrixRoomUtils.Core.Responses @using MatrixRoomUtils.Core.StateEventTypes +@using MatrixRoomUtils.Core.Helpers
- + @ProfileName
- @if (ChildContent != null) { + @if (ChildContent is not null) { @ChildContent }
@@ -21,7 +22,7 @@ public ProfileResponse User { get; set; } [Parameter] - public string UserId { get; set; } + public string? UserId { get; set; } [Parameter] public string? ProfileAvatar { get; set; } = null; @@ -33,19 +34,16 @@ protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); - + var hs = await MRUStorage.GetCurrentSession(); + await _semaphoreSlim.WaitAsync(); - if (User == null) { - if (UserId == null) { - throw new ArgumentNullException(nameof(UserId)); - } - User = await RuntimeCache.CurrentHomeServer.GetProfile(UserId); - } + if (User == null && UserId == null) + throw new ArgumentNullException(nameof(UserId)); + User ??= await hs.GetProfile(UserId); + - // UserId = User.; - ProfileAvatar ??= RuntimeCache.CurrentHomeServer.ResolveMediaUri(User.AvatarUrl); + ProfileAvatar ??= MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, User.AvatarUrl); ProfileName ??= User.DisplayName; _semaphoreSlim.Release(); diff --git a/MatrixRoomUtils.Web/Shared/LogView.razor b/MatrixRoomUtils.Web/Shared/LogView.razor index 2f83cb2..d541b82 100644 --- a/MatrixRoomUtils.Web/Shared/LogView.razor +++ b/MatrixRoomUtils.Web/Shared/LogView.razor @@ -1,42 +1,41 @@ -@using System.Text -@if (LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers) { - Logs -
-
-        @_stringBuilder
-    
-} - -@code { - StringBuilder _stringBuilder = new(); - - 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); - Console.SetError(sw); - //keep updated - var length = 0; - Task.Run(async () => { - while (true) { - await Task.Delay(100); - if (_stringBuilder.Length != length) { - StateHasChanged(); - length = _stringBuilder.Length; - } - } - // ReSharper disable once FunctionNeverReturns - This is intentional behavior - }); - await base.OnInitializedAsync(); - } - -} \ No newline at end of file +@* @using System.Text *@ +@* @if (LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers) { *@ +@* Logs *@ +@*
*@ +@*
 *@
+@*         @_stringBuilder *@
+@*     
*@ +@* } *@ +@* *@ +@* @code { *@ +@* StringBuilder _stringBuilder = new(); *@ +@* *@ +@* protected override async Task OnInitializedAsync() { *@ +@* 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); *@ +@* Console.SetError(sw); *@ +@* //keep updated *@ +@* var length = 0; *@ +@* Task.Run(async () => { *@ +@* while (true) { *@ +@* await Task.Delay(100); *@ +@* if (_stringBuilder.Length != length) { *@ +@* StateHasChanged(); *@ +@* length = _stringBuilder.Length; *@ +@* } *@ +@* } *@ +@* // ReSharper disable once FunctionNeverReturns - This is intentional behavior *@ +@* }); *@ +@* await base.OnInitializedAsync(); *@ +@* } *@ +@* *@ +@* } *@ \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/MainLayout.razor b/MatrixRoomUtils.Web/Shared/MainLayout.razor index 317f9e6..691acbb 100644 --- a/MatrixRoomUtils.Web/Shared/MainLayout.razor +++ b/MatrixRoomUtils.Web/Shared/MainLayout.razor @@ -29,14 +29,14 @@ using var hc = new HttpClient(); var hr = await hc.SendAsync(new HttpRequestMessage(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); - } + + // TODO: fix console logging toggle + // 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 9ddbd84..5f9ad8a 100644 --- a/MatrixRoomUtils.Web/Shared/NavMenu.razor +++ b/MatrixRoomUtils.Web/Shared/NavMenu.razor @@ -23,11 +23,6 @@
Main tools

-