@page "/{User}" @using System.Text.RegularExpressions @using Iceshrimp.Frontend.Components @using Iceshrimp.Frontend.Components.Note @using Iceshrimp.Frontend.Core.Miscellaneous @using Iceshrimp.Frontend.Core.Services @using Iceshrimp.Shared.Schemas.Web @using Microsoft.AspNetCore.Authorization @using Iceshrimp.Assets.PhosphorIcons @using Iceshrimp.Frontend.Localization @using Microsoft.Extensions.Localization @attribute [Authorize] @inject ApiService Api @inject IJSRuntime Js; @inject IStringLocalizer Loc; @inject MetadataService MetadataService @inject NavigationManager Nav; @inject SessionService Session @if (_init) {
@if (UserResponse.BannerUrl != null) { }
avatar for @UserResponse.DisplayName
@@@UserResponse.Username @if (UserResponse.Host != null) { var host = $"@{UserResponse.Host}"; @host } @if (Profile != null && Profile.Relations.HasFlag(Relations.FollowedBy)) { Follows you }
@if (UserNotes.Count > 0) {
@foreach (var note in UserNotes) {
}
}
} @if (_loading) {
loading
} @if (_notFound) {
User does not exist!
} @if (_error) {
Failure
} @code { [Parameter] public string? User { get; set; } [Parameter] public string? Host { get; set; } private UserResponse UserResponse { get; set; } = null!; private UserProfileResponse? Profile { get; set; } private string? MinId { get; set; } private List UserNotes { get; set; } = []; private ElementReference MenuButton { get; set; } private Menu ContextMenu { get; set; } = null!; private bool _loading = true; private bool _init; private bool _notFound; private bool _error; private bool _fetchLock; private async Task GetNotes(string? minId) { var pq = new PaginationQuery { Limit = 10, MaxId = minId }; var notes = await Api.Users.GetUserNotesAsync(UserResponse.Id, pq); if (notes is not null && notes.Count > 0) { MinId = notes.Last().Id; UserNotes.AddRange(notes); StateHasChanged(); } } private async Task AddNotes() { if (_fetchLock == false) { _fetchLock = true; await GetNotes(MinId); _fetchLock = false; } } private async Task LoadProfile() { try { if (User is null) { _notFound = true; } else { var pattern = "^@([^@]+)@?(.+)?$"; var matches = Regex.Match(User, pattern); var userResponse = await Api.Users.LookupUserAsync(matches.Groups[1].Value, matches.Groups[2].Value); if (userResponse is null) { _notFound = true; } else { UserResponse = userResponse; Profile = await Api.Users.GetUserProfileAsync(UserResponse.Id); await GetNotes(null); _init = true; _loading = false; } } } catch (ApiException) { _loading = false; _error = true; } } private void OpenNote(string id) { Nav.NavigateTo($"/notes/{id}"); } protected override async Task OnInitializedAsync() { await LoadProfile(); } protected override async Task OnParametersSetAsync() { _init = false; _loading = true; UserNotes = []; MinId = null; Profile = null; StateHasChanged(); await LoadProfile(); } private void ToggleMenu() => ContextMenu.Toggle(MenuButton); private void EditProfile() => Nav.NavigateTo("/settings/profile"); private void Bite() => Api.Users.BiteUserAsync(UserResponse.Id); private void RemoveFromFollowers() => Api.Users.RemoveUserFromFollowersAsync(UserResponse.Id); private void OpenOriginal() { if (Profile != null) Js.InvokeVoidAsync("open", Profile.Url, "_blank"); } private async Task CopyLink() { var instance = await MetadataService.Instance.Value; await Js.InvokeVoidAsync("navigator.clipboard.writeText", $"https://{instance.WebDomain}/@{UserResponse.Username}" + (UserResponse.Host != null ? $"@{UserResponse.Host}" : "")); } private void CopyLinkRemote() { if (Profile != null) Js.InvokeVoidAsync("navigator.clipboard.writeText", Profile.Url); } private void CopyUsername() => Js.InvokeVoidAsync("navigator.clipboard.writeText", $"@{UserResponse.Username}" + (UserResponse.Host != null ? $"@{UserResponse.Host}" : "")); }