From 0846b76e9343fd90a33f5a8864f39cf071d3841e Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 24 Jun 2022 17:17:40 +0200 Subject: [bugfix] Fix 404 on status delete redraft (#668) * add unattach function to media processor * call delete or unattach appropriately unattach from client api, delete from federated api * typo fix --- internal/processing/fromcommon.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'internal/processing/fromcommon.go') diff --git a/internal/processing/fromcommon.go b/internal/processing/fromcommon.go index e9a2e4994..2cac20193 100644 --- a/internal/processing/fromcommon.go +++ b/internal/processing/fromcommon.go @@ -444,11 +444,23 @@ func (p *processor) deleteStatusFromTimelines(ctx context.Context, status *gtsmo // wipeStatus contains common logic used to totally delete a status // + all its attachments, notifications, boosts, and timeline entries. -func (p *processor) wipeStatus(ctx context.Context, statusToDelete *gtsmodel.Status) error { - // delete all attachments for this status - for _, a := range statusToDelete.AttachmentIDs { - if err := p.mediaProcessor.Delete(ctx, a); err != nil { - return err +func (p *processor) wipeStatus(ctx context.Context, statusToDelete *gtsmodel.Status, deleteAttachments bool) error { + // either delete all attachments for this status, or simply + // unattach all attachments for this status, so they'll be + // cleaned later by a separate process; reason to unattach rather + // than delete is that the poster might want to reattach them + // to another status immediately (in case of delete + redraft) + if deleteAttachments { + for _, a := range statusToDelete.AttachmentIDs { + if err := p.mediaProcessor.Delete(ctx, a); err != nil { + return err + } + } + } else { + for _, a := range statusToDelete.AttachmentIDs { + if _, err := p.mediaProcessor.Unattach(ctx, statusToDelete.Account, a); err != nil { + return err + } } } -- cgit v1.2.3