about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared/RoomListItem.razor
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-11-09 07:38:33 +0100
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-11-09 07:38:33 +0100
commitc37bcb0e4a878d4f4c0e47988adb8624131c82cd (patch)
tree706f5300ce83b511d807decddd5b3521168b5fc7 /MatrixRoomUtils.Web/Shared/RoomListItem.razor
parentFix updates (diff)
downloadMatrixUtils-c37bcb0e4a878d4f4c0e47988adb8624131c82cd.tar.xz
event types
Diffstat (limited to 'MatrixRoomUtils.Web/Shared/RoomListItem.razor')
-rw-r--r--MatrixRoomUtils.Web/Shared/RoomListItem.razor83
1 files changed, 49 insertions, 34 deletions
diff --git a/MatrixRoomUtils.Web/Shared/RoomListItem.razor b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
index a24ccad..970526d 100644
--- a/MatrixRoomUtils.Web/Shared/RoomListItem.razor
+++ b/MatrixRoomUtils.Web/Shared/RoomListItem.razor
@@ -9,14 +9,14 @@
 @if (RoomInfo is not null) {
     <div class="roomListItem @(HasDangerousRoomVersion ? "dangerousRoomVersion" : HasOldRoomVersion ? "oldRoomVersion" : "")" id="@RoomInfo.Room.RoomId">
         @if (OwnMemberState != null) {
-            <img class="avatar32 @(OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? "highlightChange" : "") @(ChildContent is not null ? "vcenter" : "")"
-                 src="@(hs.ResolveMediaUri(OwnMemberState.AvatarUrl ?? GlobalProfile.AvatarUrl) ?? "/icon-192.png")"/>
+            <MxcImage Class="@("avatar32" + (OwnMemberState?.AvatarUrl != GlobalProfile?.AvatarUrl ? " highlightChange" : "") + (ChildContent is not null ? " vcenter" : ""))"
+                      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>
         }
-        <img class="avatar32" src="@hs?.ResolveMediaUri(RoomInfo.RoomIcon)" style="@(ChildContent is not null ? "vertical-align: middle;" : "")"/>
+        <MxcImage Class="avatar32" MxcUri="RoomInfo.RoomIcon" Style="@(ChildContent is not null ? "vertical-align: middle;" : "")"/>
         <div class="inlineBlock">
             <span class="centerVertical">@RoomInfo.RoomName</span>
             @if (ChildContent is not null) {
@@ -36,7 +36,13 @@ else {
     public RenderFragment? ChildContent { get; set; }
 
     [Parameter]
-    public RoomInfo? RoomInfo { get; set; }
+    public RoomInfo? RoomInfo {
+        get => _roomInfo;
+        set {
+            _roomInfo = value;
+            OnParametersSetAsync();
+        }
+    }
 
     [Parameter]
     public bool ShowOwnProfile { get; set; } = false;
@@ -48,42 +54,52 @@ else {
     public UserProfileResponse? GlobalProfile { get; set; }
 
     [Parameter]
-    public bool LoadData { get; set; } = false;
+    public bool LoadData {
+        get => _loadData;
+        set {
+            _loadData = value;
+            OnParametersSetAsync();
+        }
+    }
 
     private bool HasOldRoomVersion { get; set; } = false;
     private bool HasDangerousRoomVersion { get; set; } = false;
 
     private static SemaphoreSlim _semaphoreSlim = new(8);
+    private RoomInfo? _roomInfo;
+    private bool _loadData = false;
     private static AuthenticatedHomeserverGeneric? hs { get; set; }
 
     protected override async Task OnParametersSetAsync() {
-        RoomInfo.PropertyChanged += (_, a) => {
-            Console.WriteLine(a.PropertyName);
-            StateHasChanged();
-        };
-
-        if (LoadData) {
-            try {
-                await RoomInfo.GetStateEvent("m.room.create");
-                if (ShowOwnProfile)
-                    OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.WhoAmI.UserId)).TypedContent as RoomMemberEventContent;
-
-                await RoomInfo.GetStateEvent("m.room.name");
-                await RoomInfo.GetStateEvent("m.room.avatar");
-            }
-            catch (MatrixException e) {
-                if (e.ErrorCode == "M_FORBIDDEN") {
-                    LoadData = false;
-                    RoomInfo.StateEvents.Add(new() {
-                        Type = "m.room.create",
-                        TypedContent = new RoomCreateEventContent() { RoomVersion = "0" }
-                    });
-                    RoomInfo.StateEvents.Add(new() {
-                        Type = "m.room.name",
-                        TypedContent = new RoomNameEventContent() {
-                            Name = "M_FORBIDDEN: Are you a member of this room? " + RoomInfo.Room.RoomId
-                        }
-                    });
+        if (RoomInfo != null) {
+            RoomInfo.PropertyChanged += (_, a) => {
+                Console.WriteLine(a.PropertyName);
+                StateHasChanged();
+            };
+
+            if (LoadData) {
+                try {
+                    await RoomInfo.GetStateEvent("m.room.create");
+                    if (ShowOwnProfile)
+                        OwnMemberState ??= (await RoomInfo.GetStateEvent("m.room.member", hs.WhoAmI.UserId)).TypedContent as RoomMemberEventContent;
+
+                    await RoomInfo.GetStateEvent("m.room.name");
+                    await RoomInfo.GetStateEvent("m.room.avatar");
+                }
+                catch (MatrixException e) {
+                    if (e.ErrorCode == "M_FORBIDDEN") {
+                        LoadData = false;
+                        RoomInfo.StateEvents.Add(new() {
+                            Type = "m.room.create",
+                            TypedContent = new RoomCreateEventContent() { RoomVersion = "0" }
+                        });
+                        RoomInfo.StateEvents.Add(new() {
+                            Type = "m.room.name",
+                            TypedContent = new RoomNameEventContent() {
+                                Name = "M_FORBIDDEN: Are you a member of this room? " + RoomInfo.Room.RoomId
+                            }
+                        });
+                    }
                 }
             }
         }
@@ -170,5 +186,4 @@ else {
     //     }
     // }
 
-}
-
+}
\ No newline at end of file