about summary refs log tree commit diff
path: root/MatrixUtils.Web/Shared/InlineUserItem.razor
diff options
context:
space:
mode:
Diffstat (limited to 'MatrixUtils.Web/Shared/InlineUserItem.razor')
-rw-r--r--MatrixUtils.Web/Shared/InlineUserItem.razor71
1 files changed, 71 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Shared/InlineUserItem.razor b/MatrixUtils.Web/Shared/InlineUserItem.razor
new file mode 100644
index 0000000..6df2307
--- /dev/null
+++ b/MatrixUtils.Web/Shared/InlineUserItem.razor
@@ -0,0 +1,71 @@
+@using LibMatrix
+@using LibMatrix.EventTypes.Spec.State
+@using LibMatrix.Helpers
+@using LibMatrix.Homeservers
+@using LibMatrix.Responses
+<div style="background-color: #ffffff11; border-radius: 0.5em; height: 1em; display: inline-block; vertical-align: middle;" alt="@UserId">
+    <img style="@(ChildContent is not null ? "vertical-align: baseline;" : "vertical-align: top;") width: 1em; height: 1em; border-radius: 50%;" src="@ProfileAvatar"/>
+    <span style="position: relative; top: -5px;">@ProfileName</span>
+
+    <div style="display: inline-block;">
+        @if (ChildContent is not null) {
+            @ChildContent
+        }
+    </div>
+
+</div>
+
+@code {
+
+    [Parameter]
+    public RenderFragment? ChildContent { get; set; }
+
+    [Parameter]
+    public UserProfileResponse? User { get; set; }
+
+    [Parameter]
+    public RoomMemberEventContent? MemberEvent { get; set; }
+
+    [Parameter]
+    public string? UserId { get; set; }
+
+    [Parameter]
+    public string? ProfileAvatar { get; set; } = null;
+
+    [Parameter]
+    public string? ProfileName { get; set; } = null;
+
+    [Parameter]
+    public AuthenticatedHomeserverGeneric? Homeserver { get; set; }
+
+    private static SemaphoreSlim _semaphoreSlim = new(128);
+
+    protected override async Task OnInitializedAsync() {
+        await base.OnInitializedAsync();
+        Homeserver ??= await RMUStorage.GetCurrentSessionOrNavigate();
+        if(Homeserver is null) return;
+
+        await _semaphoreSlim.WaitAsync();
+
+        if (User == null && UserId == null && MemberEvent != null)
+            throw new ArgumentNullException(nameof(UserId));
+
+        if (MemberEvent != null) {
+            User = new UserProfileResponse {
+                AvatarUrl = MemberEvent.AvatarUrl,
+                DisplayName = MemberEvent.DisplayName
+            };
+        }
+
+        if (User is null && UserId is not null) {
+            User ??= await Homeserver.GetProfileAsync(UserId);
+        }
+
+
+        ProfileAvatar ??= Homeserver.ResolveMediaUri(User.AvatarUrl);
+        ProfileName ??= User.DisplayName;
+
+        _semaphoreSlim.Release();
+    }
+
+}