about summary refs log tree commit diff
path: root/MatrixRoomUtils.Web/Shared/IndexComponents/IndexUserItem.razor
blob: 03a7145c71d5e8a4e04a02d9852ad06356cd1f0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@using MatrixRoomUtils.Web.Classes
@using System.Text.Json
@using Blazored.LocalStorage
@using MatrixRoomUtils.Core
@using MatrixRoomUtils.Core.Extensions
@using Index = MatrixRoomUtils.Web.Pages.Index
@using System.ComponentModel.DataAnnotations
@inject ILocalStorageService LocalStorage
@inject NavigationManager NavigationManager

<div style="margin-bottom: 1em;">
    <img style="border-radius: 50%; height: 3em; width: 3em;" src="@_avatarUrl"/>
    <p style="margin-left: 1em; margin-top: -0.5em; display: inline-block;">
        <input type="radio" name="csa" checked="@(RuntimeCache.LastUsedToken == User.AccessToken)" onclick="@SetCurrent" style="text-decoration-line: unset;"/>
        <b>@User.Profile.DisplayName</b> on <b>@User.LoginResponse.HomeServer</b>
        <a href="#" onclick="@RemoveUser">Remove</a>
    </p>
    <p style="margin-top: -1.5em; margin-left: 4em;">Member of @_roomCount rooms</p>

</div>

@code {

    [Parameter]
    public UserInfo User { get; set; } = null!;

    private string? _avatarUrl { get; set; }
    private int _roomCount { get; set; } = 0;

    protected override async Task OnInitializedAsync()
    {
        var hs = await new AuthenticatedHomeServer(User.LoginResponse.UserId, User.AccessToken, User.LoginResponse.HomeServer).Configure();
        if (User.Profile.AvatarUrl != null && User.Profile.AvatarUrl != "")
            _avatarUrl = hs.ResolveMediaUri(User.Profile.AvatarUrl);
        else _avatarUrl = "https://api.dicebear.com/6.x/identicon/svg?seed=" + User.LoginResponse.UserId;
        _roomCount = (await hs.GetJoinedRooms()).Count;
        await base.OnInitializedAsync();
    }

    private async Task RemoveUser()
    {
        Console.WriteLine(User.ToJson());
        RuntimeCache.LoginSessions.Remove(User.AccessToken);

        StateHasChanged();
    }

    private async Task SetCurrent()
    {
        RuntimeCache.LastUsedToken = User.AccessToken;
    //RuntimeCache.CurrentHomeserver = await MatrixAuth.ResolveHomeserverFromWellKnown(LocalStorageWrapper.LoginSessions[Token].LoginResponse.HomeServer);
        await LocalStorageWrapper.SaveToLocalStorage(LocalStorage);
        await LocalStorageWrapper.InitialiseRuntimeVariables(LocalStorage);
        StateHasChanged();
    }
}