1 files changed, 35 insertions, 18 deletions
diff --git a/MatrixUtils.Web/Shared/RoomListItem.razor b/MatrixUtils.Web/Shared/RoomListItem.razor
index bfaa900..2d85f64 100644
--- a/MatrixUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixUtils.Web/Shared/RoomListItem.razor
@@ -1,19 +1,26 @@
+@using ArcaneLibs
@using LibMatrix
-@using LibMatrix.EventTypes.Spec.State
+@using LibMatrix.EventTypes.Spec.State.RoomInfo
@using LibMatrix.Responses
@using MatrixUtils.Abstractions
@using MatrixUtils.Web.Classes.Constants
@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)"/>
<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;" : "")"/>
+ @* <MxcImage Circular="true" Height="32" Width="32" MxcUri="@RoomInfo.RoomIcon" Style="@(ChildContent is not null ? "vertical-align: middle;" : "")"/> *@
+
+ @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) {
@@ -42,8 +49,6 @@ else {
}
}
-
-
[Parameter]
public bool ShowOwnProfile { get; set; } = false;
@@ -61,27 +66,36 @@ else {
OnParametersSetAsync();
}
}
+
+ [Parameter]
+ public AuthenticatedHomeserverGeneric? Homeserver { get; set; }
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;
- private static AuthenticatedHomeserverGeneric? hs { get; set; }
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();
}
-
+
StateHasChanged();
};
}
-
+
// protected override async Task OnParametersSetAsync() {
// if (RoomInfo != null) {
// if (!_hooked) {
@@ -127,21 +141,24 @@ else {
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
- hs ??= await RMUStorage.GetCurrentSessionOrNavigate();
- if (hs is null) return;
+ // hs ??= await sessionStore.GetCurrentHomeserver(navigateOnFailure: true);
+ // if (hs is null) return;
+ if (Homeserver is null) {
+ Console.WriteLine($"RoomListItem called without homeserver");
+ }
await CheckRoomVersion();
}
private async Task LoadOwnProfile() {
if (!ShowOwnProfile) return;
try {
- // OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.UserId)).TypedContent as RoomMemberEventContent;
- GlobalProfile ??= await hs.GetProfileAsync(hs.UserId);
+ // OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.UserId)).TypedContent as RoomMemberEventContent;
+ GlobalProfile ??= await Homeserver.GetProfileAsync(Homeserver.UserId);
}
catch (MatrixException e) {
if (e is { ErrorCode: "M_FORBIDDEN" }) {
- Console.WriteLine($"Failed to get profile for {hs.UserId}: {e.Message}");
+ Console.WriteLine($"Failed to get profile for {Homeserver.UserId}: {e.Message}");
ShowOwnProfile = false;
}
else {
@@ -151,8 +168,8 @@ else {
}
private async Task CheckRoomVersion() {
- if (RoomInfo?.CreationEventContent is null) return;
-
+ if (RoomInfo?.CreationEventContent is null) return;
+
var ce = RoomInfo.CreationEventContent;
if (int.TryParse(ce.RoomVersion, out var rv)) {
if (rv < 10)
@@ -163,7 +180,7 @@ else {
if (RoomConstants.DangerousRoomVersions.Contains(ce.RoomVersion)) {
HasDangerousRoomVersion = true;
- // RoomName = "Dangerous room: " + RoomName;
+ // RoomName = "Dangerous room: " + RoomName;
}
}
|