diff options
| author | 2025-08-12 14:05:15 +0200 | |
|---|---|---|
| committer | 2025-08-12 14:05:15 +0200 | |
| commit | 660cf2c94ce6a87ac33d704ab1f68b2d4a258d92 (patch) | |
| tree | 03eeab55b2f3bc2f3fc7667d245ed3b561a4f1a4 /internal/cleaner | |
| parent | [docs] Revamp trusted proxies warning a bit (#4365) (diff) | |
| download | gotosocial-660cf2c94ce6a87ac33d704ab1f68b2d4a258d92.tar.xz | |
[feature] scheduled statuses (#4274)
An implementation of [`scheduled_statuses`](https://docs.joinmastodon.org/methods/scheduled_statuses/). Will fix #1006.
this is heavily WIP and I need to reorganize some of the code, working on this made me somehow familiar with the codebase and led to my other recent contributions
i told some fops on fedi i'd work on this so i have no choice but to complete it 🤷‍♀️
btw iirc my avatar presents me working on this branch
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4274
Co-authored-by: nicole mikołajczyk <git@mkljczk.pl>
Co-committed-by: nicole mikołajczyk <git@mkljczk.pl>
Diffstat (limited to 'internal/cleaner')
| -rw-r--r-- | internal/cleaner/media.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/internal/cleaner/media.go b/internal/cleaner/media.go index 84473bc22..99fd5779f 100644 --- a/internal/cleaner/media.go +++ b/internal/cleaner/media.go @@ -375,6 +375,25 @@ func (m *Media) pruneUnused(ctx context.Context, media *gtsmodel.MediaAttachment } } + // Check whether we have the required scheduled status for media. + scheduledStatus, missing, err := m.getRelatedScheduledStatus(ctx, media) + if err != nil { + return false, err + } else if missing { + l.Debug("deleting due to missing scheduled status") + return true, m.delete(ctx, media) + } + + if scheduledStatus != nil { + // Check whether still attached to status. + for _, id := range scheduledStatus.MediaIDs { + if id == media.ID { + l.Debug("skippping as attached to scheduled status") + return false, nil + } + } + } + // Media totally unused, delete it. l.Debug("deleting unused media") return true, m.delete(ctx, media) @@ -543,6 +562,29 @@ func (m *Media) getRelatedStatus(ctx context.Context, media *gtsmodel.MediaAttac return status, false, nil } +func (m *Media) getRelatedScheduledStatus(ctx context.Context, media *gtsmodel.MediaAttachment) (*gtsmodel.ScheduledStatus, bool, error) { + if media.ScheduledStatusID == "" { + // no related status. + return nil, false, nil + } + + // Load the status related to this media. + status, err := m.state.DB.GetScheduledStatusByID( + gtscontext.SetBarebones(ctx), + media.ScheduledStatusID, + ) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + return nil, false, gtserror.Newf("error fetching scheduled status by id %s: %w", media.ScheduledStatusID, err) + } + + if status == nil { + // status is missing. + return nil, true, nil + } + + return status, false, nil +} + func (m *Media) uncache(ctx context.Context, media *gtsmodel.MediaAttachment) error { if gtscontext.DryRun(ctx) { // Dry run, do nothing. |
