@page "/User/DirectMessages"
@using LibMatrix.EventTypes.Spec.State
@using LibMatrix.Responses
@using MatrixUtils.Abstractions
Direct Messages
@foreach (var (targetUser, rooms) in DMRooms) {
@foreach (var room in rooms) {
}
}
@code {
private string? _status;
private AuthenticatedHomeserverGeneric? Homeserver { get; set; }
private Dictionary> 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>>("m.direct");
DMRooms.Clear();
foreach (var (userId, rooms) in dms) {
var roomList = new List();
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();
}
}