@page "/" @using LibMatrix.Responses @using LibMatrix @using LibMatrix.Helpers @using LibMatrix.Homeservers @using ArcaneLibs.Extensions 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; @* *@ }

Manage Remove

@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(); AuthenticatedHomeserverGeneric 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; Console.WriteLine(profile.ToJson()); 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(UserAuth 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(UserAuth auth) { Console.WriteLine($"Switching to {auth.Homeserver} {auth.UserId} via {auth.Proxy}"); await MRUStorage.SetCurrentToken(auth); await OnInitializedAsync(); } }