diff --git a/MatrixUtils.Web/Pages/User/DMManager.razor b/MatrixUtils.Web/Pages/User/DMManager.razor
index 80bf3b2..4b8b7c2 100644
--- a/MatrixUtils.Web/Pages/User/DMManager.razor
+++ b/MatrixUtils.Web/Pages/User/DMManager.razor
@@ -1,8 +1,8 @@
@page "/User/DirectMessages"
-@using LibMatrix.EventTypes.Spec.State
@using LibMatrix.Responses
@using MatrixUtils.Abstractions
@using LibMatrix
+@using LibMatrix.EventTypes.Spec.State.RoomInfo
<h3>Direct Messages</h3>
<hr/>
@@ -29,7 +29,7 @@
}
protected override async Task OnInitializedAsync() {
- Homeserver = await RMUStorage.GetCurrentSessionOrNavigate();
+ Homeserver = await sessionStore.GetCurrentHomeserver(navigateOnFailure: true);
if (Homeserver is null) return;
Status = "Loading global profile...";
if (Homeserver.WhoAmI?.UserId is null) return;
diff --git a/MatrixUtils.Web/Pages/User/Profile.razor b/MatrixUtils.Web/Pages/User/Profile.razor
index 49af22f..ccd3e7b 100644
--- a/MatrixUtils.Web/Pages/User/Profile.razor
+++ b/MatrixUtils.Web/Pages/User/Profile.razor
@@ -1,10 +1,8 @@
@page "/User/Profile"
-@using LibMatrix.EventTypes.Spec.State
-@using ArcaneLibs.Extensions
@using LibMatrix
+@using LibMatrix.EventTypes.Spec.State.RoomInfo
@using LibMatrix.Responses
@using MatrixUtils.Abstractions
-@using Microsoft.AspNetCore.Components.Forms
<h3>Manage Profile - @Homeserver?.WhoAmI?.UserId</h3>
<hr/>
@@ -12,7 +10,7 @@
<h4>Profile</h4>
<hr/>
<div>
- <img src="@Homeserver.ResolveMediaUri(NewProfile.AvatarUrl)" style="width: 96px; height: 96px; border-radius: 50%; object-fit: cover;"/>
+ <MxcAvatar Homeserver="@Homeserver" MxcUri="@NewProfile.AvatarUrl" Circular="true" Size="96"/>
<div style="display: inline-block; vertical-align: middle;">
<span>Display name: </span><FancyTextBox @bind-Value="@NewProfile.DisplayName"></FancyTextBox><br/>
<span>Avatar URL: </span><FancyTextBox @bind-Value="@NewProfile.AvatarUrl"></FancyTextBox>
@@ -35,12 +33,13 @@
<summary style="@(room.OwnMembership?.DisplayName == OldProfile.DisplayName && room.OwnMembership?.AvatarUrl == OldProfile.AvatarUrl ? "" : "#ffff0033")">
<div style="display: inline-block; width: calc(100% - 50px); vertical-align: middle; margin-top: -8px; margin-bottom: -8px;">
<CascadingValue Value="OldProfile">
- <RoomListItem ShowOwnProfile="true" RoomInfo="@room" OwnMemberState="@room.OwnMembership"></RoomListItem>
+ <RoomListItem Homeserver="Homeserver" ShowOwnProfile="true" RoomInfo="@room" OwnMemberState="@room.OwnMembership"></RoomListItem>
</CascadingValue>
</div>
</summary>
@if (room.OwnMembership is not null) {
- <img src="@Homeserver.ResolveMediaUri(room.OwnMembership.AvatarUrl)" style="width: 96px; height: 96px; border-radius: 50%; object-fit: cover;"/>
+ @* <img src="@Homeserver.ResolveMediaUri(room.OwnMembership.AvatarUrl)" style="width: 96px; height: 96px; border-radius: 50%; object-fit: cover;"/> *@
+ <MxcAvatar Homeserver="@Homeserver" MxcUri="@room.OwnMembership.AvatarUrl" Circular="true" Size="96"/>
<div style="display: inline-block; vertical-align: middle;">
<span>Display name: </span><FancyTextBox BackgroundColor="@(room.OwnMembership.DisplayName == OldProfile.DisplayName ? "" : "#ffff0033")" @bind-Value="@room.OwnMembership.DisplayName"></FancyTextBox><br/>
<span>Avatar URL: </span><FancyTextBox BackgroundColor="@(room.OwnMembership.AvatarUrl == OldProfile.AvatarUrl ? "" : "#ffff0033")" @bind-Value="@room.OwnMembership.AvatarUrl"></FancyTextBox>
@@ -58,29 +57,11 @@
</details>
<br/>
}
-
- @foreach (var (roomId, roomProfile) in RoomProfiles.OrderBy(x => RoomNames.TryGetValue(x.Key, out var _name) ? _name : x.Key)) {
- <details class="details-compact">
- <summary style="@(roomProfile.DisplayName == OldProfile.DisplayName && roomProfile.AvatarUrl == OldProfile.AvatarUrl ? "" : "#ffff0033")">@(RoomNames.TryGetValue(roomId, out var name) ? name : roomId)</summary>
- <img src="@Homeserver.ResolveMediaUri(roomProfile.AvatarUrl)" style="width: 96px; height: 96px; border-radius: 50%; object-fit: cover;"/>
- <div style="display: inline-block; vertical-align: middle;">
- <span>Display name: </span><FancyTextBox BackgroundColor="@(roomProfile.DisplayName == OldProfile.DisplayName ? "" : "#ffff0033")" @bind-Value="@roomProfile.DisplayName"></FancyTextBox><br/>
- <span>Avatar URL: </span><FancyTextBox BackgroundColor="@(roomProfile.AvatarUrl == OldProfile.AvatarUrl ? "" : "#ffff0033")" @bind-Value="@roomProfile.AvatarUrl"></FancyTextBox>
- <InputFile OnChange="@(ifcea => RoomAvatarChanged(ifcea, roomId))"></InputFile><br/>
- <LinkButton OnClick="@(() => UpdateRoomProfile(roomId))">Update profile</LinkButton>
- </div>
- <br/>
- @if (!string.IsNullOrWhiteSpace(Status)) {
- <p>@Status</p>
- }
- </details>
- <br/>
- }
// </details>
}
@code {
- private string? _status = null;
+ private string? _status;
private AuthenticatedHomeserverGeneric? Homeserver { get; set; }
private UserProfileResponse? NewProfile { get; set; }
@@ -99,7 +80,7 @@
private Dictionary<string, string> RoomNames { get; set; } = new();
protected override async Task OnInitializedAsync() {
- Homeserver = await RMUStorage.GetCurrentSessionOrNavigate();
+ Homeserver = await sessionStore.GetCurrentHomeserver(navigateOnFailure: true);
if (Homeserver is null) return;
Status = "Loading global profile...";
if (Homeserver.WhoAmI?.UserId is null) return;
@@ -107,44 +88,50 @@
OldProfile = (await Homeserver.GetProfileAsync(Homeserver.WhoAmI.UserId)); //.DeepClone();
Status = "Loading room profiles...";
var roomProfiles = Homeserver.GetRoomProfilesAsync();
+ List<Task> roomInfoTasks = [];
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) {
- OwnMembership = roomProfile
- };
- try {
- roomInfo.RoomIcon = (await roomIconTask).Url;
- }
- catch (MatrixException e) {
- if (e is not { ErrorCode: "M_NOT_FOUND" }) throw;
- }
+ var task = Task.Run(async () => {
+ var room = Homeserver.GetRoom(roomId);
+ var roomNameTask = room.GetNameOrFallbackAsync();
+ var roomIconTask = room.GetAvatarUrlAsync();
+ var roomInfo = new RoomInfo(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;
- }
+ try {
+ RoomNames[roomId] = 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();
+ Rooms.Add(roomInfo);
+ // Status = $"Got profile for {roomId}...";
+ RoomProfiles[roomId] = roomProfile; //.DeepClone();
+ });
+ roomInfoTasks.Add(task);
}
+
+ await Task.WhenAll(roomInfoTasks);
StateHasChanged();
Status = "Room profiles loaded, loading room names...";
- var roomNameTasks = RoomProfiles.Keys.Select(x => Homeserver.GetRoom(x)).Select(async x => {
- var name = await x.GetNameOrFallbackAsync();
- return new KeyValuePair<string, string?>(x.RoomId, name);
- }).ToAsyncEnumerable();
+ // var roomNameTasks = RoomProfiles.Keys.Select(x => Homeserver.GetRoom(x)).Select(async x => {
+ // var name = await x.GetNameOrFallbackAsync();
+ // return new KeyValuePair<string, string?>(x.RoomId, name);
+ // }).ToAsyncEnumerable();
- await foreach (var (roomId, roomName) in roomNameTasks) {
- // Status = $"Got room name for {roomId}: {roomName}";
- RoomNames[roomId] = roomName;
- }
+ // await foreach (var (roomId, roomName) in roomNameTasks) {
+ // Status = $"Got room name for {roomId}: {roomName}";
+ // RoomNames[roomId] = roomName;
+ // }
StateHasChanged();
Status = null;
|