139 lines
No EOL
4.6 KiB
Text
139 lines
No EOL
4.6 KiB
Text
@page "/notes/{id}"
|
|
@using Iceshrimp.Backend.Core.Database.Tables
|
|
@using Iceshrimp.Backend.Core.Extensions
|
|
@model Iceshrimp.Backend.Pages.NoteModel
|
|
|
|
@if (Model.Note == null)
|
|
{
|
|
Response.StatusCode = 404;
|
|
<div>
|
|
<h2>Not found</h2>
|
|
<p>This note either doesn't exist or is only accessible to authenticated users</p>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
async Task RenderNote(string name, Note note)
|
|
{
|
|
Model.TextContent.TryGetValue(note.Id, out var textContent);
|
|
var acct = "@" + note.User.Username + (note.User.Host == null ? "" : "@" + note.User.Host);
|
|
var displayName = note.User.DisplayName;
|
|
var username = note.User.Username;
|
|
|
|
<div class="user">
|
|
<img src="@(note.User.AvatarUrl ?? $"/identicon/{note.User.Id}")" class="avatar" alt="User avatar"/>
|
|
<div class="title">@name by <span>@(displayName ?? username)</span></div>
|
|
<span class="acct">@acct</span>
|
|
</div>
|
|
<small>Published at: @note.CreatedAt.ToDisplayString()</small>
|
|
@if (note.UpdatedAt != null)
|
|
{
|
|
<small>Edited at: @note.UpdatedAt.Value.ToDisplayString()</small>
|
|
}
|
|
|
|
if (textContent != null)
|
|
{
|
|
<div class="content-wrapper">
|
|
@if (note.Cw != null)
|
|
{
|
|
<details>
|
|
<summary>@note.Cw</summary>
|
|
@Html.Raw(textContent)
|
|
</details>
|
|
}
|
|
else
|
|
{
|
|
<div class="content">@Html.Raw(textContent)</div>
|
|
}
|
|
</div>
|
|
}
|
|
|
|
if (!Model.MediaAttachments.TryGetValue(note.Id, out var files)) return;
|
|
|
|
if (!Model.ShowMedia)
|
|
{
|
|
<p>
|
|
<i>This post has attachments, but this server's configuration prevents them from being displayed here.</i>
|
|
</p>
|
|
return;
|
|
}
|
|
|
|
@foreach (var file in files)
|
|
{
|
|
if (file.Type.StartsWith("image/"))
|
|
{
|
|
<img src="@file.Url" max-width="200px" alt="@file.Comment"/>
|
|
}
|
|
else if (file.Type.StartsWith("video/"))
|
|
{
|
|
<video controls max-width="200px">
|
|
<source src="@file.Url" type="@file.Type"/>
|
|
<p>@(file.Comment ?? "No alt text.")</p>
|
|
</video>
|
|
}
|
|
else
|
|
{
|
|
<div>Attachment: <a href="@file.Url">@file.Name</a> (@file.Type)</div>
|
|
}
|
|
}
|
|
}
|
|
|
|
async Task RenderQuoteUrl(string url)
|
|
{
|
|
var displayUrl = url.StartsWith("https://") ? url[8..] : url[7..];
|
|
<p>
|
|
<i>This post is quoting <a href="@url">@displayUrl</a>, but that post either has been deleted or is not publicly visible.</i>
|
|
</p>
|
|
}
|
|
|
|
ViewData["title"] = $"Note by @{Model.Note.User.Username} - Iceshrimp.NET";
|
|
@section head
|
|
{
|
|
@{
|
|
Model.MediaAttachments.TryGetValue(Model.Note.Id, out var attachments);
|
|
}
|
|
<meta name="twitter:card" content="summary">
|
|
<meta name="og:title" content="Note by @@@Model.Note.User.Username">
|
|
@if (Model.Note.Cw != null)
|
|
{
|
|
<meta name="og:description" content="Content warning: @Model.Note.Cw)">
|
|
}
|
|
else
|
|
{
|
|
var text = Model.Note.Text;
|
|
if (attachments != null)
|
|
{
|
|
var attachmentText = $"({attachments.Count} attachments)";
|
|
if (string.IsNullOrWhiteSpace(text))
|
|
text = attachmentText;
|
|
else
|
|
text += $"\n{attachmentText}";
|
|
}
|
|
|
|
<meta name="og:description" content="@(text + (Model.QuoteUrl != null ? $"\n\nRE: {Model.QuoteUrl}" : ""))">
|
|
}
|
|
<meta name="og:site_name" content="Iceshrimp.NET">
|
|
@if (Model.ShowMedia && attachments != null)
|
|
{
|
|
if (attachments.Any(p => p.Type.StartsWith("image/")))
|
|
{
|
|
<meta name="og:image" content="@attachments.First(p => p.Type.StartsWith("image/")).Url">
|
|
}
|
|
}
|
|
}
|
|
<div class="note">
|
|
@{
|
|
await RenderNote("Note", Model.Note);
|
|
if (Model.Note.Renote != null)
|
|
await RenderNote("Quote", Model.Note.Renote);
|
|
else if (Model.QuoteUrl != null)
|
|
await RenderQuoteUrl(Model.QuoteUrl);
|
|
}
|
|
</div>
|
|
if (!Model.ShowRemoteReplies)
|
|
{
|
|
<p>
|
|
<i>This server's configuration is preventing remotely originating content from being shown. This view may therefore be incomplete.</i>
|
|
</p>
|
|
}
|
|
} |