From 9e6625d30990159b7c8ee1d5be5cb885cb6b01ca Mon Sep 17 00:00:00 2001 From: kim Date: Tue, 24 Dec 2024 14:25:02 +0000 Subject: [PATCH] improve handling of remote status updated_at to fix previous cases --- internal/federation/dereferencing/status.go | 32 ++++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go index 0a75a4802..b23f048a2 100644 --- a/internal/federation/dereferencing/status.go +++ b/internal/federation/dereferencing/status.go @@ -1157,6 +1157,25 @@ func (d *Dereferencer) handleStatusEdit( edited = true } + switch { + // We prefer to use provided 'upated_at', but ensure + // it fits chronologically with creation / last update. + + // updated_at has jumped backward, safety check it. + case existing.UpdatedAt.Before(status.UpdatedAt): + cols = append(cols, "updated_at") + + if existing.CreatedAt.After(status.UpdatedAt) { + // It's jumped behind creation date, + // at least match it to creation time. + status.UpdatedAt = existing.CreatedAt + } + + // updated_at has jumped forward, this is fine. + case existing.UpdatedAt.After(status.UpdatedAt): + cols = append(cols, "updated_at") + } + if pollChanged { // Attached poll was changed. cols = append(cols, "poll_id") @@ -1210,15 +1229,6 @@ 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) { - - // Else fallback to now as update time. - status.UpdatedAt = status.FetchedAt - } - // Status has been editted since last // we saw it, take snapshot of existing. var edit gtsmodel.StatusEdit @@ -1265,8 +1275,8 @@ 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") } return cols, nil