about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Pages/User/DMManager.razor
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-25 14:00:02 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-25 14:00:02 +0200
commit89315fa530e1f21e2e50d94f955693b9413c98fe (patch)
treebc0747aa1b4f53147030be26c24d079fb0b34001 /MatrixRoomUtils.Web/Pages/User/DMManager.razor
parentClean up MRUStorageWrapper (diff)
downloadMatrixUtils-89315fa530e1f21e2e50d94f955693b9413c98fe.tar.xz
New things
Diffstat (limited to 'MatrixRoomUtils.Web/Pages/User/DMManager.razor')
-rw-r--r--MatrixRoomUtils.Web/Pages/User/DMManager.razor56
1 files changed, 56 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Web/Pages/User/DMManager.razor b/MatrixRoomUtils.Web/Pages/User/DMManager.razor
new file mode 100644
index 0000000..04ff6e5
--- /dev/null
+++ b/MatrixRoomUtils.Web/Pages/User/DMManager.razor
@@ -0,0 +1,56 @@
+@page "/User/DirectMessages"
+@using LibMatrix.Homeservers
+@using LibMatrix.EventTypes.Spec.State
+@using LibMatrix.Responses
+<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 MRUStorage.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) {
+                roomList.Add(new RoomInfo() { Room = HomeServer.GetRoom(room) });
+            }
+            StateHasChanged();
+        }
+
+        StateHasChanged();
+        Status = null;
+
+        await base.OnInitializedAsync();
+    }
+
+
+
+}
\ No newline at end of file