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 --- ArcaneLibs | 2 +- LibMatrix | 2 +- MatrixRoomUtils.Web/Pages/User/Manage.razor | 90 +++++++++++++++++++++++++---- MatrixRoomUtils.Web/wwwroot/css/app.css | 8 +++ 4 files changed, 90 insertions(+), 12 deletions(-) diff --git a/ArcaneLibs b/ArcaneLibs index e4e3635..da722ab 160000 --- a/ArcaneLibs +++ b/ArcaneLibs @@ -1 +1 @@ -Subproject commit e4e36357535e1f44119a2861027a71d3f92f989e +Subproject commit da722ab1751728d485b415332d0427dd491653c7 diff --git a/LibMatrix b/LibMatrix index 6356f2c..90d54c1 160000 --- a/LibMatrix +++ b/LibMatrix @@ -1 +1 @@ -Subproject commit 6356f2c1cedec67dd883986ff101e961118bc745 +Subproject commit 90d54c12a9d1fc06c3e07b4e367021538d08063e 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 diff --git a/MatrixRoomUtils.Web/wwwroot/css/app.css b/MatrixRoomUtils.Web/wwwroot/css/app.css index bcd8f5d..3baddbb 100644 --- a/MatrixRoomUtils.Web/wwwroot/css/app.css +++ b/MatrixRoomUtils.Web/wwwroot/css/app.css @@ -1,6 +1,14 @@ @import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); @import url('jetbrains-mono/jetbrains-mono.css'); +.details-compact > summary { + line-height: 0px; +} + +.details-compact[open] > summary { + margin-bottom: 24px; +} + article > h3:first-child { padding-top: 24px; } -- cgit 1.4.1