From 0784aa3218934dea46c2fa501696e7f32696168b Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Tue, 24 Dec 2024 21:16:49 +0000 Subject: [bugfix] small editing tweaks (#3631) * ensure edited_at isn't set on boost wrapper statuses * improve handling of remote status updated_at to fix previous cases * formatting * add remote status published / updated field validation checks, handle appropriately in handleStatusEdit() * specifically allowed updated to be equal to published * only check creation date change when an existing status --- internal/federation/dereferencing/status.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'internal/federation') diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go index 0a75a4802..223389ad7 100644 --- a/internal/federation/dereferencing/status.go +++ b/internal/federation/dereferencing/status.go @@ -505,6 +505,12 @@ func (d *Dereferencer) enrichStatus( latestStatus.ID = id.NewULIDFromTime(latestStatus.CreatedAt) } else { + // Ensure that status isn't trying to re-date itself. + if !latestStatus.CreatedAt.Equal(status.CreatedAt) { + err := gtserror.Newf("status %s 'published' changed", uri) + return nil, nil, gtserror.SetMalformed(err) + } + // Reuse existing status ID. latestStatus.ID = status.ID } @@ -1210,12 +1216,12 @@ func (d *Dereferencer) handleStatusEdit( } if edited { - // We prefer to use provided 'upated_at', but ensure - // it fits chronologically with creation / last update. - if !status.UpdatedAt.After(status.CreatedAt) || - !status.UpdatedAt.After(existing.UpdatedAt) { + // ensure that updated_at hasn't remained the same + // but an edit was received. manually intervene here. + if status.UpdatedAt.Equal(existing.UpdatedAt) || + status.CreatedAt.Equal(status.UpdatedAt) { - // Else fallback to now as update time. + // Simply use current fetching time. status.UpdatedAt = status.FetchedAt } @@ -1265,8 +1271,14 @@ func (d *Dereferencer) handleStatusEdit( status.EditIDs = append(status.EditIDs, edit.ID) status.Edits = append(status.Edits, &edit) - // Add updated_at and edits to list of cols. - cols = append(cols, "updated_at", "edits") + // Add edit to list of cols. + cols = append(cols, "edits") + } + + if !existing.UpdatedAt.Equal(status.UpdatedAt) { + // Whether status edited or not, + // updated_at column has changed. + cols = append(cols, "updated_at") } return cols, nil -- cgit v1.3