@page "/" @using MatrixRoomUtils.Web.Shared.SimpleComponents @using LibMatrix.Responses @using LibMatrix @using LibMatrix.Helpers Index

Rory&::MatrixUtils

Small collection of tools to do not-so-everyday things.

Signed in accounts - Add new account

@foreach (var (auth, user) in _users.OrderByDescending(x=>x.Value.RoomCount)) { var _auth = auth;

@user.DisplayName on @_auth.Homeserver Remove

Member of @user.RoomCount rooms

}
@code { private Dictionary _users = new(); protected override async Task OnInitializedAsync() { _currentSession = await MRUStorage.GetCurrentToken(); _users.Clear(); var tokens = await MRUStorage.GetAllTokens(); var profileTasks = tokens.Select(async token => { UserInfo userInfo = new(); AuthenticatedHomeServer hs; try { hs = await HomeserverProvider.GetAuthenticatedWithToken(token.Homeserver, token.AccessToken); } catch (MatrixException e) { if (e.ErrorCode == "M_UNKNOWN_TOKEN") { NavigationManager.NavigateTo("/InvalidSession?ctx="+token.AccessToken); return; } throw; } 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; } } 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(); } }