From 063fb6f12aea3a5b71c05beea22e7f6482c2f1cf Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Thu, 19 Oct 2023 07:21:41 +0200 Subject: Refactor, fix stuff --- MatrixRoomUtils.Web/Shared/NavMenu.razor | 49 ++++--- MatrixRoomUtils.Web/Shared/PortableDevTools.razor | 26 ---- MatrixRoomUtils.Web/Shared/RoomList.razor | 89 +++++++------ .../Shared/RoomListComponents/RoomListSpace.razor | 5 +- MatrixRoomUtils.Web/Shared/RoomListItem.razor | 143 ++++++++++----------- MatrixRoomUtils.Web/Shared/RoomListItem.razor.css | 56 ++++++-- .../TimelineComponents/BaseTimelineItem.razor | 1 - .../TimelineComponents/TimelineMemberItem.razor | 1 - .../TimelineComponents/TimelineMessageItem.razor | 1 - .../TimelineRoomCreateItem.razor | 1 - .../TimelineComponents/TimelineUnknownItem.razor | 1 - MatrixRoomUtils.Web/Shared/UserListItem.razor | 30 ++--- 12 files changed, 210 insertions(+), 193 deletions(-) delete mode 100644 MatrixRoomUtils.Web/Shared/PortableDevTools.razor (limited to 'MatrixRoomUtils.Web/Shared') diff --git a/MatrixRoomUtils.Web/Shared/NavMenu.razor b/MatrixRoomUtils.Web/Shared/NavMenu.razor index ad671c5..68b491d 100644 --- a/MatrixRoomUtils.Web/Shared/NavMenu.razor +++ b/MatrixRoomUtils.Web/Shared/NavMenu.razor @@ -14,61 +14,74 @@ Home + + + + - + - @* *@ + + + + + - @* *@ - @* *@ - + + + + + + + diff --git a/MatrixRoomUtils.Web/Shared/PortableDevTools.razor b/MatrixRoomUtils.Web/Shared/PortableDevTools.razor deleted file mode 100644 index 8ca10a0..0000000 --- a/MatrixRoomUtils.Web/Shared/PortableDevTools.razor +++ /dev/null @@ -1,26 +0,0 @@ -@* @if (Enabled) { *@ -@* Portable devtools (enabled) *@ -@*
*@ -@* $1$

Cache size: @RuntimeCache.GenericResponseCache.Sum(x => x.Value.Cache.Count)

#1# *@ -@*
*@ -@* } *@ -@* else { *@ -@* Portable devtools (disabled) *@ -@* } *@ -@* *@ -@* @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/RoomList.razor b/MatrixRoomUtils.Web/Shared/RoomList.razor index 91ebb0b..705f68c 100644 --- a/MatrixRoomUtils.Web/Shared/RoomList.razor +++ b/MatrixRoomUtils.Web/Shared/RoomList.razor @@ -3,8 +3,10 @@ @using LibMatrix.Extensions @using ArcaneLibs.Extensions @using LibMatrix.EventTypes.Spec.State -@if(Rooms.Count != RoomsWithTypes.Sum(x=>x.Value.Count)) { -

Fetching room details... @RoomsWithTypes.Sum(x=>x.Value.Count) out of @Rooms.Count done!

+@using System.Collections.ObjectModel +@using _Imports = MatrixRoomUtils.Web._Imports +@if (!StillFetching) { +

Fetching room details... @RoomsWithTypes.Sum(x => x.Value.Count) out of @Rooms.Count done!

@foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) {

@category.Key (@category.Value.Count)

} @@ -18,23 +20,35 @@ else { @code { [Parameter] - public List Rooms { get; set; } + public ObservableCollection Rooms { get; set; } + [Parameter] public ProfileResponseEventContent? GlobalProfile { get; set; } - Dictionary> RoomsWithTypes = new(); + [Parameter] + public bool StillFetching { get; set; } = true; + + [Parameter] + public EventCallback StillFetchingChanged { get; set; } - protected override async Task OnInitializedAsync() { + private Dictionary> RoomsWithTypes => Rooms is null ? new() : Rooms.GroupBy(x => GetRoomTypeName(x.CreationEventContent?.Type)).ToDictionary(x => x.Key, x => x.ToList()); + + protected override async Task OnParametersSetAsync() { var hs = await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; + Rooms.CollectionChanged += (_, args) => { + foreach (RoomInfo item in args.NewItems) { + item.PropertyChanged += (_, args2) => { + Console.WriteLine(args2); + if(args2.PropertyName == nameof(item.CreationEventContent)) + StateHasChanged(); + }; + } + }; - GlobalProfile ??= await hs.GetProfileAsync(hs.WhoAmI.UserId); - if (RoomsWithTypes.Any()) return; - - var tasks = Rooms.Select(ProcessRoom); - await Task.WhenAll(tasks); + // GlobalProfile ??= await hs.GetProfileAsync(hs.WhoAmI.UserId); - await base.OnInitializedAsync(); + await base.OnParametersSetAsync(); } private string GetRoomTypeName(string? roomType) => roomType switch { @@ -45,32 +59,33 @@ else { _ => roomType }; + // private static SemaphoreSlim _semaphoreSlim = new(8, 8); - private static SemaphoreSlim _semaphoreSlim = new(8, 8); - private async Task ProcessRoom(RoomInfo room) { - await _semaphoreSlim.WaitAsync(); - string roomType; - try { - var createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventContent; - roomType = GetRoomTypeName(createEvent.Type); - - if (roomType == "Room") { - var mjolnirData = await room.GetStateEvent("org.matrix.mjolnir.shortcode"); - if(mjolnirData?.RawContent?.ToJson(ignoreNull: true) is not null and not "{}") - roomType = "Legacy policy room"; - } - } - catch (MatrixException e) { - roomType = $"Error: {e.ErrorCode}"; - } - - if (!RoomsWithTypes.ContainsKey(roomType)) { - RoomsWithTypes.Add(roomType, new List()); - } - RoomsWithTypes[roomType].Add(room); - - StateHasChanged(); - _semaphoreSlim.Release(); - } + // private async Task ProcessRoom(RoomInfo room) { + // await _semaphoreSlim.WaitAsync(); + // string roomType; + // try { + // var createEvent = (await room.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventContent; + // roomType = GetRoomTypeName(createEvent.Type); + // + // if (roomType == "Room") { + // var mjolnirData = await room.GetStateEvent("org.matrix.mjolnir.shortcode"); + // if (mjolnirData?.RawContent?.ToJson(ignoreNull: true) is not null and not "{}") + // roomType = "Legacy policy room"; + // } + // } + // catch (MatrixException e) { + // roomType = $"Error: {e.ErrorCode}"; + // } + // + // // if (!RoomsWithTypes.ContainsKey(roomType)) { + // // RoomsWithTypes.Add(roomType, new List()); + // // } + // // RoomsWithTypes[roomType].Add(room); + // + // StateHasChanged(); + // _semaphoreSlim.Release(); + // } } + diff --git a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor index 1b54577..e08f98d 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListComponents/RoomListSpace.razor @@ -1,3 +1,4 @@ +@using System.Collections.ObjectModel Manage space
@@ -25,7 +26,7 @@ set => _breadcrumbs = value; } - private List Children { get; set; } = new(); + private ObservableCollection Children { get; set; } = new(); protected override async Task OnInitializedAsync() { if (Breadcrumbs == null) throw new ArgumentNullException(nameof(Breadcrumbs)); @@ -35,7 +36,7 @@ if (Breadcrumbs.Contains(room.RoomId)) continue; var roomInfo = KnownRooms.FirstOrDefault(x => x.Room.RoomId == room.RoomId); if (roomInfo is null) { - roomInfo = new RoomInfo { + roomInfo = new RoomInfo() { Room = room }; KnownRooms.Add(roomInfo); diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor index 0e1d70d..79c7f4e 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor @@ -5,41 +5,38 @@ @using LibMatrix.Homeservers @using LibMatrix.RoomTypes @using MatrixRoomUtils.Web.Classes.Constants -
- @if (OwnMemberState != null) { - - - @(OwnMemberState?.DisplayName ?? GlobalProfile?.DisplayName ?? "Loading...") - - -> - } - -
- @roomName - @if (ChildContent is not null) { - @ChildContent +@if (RoomInfo is not null) { +
+ @if (OwnMemberState != null) { + + + @(OwnMemberState?.DisplayName ?? GlobalProfile?.DisplayName ?? "Loading...") + + -> } -
+ @* style="@(ChildContent is not null ? "vertical-align: baseline;" : "")"*@ +
+ @RoomInfo.RoomName + @* @if (ChildContent is not null) { *@ + @* @ChildContent *@ + @* } *@ +
-
+
+} +else { +

Warning: RoomInfo is null!

+} @code { - [Parameter] - public RenderFragment? ChildContent { get; set; } - - [Parameter] - public GenericRoom? Room { get; set; } + // [Parameter] + // public RenderFragment? ChildContent { get; set; } [Parameter] public RoomInfo? RoomInfo { get; set; } - [Parameter] - public string? RoomId { get; set; } - [Parameter] public bool ShowOwnProfile { get; set; } = false; @@ -49,16 +46,20 @@ [CascadingParameter] public ProfileResponseEventContent? GlobalProfile { get; set; } - private string? roomName { get; set; } - - private string? roomIcon { get; set; } = "/icon-192.png"; - - private bool hasOldRoomVersion { get; set; } = false; - private bool hasDangerousRoomVersion { get; set; } = false; + private bool HasOldRoomVersion { get; set; } = false; + private bool HasDangerousRoomVersion { get; set; } = false; private static SemaphoreSlim _semaphoreSlim = new(8); private static AuthenticatedHomeserverGeneric? hs { get; set; } + protected override async Task OnParametersSetAsync() { + RoomInfo.PropertyChanged += (_, a) => { + Console.WriteLine(a.PropertyName); + StateHasChanged(); + }; + await base.OnParametersSetAsync(); + } + protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); @@ -67,34 +68,20 @@ hs ??= await MRUStorage.GetCurrentSessionOrNavigate(); if (hs is null) return; - if (Room is null && RoomId is null && RoomInfo is null) { - throw new ArgumentNullException(nameof(RoomId)); - } - - // sweep from roominfo to id - if (RoomInfo is not null) Room = RoomInfo.Room; - if(Room is not null) RoomId = Room.RoomId; - - //sweep from id to roominfo - if(RoomId is not null) Room ??= hs.GetRoom(RoomId); - if(Room is not null) RoomInfo ??= new RoomInfo { - Room = Room - }; - try { - await CheckRoomVersion(); - await GetRoomInfo(); - await LoadOwnProfile(); + await CheckRoomVersion(); + // await GetRoomInfo(); + // await LoadOwnProfile(); } catch (MatrixException e) { if (e is not { ErrorCode: "M_FORBIDDEN" }) { throw; } - roomName = "Error: " + e.Message; - roomIcon = "/blobfox_outage.gif"; + // RoomName = "Error: " + e.Message; + // RoomIcon = "/blobfox_outage.gif"; } catch (Exception e) { - Console.WriteLine($"Failed to load room info for {RoomId}: {e.Message}"); + Console.WriteLine($"Failed to load room info for {RoomInfo.Room.RoomId}: {e.Message}"); } _semaphoreSlim.Release(); } @@ -102,7 +89,7 @@ private async Task LoadOwnProfile() { if (!ShowOwnProfile) return; try { - OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.UserId)).TypedContent as RoomMemberEventContent; + // OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.UserId)).TypedContent as RoomMemberEventContent; GlobalProfile ??= await hs.GetProfileAsync(hs.UserId); } catch (MatrixException e) { @@ -117,35 +104,39 @@ } private async Task CheckRoomVersion() { - var ce = (await RoomInfo.GetStateEvent("m.room.create")).TypedContent as RoomCreateEventContent; + while (RoomInfo?.CreationEventContent is null) { + Console.WriteLine($"Room creation event content for {RoomInfo.Room.RoomId} is null..."); + await Task.Delay(Random.Shared.Next(1000, 2500)); + } + var ce = RoomInfo.CreationEventContent; if (int.TryParse(ce.RoomVersion, out var rv)) { if (rv < 10) - hasOldRoomVersion = true; + HasOldRoomVersion = true; } else // treat unstable room versions as dangerous - hasDangerousRoomVersion = true; + HasDangerousRoomVersion = true; if (RoomConstants.DangerousRoomVersions.Contains(ce.RoomVersion)) { - hasDangerousRoomVersion = true; - roomName = "Dangerous room: " + roomName; - } - } - - private async Task GetRoomInfo() { - try { - roomName ??= ((await RoomInfo.GetStateEvent("m.room.name"))?.TypedContent as RoomNameEventContent)?.Name ?? RoomId; - - var state = (await RoomInfo.GetStateEvent("m.room.avatar")).TypedContent as RoomAvatarEventContent; - if (state?.Url is { } url) { - roomIcon = await hsResolver.ResolveMediaUri(hs.ServerName, url); - // Console.WriteLine($"Got avatar for room {RoomId}: {roomIcon} ({url})"); - } - } - catch (MatrixException e) { - if (e is not { ErrorCode: "M_FORBIDDEN" }) { - throw; - } + HasDangerousRoomVersion = true; + // RoomName = "Dangerous room: " + RoomName; } } -} + // private async Task GetRoomInfo() { + // try { + // RoomName ??= ((await RoomInfo.GetStateEvent("m.room.name"))?.TypedContent as RoomNameEventContent)?.Name ?? RoomId; + // + // var state = (await RoomInfo.GetStateEvent("m.room.avatar")).TypedContent as RoomAvatarEventContent; + // if (state?.Url is { } url) { + // RoomIcon = await hsResolver.ResolveMediaUri(hs.ServerName, url); + // // Console.WriteLine($"Got avatar for room {RoomId}: {roomIcon} ({url})"); + // } + // } + // catch (MatrixException e) { + // if (e is not { ErrorCode: "M_FORBIDDEN" }) { + // throw; + // } + // } + // } + +} \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor.css b/MatrixRoomUtils.Web/Shared/RoomListItem.razor.css index da22d38..13de656 100644 --- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor.css +++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor.css @@ -1,10 +1,48 @@ -/*.imageUnloaded {*/ -/* scale: 3;*/ -/* opacity: 0.5;*/ -/* transition: scale 0.5s ease-in-out;*/ -/*}*/ - -.imageLoaded { - opacity: 1; - scale: 1; +.roomListItem { + background-color: #ffffff11; + border-radius: 25px; + margin: 8px; + width: fit-Content; +} + +.roomListItem.dangerousRoomVersion { + border: red 4px solid; +} + +.roomListItem.oldRoomVersion { + border: #FF0 1px solid; +} + +.avatar32 { + width: 32px; + height: 32px; + border-radius: 50%; +} + +.avatar32.vcenter { + vertical-align: baseline; +} + +.highlightChange { + background-color: red; + border-color: red; + border-width: 3px; + border-style: dashed; +} + +.inlineBlock { + display: inline-block; +} + +.centerVertical { + vertical-align: middle; + padding-right: 8px; +} + +.noLeftPadding { + padding-left: 0px; +} + +.border75 { + border-radius: 75px; } \ No newline at end of file diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor index e4ee873..9efeaab 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/BaseTimelineItem.razor @@ -1,4 +1,3 @@ -@using LibMatrix.Responses @using LibMatrix @using LibMatrix.Homeservers

BaseTimelineItem

diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor index b58afba..a454103 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMemberItem.razor @@ -1,4 +1,3 @@ -@using LibMatrix.Extensions @using ArcaneLibs.Extensions @using LibMatrix.EventTypes.Spec.State @inherits BaseTimelineItem diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor index 5dd87e0..8073406 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineMessageItem.razor @@ -1,4 +1,3 @@ -@using LibMatrix.Extensions @using ArcaneLibs.Extensions @inherits BaseTimelineItem diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor index ff77726..2d05151 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineRoomCreateItem.razor @@ -1,4 +1,3 @@ -@using LibMatrix.Extensions @using ArcaneLibs.Extensions @using LibMatrix.EventTypes.Spec.State @inherits BaseTimelineItem diff --git a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor index 69845d9..1ab530d 100644 --- a/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor +++ b/MatrixRoomUtils.Web/Shared/TimelineComponents/TimelineUnknownItem.razor @@ -1,4 +1,3 @@ -@using LibMatrix.Extensions @using ArcaneLibs.Extensions @inherits BaseTimelineItem diff --git a/MatrixRoomUtils.Web/Shared/UserListItem.razor b/MatrixRoomUtils.Web/Shared/UserListItem.razor index 9010820..96e8e64 100644 --- a/MatrixRoomUtils.Web/Shared/UserListItem.razor +++ b/MatrixRoomUtils.Web/Shared/UserListItem.razor @@ -1,8 +1,9 @@ @using LibMatrix.Helpers @using LibMatrix.EventTypes.Spec.State +@using LibMatrix.Homeservers
- - @profileName + + @User?.DisplayName
@if (ChildContent is not null) { @@ -18,36 +19,25 @@ public RenderFragment? ChildContent { get; set; } [Parameter] - public ProfileResponseEventContent User { get; set; } + public ProfileResponseEventContent? User { get; set; } [Parameter] public string UserId { get; set; } - private string? profileAvatar { get; set; } = "/icon-192.png"; - private string? profileName { get; set; } = "Loading..."; - - private static SemaphoreSlim _semaphoreSlim = new(8); + private AuthenticatedHomeserverGeneric _homeserver = null!; protected override async Task OnInitializedAsync() { - await base.OnInitializedAsync(); - - var hs = await MRUStorage.GetCurrentSessionOrNavigate(); - if (hs is null) return; - - await _semaphoreSlim.WaitAsync(); + _homeserver = await MRUStorage.GetCurrentSessionOrNavigate(); + if (_homeserver is null) return; if (User == null) { if (UserId == null) { throw new ArgumentNullException(nameof(UserId)); } - User = await hs.GetProfileAsync(UserId); + User = await _homeserver.GetProfileAsync(UserId); } - // UserId = User.; - profileAvatar = await hsResolver.ResolveMediaUri(hs.ServerName, User.AvatarUrl); - profileName = User.DisplayName; - - _semaphoreSlim.Release(); + await base.OnInitializedAsync(); } -} +} \ No newline at end of file -- cgit 1.5.1