diff options
author | Rory& <root@rory.gay> | 2024-01-24 02:31:56 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-01-24 17:05:25 +0100 |
commit | 03313562d21d5db9bf6a14ebbeab80e06c883d3a (patch) | |
tree | e000546a2ee8e6a886a7ed9fd01ad674178fb7cb /MatrixUtils.Web/Pages/User/DMManager.razor | |
parent | Make RMU installable (diff) | |
download | MatrixUtils-03313562d21d5db9bf6a14ebbeab80e06c883d3a.tar.xz |
MRU->RMU, fixes, cleanup
Diffstat (limited to 'MatrixUtils.Web/Pages/User/DMManager.razor')
-rw-r--r-- | MatrixUtils.Web/Pages/User/DMManager.razor | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Pages/User/DMManager.razor b/MatrixUtils.Web/Pages/User/DMManager.razor new file mode 100644 index 0000000..df5cd6b --- /dev/null +++ b/MatrixUtils.Web/Pages/User/DMManager.razor @@ -0,0 +1,62 @@ +@page "/User/DirectMessages" +@using LibMatrix.EventTypes.Spec.State +@using LibMatrix.Responses +@using MatrixUtils.Abstractions +<h3>Direct Messages</h3> +<hr/> + +@foreach (var (targetUser, rooms) in DMRooms) { + <div> + <InlineUserItem User="targetUser"></InlineUserItem> + @foreach (var room in rooms) { + <RoomListItem RoomInfo="room" LoadData="true"></RoomListItem> + } + </div> +} + +@code { + private string? _status; + private AuthenticatedHomeserverGeneric? Homeserver { get; set; } + private Dictionary<UserProfileResponse, List<RoomInfo>> DMRooms { get; set; } = new(); + + public string? Status { + get => _status; + set { + _status = value; + StateHasChanged(); + } + } + + protected override async Task OnInitializedAsync() { + Homeserver = await RMUStorage.GetCurrentSessionOrNavigate(); + if (Homeserver is null) return; + Status = "Loading global profile..."; + if (Homeserver.WhoAmI?.UserId is null) return; + + Status = "Loading DM list from account data..."; + var dms = await Homeserver.GetAccountDataAsync<Dictionary<string, List<string>>>("m.direct"); + DMRooms.Clear(); + foreach (var (userId, rooms) in dms) { + var roomList = new List<RoomInfo>(); + DMRooms.Add(await Homeserver.GetProfileAsync(userId), roomList); + foreach (var room in rooms) { + var roomInfo = new RoomInfo() { Room = Homeserver.GetRoom(room) }; + roomList.Add(roomInfo); + roomInfo.StateEvents.Add(new() { + Type = RoomNameEventContent.EventId, + TypedContent = new RoomNameEventContent() { + Name = await Homeserver.GetRoom(room).GetNameOrFallbackAsync(4) + }, + RoomId = room, Sender = null, EventId = null + }); + } + StateHasChanged(); + } + + StateHasChanged(); + Status = null; + + await base.OnInitializedAsync(); + } + +} \ No newline at end of file |