102 lines
No EOL
3.2 KiB
Text
102 lines
No EOL
3.2 KiB
Text
@page "/notes/{NoteId}/about"
|
|
@page "/{User}/about"
|
|
@using System.Text.Json
|
|
@using System.Text.RegularExpressions
|
|
@using Iceshrimp.Assets.PhosphorIcons
|
|
@using Iceshrimp.Frontend.Components
|
|
@using Iceshrimp.Frontend.Core.Miscellaneous
|
|
@using Iceshrimp.Frontend.Core.Services
|
|
@using Iceshrimp.Frontend.Localization
|
|
@using Microsoft.AspNetCore.Authorization
|
|
@using Microsoft.AspNetCore.Components.Sections
|
|
@using Microsoft.Extensions.Localization
|
|
@attribute [Authorize]
|
|
@inject ApiService Api;
|
|
@inject IStringLocalizer<Localization> Loc;
|
|
@inject SessionService SessionSvc;
|
|
|
|
<HeadTitle Text="@Loc["About"]"/>
|
|
|
|
<SectionContent SectionName="top-bar">
|
|
<Icon Name="Icons.Info"></Icon>
|
|
@Loc["About"]
|
|
</SectionContent>
|
|
|
|
@if (State == State.Loaded)
|
|
{
|
|
@foreach (var document in Documents)
|
|
{
|
|
<details>
|
|
<summary>@document.Key</summary>
|
|
<JsonViewer Element="document.Value.RootElement"/>
|
|
</details>
|
|
}
|
|
}
|
|
@if (State == State.NotFound)
|
|
{
|
|
<i>Not found</i>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public string? NoteId { get; set; }
|
|
[Parameter] public string? User { get; set; }
|
|
private State State { get; set; }
|
|
private Dictionary<string, JsonDocument> Documents { get; set; } = [];
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (NoteId != null)
|
|
{
|
|
var noteResponse = await Api.Notes.GetNoteAsync(NoteId);
|
|
|
|
if (noteResponse == null)
|
|
{
|
|
State = State.NotFound;
|
|
return;
|
|
}
|
|
|
|
Documents.Add(Loc["Note response"], JsonSerializer.SerializeToDocument(noteResponse));
|
|
|
|
if (SessionSvc.Current?.IsAdmin is true)
|
|
{
|
|
var activity = await Api.Admin.GetActivityByNoteIdAsync(noteResponse.Id);
|
|
|
|
if (activity != null)
|
|
Documents.Add(Loc["Activity"], JsonSerializer.SerializeToDocument(activity));
|
|
}
|
|
|
|
State = State.Loaded;
|
|
}
|
|
else if (User != null)
|
|
{
|
|
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)
|
|
{
|
|
State = State.NotFound;
|
|
return;
|
|
}
|
|
|
|
var profileResponse = await Api.Users.GetUserProfileAsync(userResponse.Id);
|
|
|
|
Documents.Add(Loc["User response"], JsonSerializer.SerializeToDocument(userResponse));
|
|
Documents.Add(Loc["Profile response"], JsonSerializer.SerializeToDocument(profileResponse));
|
|
|
|
if (SessionSvc.Current?.IsAdmin is true)
|
|
{
|
|
var activity = await Api.Admin.GetActivityByUserIdAsync(userResponse.Id);
|
|
|
|
if (activity != null)
|
|
Documents.Add(Loc["Activity"], JsonSerializer.SerializeToDocument(activity));
|
|
}
|
|
|
|
State = State.Loaded;
|
|
}
|
|
else
|
|
{
|
|
State = State.NotFound;
|
|
}
|
|
}
|
|
} |