MatrixRoomUtils

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

IndexUserItem.razor (2256B)


      1 @using MatrixRoomUtils.Web.Classes
      2 @using System.Text.Json
      3 @using Blazored.LocalStorage
      4 @using MatrixRoomUtils.Core
      5 @using MatrixRoomUtils.Core.Extensions
      6 @using Index = MatrixRoomUtils.Web.Pages.Index
      7 @using System.ComponentModel.DataAnnotations
      8 @inject ILocalStorageService LocalStorage
      9 @inject NavigationManager NavigationManager
     10 
     11 <div style="margin-bottom: 1em;">
     12     <img style="border-radius: 50%; height: 3em; width: 3em;" src="@_avatarUrl"/>
     13     <p style="margin-left: 1em; margin-top: -0.5em; display: inline-block;">
     14         <input type="radio" name="csa" checked="@(RuntimeCache.LastUsedToken == User.AccessToken)" onclick="@SetCurrent" style="text-decoration-line: unset;"/>
     15         <b>@User.Profile.DisplayName</b> on <b>@User.LoginResponse.HomeServer</b>
     16         <a href="#" onclick="@RemoveUser">Remove</a>
     17     </p>
     18     <p style="margin-top: -1.5em; margin-left: 4em;">Member of @_roomCount rooms</p>
     19 
     20 </div>
     21 
     22 @code {
     23 
     24     [Parameter]
     25     public UserInfo User { get; set; } = null!;
     26 
     27     private string _avatarUrl { get; set; }
     28     private int _roomCount { get; set; } = 0;
     29 
     30     protected override async Task OnInitializedAsync()
     31     {
     32         var hs = await new AuthenticatedHomeServer(User.LoginResponse.UserId, User.AccessToken, User.LoginResponse.HomeServer).Configure();
     33         if (User.Profile.AvatarUrl != null && User.Profile.AvatarUrl != "")
     34             _avatarUrl = hs.ResolveMediaUri(User.Profile.AvatarUrl);
     35         else _avatarUrl = "https://api.dicebear.com/6.x/identicon/svg?seed=" + User.LoginResponse.UserId;
     36         _roomCount = (await hs.GetJoinedRooms()).Count;
     37         await base.OnInitializedAsync();
     38     }
     39 
     40     private async Task RemoveUser()
     41     {
     42         Console.WriteLine(User.ToJson());
     43         RuntimeCache.LoginSessions.Remove(User.AccessToken);
     44 
     45         StateHasChanged();
     46     }
     47 
     48     private async Task SetCurrent()
     49     {
     50         RuntimeCache.LastUsedToken = User.AccessToken;
     51     //RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(LocalStorageWrapper.LoginSessions[Token].LoginResponse.HomeServer);
     52         await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
     53         await LocalStorageWrapper.InitialiseRuntimeVariables(LocalStorage);
     54         StateHasChanged();
     55     }
     56 }