From bb8c2637af3b7982e7a4b2fd15e2fbec613d0848 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 30 Jun 2023 03:36:58 +0200 Subject: Todays progress --- MatrixRoomUtils.Web/Pages/Index.razor | 67 ++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 9 deletions(-) (limited to 'MatrixRoomUtils.Web/Pages/Index.razor') diff --git a/MatrixRoomUtils.Web/Pages/Index.razor b/MatrixRoomUtils.Web/Pages/Index.razor index 33cca61..16a6cee 100644 --- a/MatrixRoomUtils.Web/Pages/Index.razor +++ b/MatrixRoomUtils.Web/Pages/Index.razor @@ -1,7 +1,7 @@ @page "/" -@using MatrixRoomUtils.Web.Shared.IndexComponents -@inject NavigationManager NavigationManager -@inject ILocalStorageService LocalStorage +@using MatrixRoomUtils.Core.Helpers +@using MatrixRoomUtils.Core.Responses +@using MatrixRoomUtils.Web.Shared.SimpleComponents Index @@ -12,18 +12,67 @@ Small collection of tools to do not-so-everyday things.
Signed in accounts - Add new account

- @foreach (var (token, user) in RuntimeCache.LoginSessions) { - + @foreach (var (auth, user) in _users.OrderByDescending(x=>x.Value.RoomCount)) { + var _auth = auth; + var _user = user; +
+ +

+ + @_user.DisplayName on @_auth.Homeserver + Remove + +

+

Member of @_user.RoomCount rooms

+ +
} @code { + private Dictionary _users = new(); + protected override async Task OnInitializedAsync() { - if (!RuntimeCache.WasLoaded) { - Console.WriteLine("[INDEX] !!! LOCALSTORAGE WAS NOT LOADED !!!"); - await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); - } + _currentSession = await MRUStorage.GetCurrentToken(); + _users.Clear(); + var tokens = await MRUStorage.GetAllTokens(); + var profileTasks = tokens.Select(async token => { + UserInfo userInfo = new(); + var hs = await HomeserverProvider.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken); + var roomCountTask = hs.GetJoinedRooms(); + var profile = await hs.GetProfile(hs.WhoAmI.UserId); + userInfo.DisplayName = profile.DisplayName ?? hs.WhoAmI.UserId; + userInfo.AvatarUrl = MediaResolver.ResolveMediaUri(hs.FullHomeServerDomain, + profile.AvatarUrl + ?? "https://api.dicebear.com/6.x/identicon/svg?seed=" + hs.WhoAmI.UserId + ); + userInfo.RoomCount = (await roomCountTask).Count; + _users.Add(token, userInfo); + // StateHasChanged(); + }); + await Task.WhenAll(profileTasks); await base.OnInitializedAsync(); } + + private class UserInfo { + internal string AvatarUrl { get; set; } + internal string DisplayName { get; set; } + internal int RoomCount { get; set; } = 0; + } + + private async Task RemoveUser(LoginResponse auth) { + await MRUStorage.RemoveToken(auth); + if ((await MRUStorage.GetCurrentToken()).AccessToken == auth.AccessToken) + MRUStorage.SetCurrentToken((await MRUStorage.GetAllTokens()).FirstOrDefault()); + await OnInitializedAsync(); + } + + private LoginResponse _currentSession; + + private async Task SwitchSession(LoginResponse auth) { + Console.WriteLine($"Switching to {auth.Homeserver} {auth.AccessToken} {auth.UserId}"); + await MRUStorage.SetCurrentToken(auth); + await OnInitializedAsync(); + } } \ No newline at end of file -- cgit 1.4.1