From c9d856d931d629eb168e25734d86e53c3d87b295 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Wed, 18 Oct 2023 06:11:13 +0200 Subject: Add user management page --- MatrixRoomUtils.Web/Pages/User/Manage.razor | 90 +++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 10 deletions(-) (limited to 'MatrixRoomUtils.Web/Pages') diff --git a/MatrixRoomUtils.Web/Pages/User/Manage.razor b/MatrixRoomUtils.Web/Pages/User/Manage.razor index 281cbfc..25debf7 100644 --- a/MatrixRoomUtils.Web/Pages/User/Manage.razor +++ b/MatrixRoomUtils.Web/Pages/User/Manage.razor @@ -9,7 +9,7 @@

Profile


- +
Display name:
Avatar URL: @@ -17,39 +17,109 @@ Update profile Update profile (restore room overrides)
- @if (Busy) { -
Busy processing profile update, please do not leave this page...
+ @if (!string.IsNullOrWhiteSpace(Status)) { +

@Status

} + +
+ Room profiles
+ + @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) + +
+ Display name:
+ Avatar URL: +
+ Update profile +
+
+ @if (!string.IsNullOrWhiteSpace(Status)) { +

@Status

+ } +
+
+ } +
} @code { + private string? _status = null; private AuthenticatedHomeserverGeneric? HomeServer { get; set; } private ProfileResponseEventContent? Profile { get; set; } - private bool Busy { get; set; } = false; + private ProfileResponseEventContent? OldProfile { get; set; } + + private string? Status { + get => _status; + set { _status = value; StateHasChanged(); } + } + + private Dictionary RoomProfiles { get; set; } = new(); + private Dictionary RoomNames { get; set; } = new(); protected override async Task OnInitializedAsync() { HomeServer = await MRUStorage.GetCurrentSessionOrNavigate(); if (HomeServer is null) return; - if (HomeServer.WhoAmI?.UserId is not null) - Profile = (await HomeServer.GetProfileAsync(HomeServer.WhoAmI.UserId)).DeepClone(); + Status = "Loading global profile..."; + if (HomeServer.WhoAmI?.UserId is null) return; + Profile = (await HomeServer.GetProfileAsync(HomeServer.WhoAmI.UserId)).DeepClone(); + OldProfile = (await HomeServer.GetProfileAsync(HomeServer.WhoAmI.UserId)).DeepClone(); + Status = "Loading room profiles..."; + var roomProfiles = HomeServer.GetRoomProfilesAsync(); + await foreach (var (roomId, roomProfile) in roomProfiles) { + // Status = $"Got profile for {roomId}..."; + RoomProfiles[roomId] = roomProfile.DeepClone(); + } + StateHasChanged(); + Status = "Room profiles loaded, loading room names..."; + + var roomNameTasks = RoomProfiles.Keys.Select(x => HomeServer.GetRoom(x)).Select(async x => { + var name = await x.GetNameAsync(); + return new KeyValuePair(x.RoomId, name); + }).ToAsyncEnumerable(); + await foreach (var (roomId, roomName) in roomNameTasks) { + // Status = $"Got room name for {roomId}: {roomName}"; + RoomNames[roomId] = roomName; + } + + StateHasChanged(); + Status = null; await base.OnInitializedAsync(); } private async Task AvatarChanged(InputFileChangeEventArgs arg) { - var res = await HomeServer.UploadFile(arg.File.Name, arg.File.OpenReadStream(), arg.File.ContentType); + var res = await HomeServer.UploadFile(arg.File.Name, arg.File.OpenReadStream(Int64.MaxValue), arg.File.ContentType); Console.WriteLine(res); Profile.AvatarUrl = res; StateHasChanged(); } private async Task UpdateProfile(bool restoreRoomProfiles = false) { - Busy = true; + Status = "Busy processing global profile update, please do not leave this page..."; StateHasChanged(); await HomeServer.UpdateProfileAsync(Profile, restoreRoomProfiles); - Busy = false; + Status = null; StateHasChanged(); + await OnInitializedAsync(); } + private async Task RoomAvatarChanged(InputFileChangeEventArgs arg, string roomId) { + var res = await HomeServer.UploadFile(arg.File.Name, arg.File.OpenReadStream(Int64.MaxValue), arg.File.ContentType); + Console.WriteLine(res); + RoomProfiles[roomId].AvatarUrl = res; + StateHasChanged(); + } + + private async Task UpdateRoomProfile(string roomId) { + Status = "Busy processing room profile update, please do not leave this page..."; + StateHasChanged(); + var room = HomeServer.GetRoom(roomId); + await room.SendStateEventAsync("m.room.member", HomeServer.WhoAmI.UserId, RoomProfiles[roomId]); + Status = null; + StateHasChanged(); + } + +} -} \ No newline at end of file -- cgit 1.5.1