about summary refs log tree commit diff
path: root/MatrixUtils.Web/Shared
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-02-18 07:41:20 +0100
committerRory& <root@rory.gay>2025-02-18 07:41:20 +0100
commit373e3a481e9b16b328002426d416344a87ef1058 (patch)
tree17b50a14479099eba4b2ab490ffd5b28cd12c440 /MatrixUtils.Web/Shared
parentVarious changes (diff)
downloadMatrixUtils-373e3a481e9b16b328002426d416344a87ef1058.tar.xz
Some cleanup
Diffstat (limited to 'MatrixUtils.Web/Shared')
-rw-r--r--MatrixUtils.Web/Shared/InlineUserItem.razor1
-rw-r--r--MatrixUtils.Web/Shared/MxcAvatar.razor52
-rw-r--r--MatrixUtils.Web/Shared/MxcImage.razor82
-rw-r--r--MatrixUtils.Web/Shared/RoomList.razor5
-rw-r--r--MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor11
-rw-r--r--MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor11
-rw-r--r--MatrixUtils.Web/Shared/RoomListItem.razor20
-rw-r--r--MatrixUtils.Web/Shared/UserListItem.razor7
8 files changed, 102 insertions, 87 deletions
diff --git a/MatrixUtils.Web/Shared/InlineUserItem.razor b/MatrixUtils.Web/Shared/InlineUserItem.razor

