A posted picture is described again by editing its post

PUT /api/v1/media/:id on a picture already posted changed the upload but never the post, which keeps its own copy, so
the new description or focal point reached nobody. As on Mastodon, PUT now takes only media not posted yet (404
otherwise), and a status edit takes media_attributes[] (id, description, focus; from a JSON body or a form): the
uploads and the post's copies change, and the Update the edit federates carries them. An edit that sends no media
keeps them as they were described. No pasture scenario edits a description, so the sweep could not see this.
MediaLifecycleTests: PUT on a posted picture is refused, an edit describes it again and keeps its warning, flag and
language as sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
thepraandClaude Opus 5.5 committed 2026-10-07 11:00:04 +02:00
1 parent a4ced664cf
commit 5252b8f320
4 files changed
+87 -2

No files matched your search

+22
View File
@@ -24,6 +24,9 @@ using PostEntity = PrivaPub.Models.Post.Post;
namespace PrivaPub.Domain.Statuses
{
// an attachment's description or focal point changed by an edit (Mastodon's media_attributes)
public sealed record MediaChange(string Id, bool HasDescription, string Description, string Focus);
public sealed class StatusDraft
{
public string Text { get; init; }
@@ -38,6 +41,7 @@ namespace PrivaPub.Domain.Statuses
public string ConversationId { get; init; }
public IReadOnlyList<string> Recipients { get; init; } = Array.Empty<string>();
public IReadOnlyList<string> MediaIds { get; init; }
public IReadOnlyList<MediaChange> MediaChanges { get; init; } = Array.Empty<MediaChange>();
// the scheduled post being published, whose media are reserved for it alone
public string ScheduledStatusId { get; init; }
public double? Latitude { get; init; }
@@ -320,6 +324,23 @@ namespace PrivaPub.Domain.Statuses
var plain = draft.PlainText || post.ContentFormat == ContentFormat.Plain;
var rendered = plain ? await _content.PlainText(draft.Text ?? string.Empty, token) : await _content.Markdown(draft.Text ?? string.Empty, token);
// descriptions and focal points changed by the edit, on the media it keeps or those the post already has
var described = media ?? (draft.MediaChanges.Count > 0
? await DB.Default.Find<MediaAttachment>().Match(m => m.PostId == post.ID && m.TrashedAt == null).ExecuteAsync(token)
: default);
foreach (var change in draft.MediaChanges)
{
if (described?.FirstOrDefault(m => m.ID == change.Id) is not { } attachment)
continue;
if (change.HasDescription)
attachment.Description = string.IsNullOrWhiteSpace(change.Description) ? default : change.Description.Trim()[..Math.Min(change.Description.Trim().Length, 1500)];
if (Domain.Media.FocalPoint.Parse(change.Focus) is { } focus)
attachment.Focus = focus;
await DB.Default.Update<MediaAttachment>().MatchID(attachment.ID)
.Modify(m => m.Description, attachment.Description).Modify(m => m.Focus, attachment.Focus).ExecuteAsync(token);
}
if (media == default && described != default)
post.Media = post.Media.Select(copy => described.FirstOrDefault(m => m.ID == copy.AttachmentId) is { } changed ? ToPostMedia(changed) : copy).ToList();
if (media != default)
{
if (!await Claim(media, post.ID, default, token))
@@ -330,6 +351,7 @@ namespace PrivaPub.Domain.Statuses
await _media.Trash(m => m.PostId == post.ID && !kept.Contains(m.ID), "edited out", token);
}
post.Title = draft.Title == default ? post.Title : Clean(draft.Title);
// as on Mastodon, an edit sends the whole post: no warning sent is no warning (the language alone falls back)
post.SpoilerText = Clean(draft.SpoilerText);
post.HasContentWarning = draft.Sensitive || post.SpoilerText != default;
post.Text = draft.Text;