From 83e6d98d2d7586fb518ed1b2097c59ea9b8af223 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 31 Jan 2024 12:10:03 +0100 Subject: New tools, fix room list items --- MatrixUtils.Web/Pages/User/Profile.razor | 56 +++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'MatrixUtils.Web/Pages/User') diff --git a/MatrixUtils.Web/Pages/User/Profile.razor b/MatrixUtils.Web/Pages/User/Profile.razor index 8cffaab..deebdaf 100644 --- a/MatrixUtils.Web/Pages/User/Profile.razor +++ b/MatrixUtils.Web/Pages/User/Profile.razor @@ -2,7 +2,9 @@ @using LibMatrix.Homeservers @using LibMatrix.EventTypes.Spec.State @using ArcaneLibs.Extensions +@using LibMatrix @using LibMatrix.Responses +@using MatrixUtils.Abstractions

Manage Profile - @Homeserver?.WhoAmI?.UserId


@@ -28,6 +30,35 @@ @*
*@

Room profiles

+ @foreach (var room in Rooms) { +
+ +
+ + + +
+
+ @if (room.OwnMembership is not null) { + +
+ Display name:
+ Avatar URL: +
+ Update profile +
+
+ @if (!string.IsNullOrWhiteSpace(Status)) { +

@Status

+ } + } + else { +

Something went wrong, own membership is missing...

+ } +
+
+ } + @foreach (var (roomId, roomProfile) in RoomProfiles.OrderBy(x => RoomNames.TryGetValue(x.Key, out var _name) ? _name : x.Key)) {
@(RoomNames.TryGetValue(roomId, out var name) ? name : roomId) @@ -63,6 +94,7 @@ } } + private List Rooms { get; set; } = new(); private Dictionary RoomProfiles { get; set; } = new(); private Dictionary RoomNames { get; set; } = new(); @@ -76,6 +108,28 @@ Status = "Loading room profiles..."; var roomProfiles = Homeserver.GetRoomProfilesAsync(); await foreach (var (roomId, roomProfile) in roomProfiles) { + var room = Homeserver.GetRoom(roomId); + var roomNameTask = room.GetNameOrFallbackAsync(); + var roomIconTask = room.GetAvatarUrlAsync(); + var roomInfo = new RoomInfo() { + Room = room, + OwnMembership = roomProfile + }; + try { + roomInfo.RoomIcon = (await roomIconTask).Url; + } + catch (MatrixException e) { + if (e is not { ErrorCode: "M_NOT_FOUND" }) throw; + } + + try { + roomInfo.RoomName = await roomNameTask; + } + catch (MatrixException e) { + if (e is not { ErrorCode: "M_NOT_FOUND" }) throw; + } + + Rooms.Add(roomInfo); // Status = $"Got profile for {roomId}..."; RoomProfiles[roomId] = roomProfile; //.DeepClone(); } @@ -87,7 +141,7 @@ var name = await x.GetNameOrFallbackAsync(); return new KeyValuePair(x.RoomId, name); }).ToAsyncEnumerable(); - + await foreach (var (roomId, roomName) in roomNameTasks) { // Status = $"Got room name for {roomId}: {roomName}"; RoomNames[roomId] = roomName; -- cgit 1.5.1