@using LibMatrix
@using LibMatrix.EventTypes.Spec.State
@using LibMatrix.Helpers
@using LibMatrix.Homeservers
@using LibMatrix.Responses
@ProfileName
@if (ChildContent is not null) {
@ChildContent
}
@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();
}
}