index 50fa9e1..eaf7a92 100644 --- a/MatrixUtils.Web/Shared/InlineUserItem.razor +++ b/MatrixUtils.Web/Shared/InlineUserItem.razor
@@ -39,7 +39,6 @@ protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); - Homeserver ??= await RmuStorage.GetCurrentSessionOrNavigate(); if(Homeserver is null) return; await _semaphoreSlim.WaitAsync(); diff --git a/MatrixUtils.Web/Shared/MxcAvatar.razor b/MatrixUtils.Web/Shared/MxcAvatar.razor
index 02aff72..822894a 100644 --- a/MatrixUtils.Web/Shared/MxcAvatar.razor +++ b/MatrixUtils.Web/Shared/MxcAvatar.razor
@@ -1,17 +1,16 @@ -<StreamedImage Stream="@_stream" style="@StyleString"/> +<MxcImage Homeserver="@Homeserver" Uri="@MxcUri" style="@StyleString"/> @code { - private string _mxcUri; private string _style; - private Stream _stream; - + [Parameter] - public string MxcUri { - get => _mxcUri ?? ""; + public string? MxcUri { + get; set { - if(_mxcUri == value) return; - _mxcUri = value; - UriHasChanged(value); + if(field == value) return; + field = value; + // UriHasChanged(value); + StateHasChanged(); } } @@ -25,31 +24,26 @@ public string SizeUnit { get; set; } = "px"; [Parameter] - public AuthenticatedHomeserverGeneric? Homeserver { get; set; } + public required AuthenticatedHomeserverGeneric Homeserver { get; set; } private string StyleString => $"{(Circular ? "border-radius: 50%;" : "")} width: {Size}{SizeUnit}; height: {Size}{SizeUnit}; object-fit: cover;"; private static readonly string Prefix = "mxc://"; private static readonly int PrefixLength = Prefix.Length; - private async Task UriHasChanged(string value) { - if (!value.StartsWith(Prefix)) { - // Console.WriteLine($"UriHasChanged: {value} does not start with {Prefix}, passing as resolved URI!!!"); - // ResolvedUri = value; - return; - } - - if (Homeserver is null) { - Console.WriteLine("Homeserver is required for MxcAvatar"); - return; - } - - var uri = value[PrefixLength..].Split('/'); - // Console.WriteLine($"UriHasChanged: {value} {uri[0]}"); - var url = $"/_matrix/media/v3/download/{uri[0]}/{uri[1]}"; - Console.WriteLine($"ResolvedUri: {url}"); - _stream = await Homeserver.ClientHttpClient.GetStreamAsync(url); - StateHasChanged(); - } + // private async Task UriHasChanged(string? value) { + // if (string.IsNullOrWhiteSpace(value) || !value.StartsWith(Prefix)) { + // Console.WriteLine($"[MxcAvatar] UriHasChanged: {value} does not start with {Prefix}!"); + // return; + // } + // + // if (Homeserver is null) { + // Console.WriteLine($"[MxcAvatar] Homeserver is required for MxcAvatar! URI: {MxcUri}, Homeserver: {Homeserver?.ToString() ?? "null"}"); + // return; + // } + // + // Console.WriteLine($"[MxcAvatar] Homeserver: {Homeserver}"); + // StateHasChanged(); + // } } \ No newline at end of file diff --git a/MatrixUtils.Web/Shared/MxcImage.razor b/MatrixUtils.Web/Shared/MxcImage.razor
index e7cb2e0..26609ee 100644 --- a/MatrixUtils.Web/Shared/MxcImage.razor +++ b/MatrixUtils.Web/Shared/MxcImage.razor
@@ -1,69 +1,69 @@ -<img src="@ResolvedUri" style="@StyleString"/> -@code { - private string _mxcUri; - private string _style; - private string _resolvedUri; +<AuthorizedImage src="@ResolvedUrl" AccessToken="@Homeserver?.AccessToken" style="@StyleString"/> +@code { [Parameter] - public string MxcUri { - get => _mxcUri ?? ""; + public string? Uri { + get; set { - Console.WriteLine($"New MXC uri: {value}"); - _mxcUri = value; + // Console.WriteLine($"New MXC uri: {value}"); + if (field == value) return; + field = value; UriHasChanged(value); } } + [Parameter] public bool Circular { get; set; } - + [Parameter] public int? Width { get; set; } - + [Parameter] public int? Height { get; set; } - + [Parameter] - public string Style { - get => _style; + public string? Style { + get; set { - _style = value; + field = value; StateHasChanged(); } } - - [CascadingParameter, Parameter] - public RemoteHomeserver? Homeserver { get; set; } - private string ResolvedUri { - get => _resolvedUri; + [Parameter] + public required AuthenticatedHomeserverGeneric Homeserver { get; set; } + + private string? ResolvedUrl { + get; set { - _resolvedUri = value; + field = value; StateHasChanged(); } } private string StyleString => $"{Style} {(Circular ? "border-radius: 50%;" : "")} {(Width.HasValue ? $"width: {Width}px;" : "")} {(Height.HasValue ? $"height: {Height}px;" : "")} object-fit: cover;"; - - private static readonly string Prefix = "mxc://"; - private static readonly int PrefixLength = Prefix.Length; - private async Task UriHasChanged(string value) { - // if (!value.StartsWith(Prefix)) { - // Console.WriteLine($"UriHasChanged: {value} does not start with {Prefix}, passing as resolved URI!!!"); - // ResolvedUri = value; - // return; - // } - // var uri = value[PrefixLength..].Split('/'); - // Console.WriteLine($"UriHasChanged: {value} {uri[0]}"); - // if (Homeserver is null) { - // Console.WriteLine($"Homeserver is null, creating new remotehomeserver for {uri[0]}"); - // Homeserver = await hsProvider.GetRemoteHomeserver(uri[0]); - // } - // ResolvedUri = Homeserver.ResolveMediaUri(value); - // Console.WriteLine($"ResolvedUri: {ResolvedUri}"); - } + // private static readonly string Prefix = "mxc://"; + // private static readonly int PrefixLength = Prefix.Length; + + private async Task UriHasChanged(string? value) { + try { + if (string.IsNullOrWhiteSpace(value)) { + ResolvedUrl = null; + return; + } + + if (Homeserver is null) { + Console.WriteLine($"Homeserver is required for MxcImage! Uri: {value}, Homeserver: {Homeserver?.ToString() ?? "null"}"); + return; + } - // [Parameter] - // public string Class { get; set; } + ResolvedUrl = await Homeserver.GetMediaUrlAsync(value); + // Console.WriteLine($"[MxcImage] Resolved URL: {ResolvedUrl}"); + StateHasChanged(); + } catch (Exception e) { + await Console.Error.WriteLineAsync($"Error resolving media URL: {e}"); + } + } } \ No newline at end of file diff --git a/MatrixUtils.Web/Shared/RoomList.razor b/MatrixUtils.Web/Shared/RoomList.razor
index 42c5a9f..ba9cd69 100644 --- a/MatrixUtils.Web/Shared/RoomList.razor +++ b/MatrixUtils.Web/Shared/RoomList.razor
@@ -10,7 +10,7 @@ } else { @foreach (var category in RoomsWithTypes.OrderBy(x => x.Value.Count)) { - <RoomListCategory Category="@category" GlobalProfile="@GlobalProfile"></RoomListCategory> + <RoomListCategory Category="@category" GlobalProfile="@GlobalProfile" Homeserver="@Homeserver"></RoomListCategory> } } @@ -35,6 +35,9 @@ else { } [Parameter] + public AuthenticatedHomeserverGeneric? Homeserver { get; set; } + + [Parameter] public UserProfileResponse? GlobalProfile { get; set; } [Parameter] diff --git a/MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor b/MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
index 555b1f1..1ab0a1a 100644 --- a/MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor +++ b/MatrixUtils.Web/Shared/RoomListComponents/RoomListCategory.razor
@@ -6,7 +6,7 @@ <summary>@RoomType (@Rooms.Count)</summary> @foreach (var room in Rooms) { <div class="room-list-item"> - <RoomListItem RoomInfo="@room" ShowOwnProfile="@(RoomType == "Room")"></RoomListItem> + <RoomListItem RoomInfo="@room" ShowOwnProfile="@(RoomType == "Room")" Homeserver="@Homeserver"/> @* @if (RoomVersionDangerLevel(room) != 0 && *@ @* (room.StateEvents.FirstOrDefault(x=>x.Type == "m.room.power_levels")?.TypedContent is RoomPowerLevelEventContent powerLevels && powerLevels.UserHasPermission(Homeserver.UserId, "m.room.tombstone"))) { *@ @* <MatrixUtils.Web.Shared.SimpleComponents.LinkButton Color="@(RoomVersionDangerLevel(room) == 2 ? "#ff0000" : "#ff8800")" href="@($"/Rooms/Create?Import={room.Room.RoomId}")">Upgrade room</MatrixUtils.Web.Shared.SimpleComponents.LinkButton> *@ @@ -14,10 +14,11 @@ <LinkButton href="@($"/Rooms/{room.Room.RoomId}/Timeline")">View timeline</LinkButton> <LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/View")">View state</LinkButton> <LinkButton href="@($"/Rooms/{room.Room.RoomId}/State/Edit")">Edit state</LinkButton> + <LinkButton href="@($"/Rooms/{room.Room.RoomId}/Upgrade")" Color="#888800">Upgrade/replace room</LinkButton> <LinkButton href="@($"/Tools/LeaveRoom?roomId={room.Room.RoomId}")" Color="#FF0000">Leave room</LinkButton> @if (room.CreationEventContent?.Type == "m.space") { - <RoomListSpace Space="@room"></RoomListSpace> + <RoomListSpace Space="@room" Homeserver="@Homeserver"/> } else if (room.CreationEventContent?.Type == "support.feline.policy.lists.msc.v1" || RoomType == "org.matrix.mjolnir.policy") { <LinkButton href="@($"/Rooms/{room.Room.RoomId}/Policies")">Manage policies</LinkButton> @@ -35,9 +36,9 @@ [Parameter] public UserProfileResponse? GlobalProfile { get; set; } - [CascadingParameter] - public AuthenticatedHomeserverGeneric Homeserver { get; set; } = null!; - + [Parameter] + public AuthenticatedHomeserverGeneric? Homeserver { get; set; } + private string RoomType => Category.Key; private List<RoomInfo> Rooms => Category.Value; diff --git a/MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor b/MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor
index 11f9040..27f0499 100644 --- a/MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor +++ b/MatrixUtils.Web/Shared/RoomListComponents/RoomListSpace.razor
@@ -35,15 +35,18 @@ set => _breadcrumbs = value; } + [Parameter] + public required AuthenticatedHomeserverGeneric Homeserver { get; set; } + private ObservableCollection<RoomInfo> Children { get; set; } = new(); private Collection<RoomInfo> Unjoined { get; set; } = new(); protected override async Task OnInitializedAsync() { if (Breadcrumbs == null) throw new ArgumentNullException(nameof(Breadcrumbs)); + if (Homeserver is null) throw new ArgumentNullException(nameof(Homeserver)); await Task.Delay(Random.Shared.Next(1000, 10000)); var rooms = Space.Room.AsSpace.GetChildrenAsync(); - var hs = await RmuStorage.GetCurrentSessionOrNavigate(); - var joinedRooms = await hs.GetJoinedRooms(); + var joinedRooms = await Homeserver.GetJoinedRooms(); await foreach (var room in rooms) { if (Breadcrumbs.Contains(room.RoomId)) continue; var roomInfo = KnownRooms.FirstOrDefault(x => x.Room.RoomId == room.RoomId); @@ -51,10 +54,12 @@ roomInfo = new RoomInfo(room); KnownRooms.Add(roomInfo); } - if(joinedRooms.Any(x=>x.RoomId == room.RoomId)) + + if (joinedRooms.Any(x => x.RoomId == room.RoomId)) Children.Add(roomInfo); else Unjoined.Add(roomInfo); } + await base.OnInitializedAsync(); } diff --git a/MatrixUtils.Web/Shared/RoomListItem.razor b/MatrixUtils.Web/Shared/RoomListItem.razor
index d75d159..46daaa2 100644 --- a/MatrixUtils.Web/Shared/RoomListItem.razor +++ b/MatrixUtils.Web/Shared/RoomListItem.razor
@@ -1,3 +1,4 @@ +@using ArcaneLibs @using LibMatrix @using LibMatrix.EventTypes.Spec.State.RoomInfo @using LibMatrix.Responses @@ -6,16 +7,20 @@ @if (RoomInfo is not null) { <div class="roomListItem @(HasDangerousRoomVersion ? "dangerousRoomVersion" : HasOldRoomVersion ? "oldRoomVersion" : "")" id="@RoomInfo.Room.RoomId"> @if (OwnMemberState != null) { - @* Class="@("avatar32" + (OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? " highlightChange" : "") + (ChildContent is not null ? " vcenter" : ""))" *@ - @* <MxcImage Homeserver="hs" Circular="true" Height="32" Width="32" MxcUri="@(OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl)"/> *@ - <MxcAvatar Homeserver="Homeserver" Circular="true" Size="32" MxcUri="@(OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl)"/> + <MxcAvatar Homeserver="@Homeserver" Circular="true" Size="32" MxcUri="@(OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl)"/> <span class="centerVertical border75 @(OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? "highlightChange" : "")"> @(OwnMemberState?.DisplayName ?? GlobalProfile?.DisplayName ?? "Loading...") </span> <span class="centerVertical noLeftPadding">-></span> } @* <MxcImage Circular="true" Height="32" Width="32" MxcUri="@RoomInfo.RoomIcon" Style="@(ChildContent is not null ? "vertical-align: middle;" : "")"/> *@ - <MxcAvatar Homeserver="Homeserver" Circular="true" Size="32" MxcUri="@RoomInfo.RoomIcon"/> + + @if (!string.IsNullOrWhiteSpace(RoomInfo.RoomIcon)) { + <MxcAvatar Homeserver="@Homeserver" Circular="true" Size="32" MxcUri="@RoomInfo.RoomIcon"/> + } + else { + <img src="@Identicon" width="32" height="32" style="border-radius: 50%;"/> + } <div class="inlineBlock"> <span class="centerVertical">@RoomInfo.RoomName</span> @if (ChildContent is not null) { @@ -68,6 +73,10 @@ else { private bool HasOldRoomVersion { get; set; } = false; private bool HasDangerousRoomVersion { get; set; } = false; + private string Identicon { get; set; } + + private static SvgIdenticonGenerator _identiconGenerator = new SvgIdenticonGenerator(); + private static SemaphoreSlim _semaphoreSlim = new(8); private RoomInfo? _roomInfo; private bool _loadData = false; @@ -75,6 +84,9 @@ else { private bool _hooked; private async Task RoomInfoChanged() { + if (RoomInfo is null) return; + Identicon = _identiconGenerator.GenerateAsDataUri(RoomInfo.Room.RoomId); + RoomInfo.PropertyChanged += async (_, a) => { if (a.PropertyName == nameof(RoomInfo.CreationEventContent)) { await CheckRoomVersion(); diff --git a/MatrixUtils.Web/Shared/UserListItem.razor b/MatrixUtils.Web/Shared/UserListItem.razor
index cf7f24d..8ce2868 100644 --- a/MatrixUtils.Web/Shared/UserListItem.razor +++ b/MatrixUtils.Web/Shared/UserListItem.razor
@@ -23,13 +23,14 @@ [Parameter] public string UserId { get; set; } - private AuthenticatedHomeserverGeneric _homeserver = null!; + [Parameter] + public AuthenticatedHomeserverGeneric _homeserver { get; set; } private SvgIdenticonGenerator _identiconGenerator = new(); protected override async Task OnInitializedAsync() { - _homeserver = await RmuStorage.GetCurrentSessionOrNavigate(); - if (_homeserver is null) return; + // _homeserver = await RmuStorage.GetCurrentSessionOrNavigate(); + // if (_homeserver is null) return; if (User == null) { if (UserId == null) {