diff options
Diffstat (limited to 'MatrixRoomUtils.Web')
-rw-r--r-- | MatrixRoomUtils.Web/Pages/User/Manage.razor | 90 | ||||
-rw-r--r-- | MatrixRoomUtils.Web/wwwroot/css/app.css | 8 |
2 files changed, 88 insertions, 10 deletions
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 @@ <h4>Profile</h4> <hr/> - <img src="@HomeServer.ResolveMediaUri(Profile.AvatarUrl)" style="width: 128px; height: 128px; border-radius: 50%;"/> + <img src="@HomeServer.ResolveMediaUri(Profile.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 @bind-Value="@Profile.DisplayName"></FancyTextBox><br/> <span>Avatar URL: </span><FancyTextBox @bind-Value="@Profile.AvatarUrl"></FancyTextBox> @@ -17,39 +17,109 @@ <LinkButton OnClick="@(() => UpdateProfile())">Update profile</LinkButton> <LinkButton OnClick="@(() => UpdateProfile(true))">Update profile (restore room overrides)</LinkButton> </div> - @if (Busy) { - <div>Busy processing profile update, please do not leave this page...</div> + @if (!string.IsNullOrWhiteSpace(Status)) { + <p>@Status</p> } + + <details> + <summary style="font-size: 1.5rem;">Room profiles<hr></summary> + + @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 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<string, RoomMemberEventContent> RoomProfiles { get; set; } = new(); + private Dictionary<string, string> 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<string, string>(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; } |