From 5188de34d5dfcf2c8351df2e626a19f2c5748523 Mon Sep 17 00:00:00 2001 From: kim Date: Mon, 6 Jan 2025 15:23:14 +0000 Subject: [PATCH] better code comments, fix setting of status + edit + mention + poll database times --- internal/federation/dereferencing/status.go | 18 ++++++++++++------ .../federation/dereferencing/status_test.go | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go index 536b5b477..2fdf55195 100644 --- a/internal/federation/dereferencing/status.go +++ b/internal/federation/dereferencing/status.go @@ -1100,8 +1100,12 @@ func (d *Dereferencer) handleStatusPoll( func (d *Dereferencer) insertStatusPoll(ctx context.Context, status *gtsmodel.Status) error { var err error - // Generate new ID for poll from latest updated time. - status.Poll.ID = id.NewULIDFromTime(status.UpdatedAt()) + // Get most-recent modified time + // which will be poll creation time. + createdAt := status.UpdatedAt() + + // Generate new ID for poll from createdAt. + status.Poll.ID = id.NewULIDFromTime(createdAt) // Update the status<->poll links. status.PollID = status.Poll.ID @@ -1220,16 +1224,21 @@ func (d *Dereferencer) handleStatusEdit( } if edited { + // Get previous-most-recent modified time, + // which will be this edit's creation time. + createdAt := existing.UpdatedAt() + // Status has been editted since last // we saw it, take snapshot of existing. var edit gtsmodel.StatusEdit - edit.ID = id.NewULIDFromTime(status.EditedAt) + edit.ID = id.NewULIDFromTime(createdAt) edit.Content = existing.Content edit.ContentWarning = existing.ContentWarning edit.Text = existing.Text edit.Language = existing.Language edit.Sensitive = existing.Sensitive edit.StatusID = status.ID + edit.CreatedAt = createdAt // Copy existing attachments and descriptions. edit.AttachmentIDs = existing.AttachmentIDs @@ -1241,9 +1250,6 @@ func (d *Dereferencer) handleStatusEdit( } } - // Edit creation is last edit time. - edit.CreatedAt = existing.EditedAt - if existing.Poll != nil { // Poll only set if existing contained them. edit.PollOptions = existing.Poll.Options diff --git a/internal/federation/dereferencing/status_test.go b/internal/federation/dereferencing/status_test.go index d530e98f0..445676ba4 100644 --- a/internal/federation/dereferencing/status_test.go +++ b/internal/federation/dereferencing/status_test.go @@ -337,7 +337,7 @@ func (suite *StatusTestSuite) TestDereferencerRefreshStatusUpdated() { AttachmentIDs: testStatus.AttachmentIDs, PollOptions: getPollOptions(testStatus), PollVotes: getPollVotes(testStatus), - CreatedAt: testStatus.EditedAt, + CreatedAt: testStatus.UpdatedAt(), }, ) }