From 03313562d21d5db9bf6a14ebbeab80e06c883d3a Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 24 Jan 2024 02:31:56 +0100 Subject: MRU->RMU, fixes, cleanup --- MatrixRoomUtils.Web/Pages/User/Profile.razor | 134 --------------------------- 1 file changed, 134 deletions(-) delete mode 100644 MatrixRoomUtils.Web/Pages/User/Profile.razor (limited to 'MatrixRoomUtils.Web/Pages/User/Profile.razor') diff --git a/MatrixRoomUtils.Web/Pages/User/Profile.razor b/MatrixRoomUtils.Web/Pages/User/Profile.razor deleted file mode 100644 index 73d7c6e..0000000 --- a/MatrixRoomUtils.Web/Pages/User/Profile.razor +++ /dev/null @@ -1,134 +0,0 @@ -@page "/User/Profile" -@using LibMatrix.Homeservers -@using LibMatrix.EventTypes.Spec.State -@using ArcaneLibs.Extensions -@using LibMatrix.Responses -

Manage Profile - @Homeserver?.WhoAmI?.UserId

-
- -@if (NewProfile is not null) { -

Profile

-
-
- -
- Display name:
- Avatar URL: -
- Update profile - Update profile (restore room overrides) -
-
- @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 UserProfileResponse? NewProfile { get; set; } - private UserProfileResponse? 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; - Status = "Loading global profile..."; - if (Homeserver.WhoAmI?.UserId is null) return; - NewProfile = (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.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; - } - - StateHasChanged(); - Status = null; - - await base.OnInitializedAsync(); - } - - private async Task AvatarChanged(InputFileChangeEventArgs arg) { - var res = await Homeserver.UploadFile(arg.File.Name, arg.File.OpenReadStream(Int64.MaxValue), arg.File.ContentType); - Console.WriteLine(res); - NewProfile.AvatarUrl = res; - StateHasChanged(); - } - - private async Task UpdateProfile(bool restoreRoomProfiles = false) { - Status = "Busy processing global profile update, please do not leave this page..."; - StateHasChanged(); - await Homeserver.UpdateProfileAsync(NewProfile, restoreRoomProfiles); - 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.4.1