@page "/notes/{id}"
@using Iceshrimp.Backend.Components.PublicPreview.Attributes
@using Iceshrimp.Backend.Core.Extensions
@attribute [PublicPreviewRouteFilter]
@inherits AsyncComponentBase
@if (_note is null)
{
Context.Response.StatusCode = 404;
Not found
This note either doesn't exist or is only accessible to authenticated users
}
else
{
if (_note.QuoteUrl != null)
{
var displayUrl = _note.QuoteUrl.StartsWith("https://") ? _note.QuoteUrl[8..] : _note.QuoteUrl[7..];
@if (_note.QuoteInaccessible)
{
This note is quoting @displayUrl , which has either been deleted or is not publicly visible.
}
else
{
This note is quoting @displayUrl
}
}
if (_note.Poll != null)
{
var total = _note.Poll.Choices.Sum(p => p.Votes);
@foreach (var choice in _note.Poll.Choices)
{
var percentage = total == 0 ? 0 : Math.Floor(choice.Votes / (double)total * 100);
@choice.Value
@choice.Votes votes @percentage%
}
List footerText = [];
@if (_note.Poll.Multiple)
footerText.Add("Multiple choice");
@if (_note.Poll.VotersCount != null)
footerText.Add($"{_note.Poll.VotersCount} users voted");
@if (_note.Poll.ExpiresAt != null)
footerText.Add(_note.Poll.ExpiresAt <= DateTime.UtcNow ? "Ended" : $"Ends at {_note.Poll.ExpiresAt.Value.ToLocalTime():G}");
@string.Join(" - ", footerText)
}
if (!ShowMedia && _note.Attachments != null)
{
This post has attachments, but this server's configuration prevents them from being displayed here.
}
else if (ShowMedia && _note.Attachments is { Count: > 0 })
{
foreach (var file in _note.Attachments)
{
if (file.MimeType.StartsWith("image/"))
{
}
else if (file.MimeType.StartsWith("video/"))
{
@(file.Alt ?? "No alt text.")
}
else
{
}
}
}
Note by @@@_note.User.Username - @_instanceName
@{
var cardType = "summary";
var previewImageUrl = _note.User.AvatarUrl;
if (ShowMedia && _note.Attachments != null)
{
if (_note.Attachments.FirstOrDefault(p => p.MimeType.StartsWith("image/") && !p.Sensitive) is { } img)
{
cardType = "summary_large_image";
previewImageUrl = img.Url;
}
}
string description;
if (_note.Cw is { } cw)
{
description = $"Content warning: {cw}";
}
else
{
var text = _note.RawText?.TruncateEllipsis(280);
if (_note.Attachments is { Count: > 0 })
{
var attachmentText = $"({_note.Attachments.Count} attachments)";
text = text is null
? attachmentText
: text + $"\n{attachmentText}";
}
description = text + (_note.QuoteUrl != null ? $"\n\nRE: {_note.QuoteUrl}" : "");
}
var username = _note.User.Username;
var title = _note.User.RawDisplayName is { } name ? $"{name} (@{username})" : $"@{username}";
}
if (!ShowRemoteReplies)
{
This server's configuration is preventing remotely originating content from being shown. This view may therefore be incomplete.
}
}