diff options
Diffstat (limited to 'internal/federation/dereferencing/status.go')
-rw-r--r-- | internal/federation/dereferencing/status.go | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go index 223389ad7..8ebfe6431 100644 --- a/internal/federation/dereferencing/status.go +++ b/internal/federation/dereferencing/status.go @@ -656,6 +656,10 @@ func (d *Dereferencer) fetchStatusMentions( err error, ) { + // Get most-recent modified time + // for use in new mention ULIDs. + updatedAt := status.UpdatedAt() + // Allocate new slice to take the yet-to-be created mention IDs. status.MentionIDs = make([]string, len(status.Mentions)) @@ -691,10 +695,10 @@ func (d *Dereferencer) fetchStatusMentions( // This mention didn't exist yet. // Generate new ID according to latest update. - mention.ID = id.NewULIDFromTime(status.UpdatedAt) + mention.ID = id.NewULIDFromTime(updatedAt) - // Set known further mention details. - mention.CreatedAt = status.UpdatedAt + // Set further mention details. + mention.CreatedAt = updatedAt mention.OriginAccount = status.Account mention.OriginAccountID = status.AccountID mention.OriginAccountURI = status.AccountURI @@ -1096,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 @@ -1133,6 +1141,10 @@ func (d *Dereferencer) handleStatusEdit( ) { var edited bool + // Copy previous status edit columns. + status.EditIDs = existing.EditIDs + status.Edits = existing.Edits + // Preallocate max slice length. cols = make([]string, 1, 13) @@ -1216,25 +1228,21 @@ func (d *Dereferencer) handleStatusEdit( } if edited { - // 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) { - - // Simply use current fetching time. - status.UpdatedAt = status.FetchedAt - } + // 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.UpdatedAt) + 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 @@ -1246,9 +1254,6 @@ func (d *Dereferencer) handleStatusEdit( } } - // Edit creation is last update time. - edit.CreatedAt = existing.UpdatedAt - if existing.Poll != nil { // Poll only set if existing contained them. edit.PollOptions = existing.Poll.Options @@ -1275,10 +1280,10 @@ func (d *Dereferencer) handleStatusEdit( cols = append(cols, "edits") } - if !existing.UpdatedAt.Equal(status.UpdatedAt) { + if !existing.EditedAt.Equal(status.EditedAt) { // Whether status edited or not, - // updated_at column has changed. - cols = append(cols, "updated_at") + // edited_at column has changed. + cols = append(cols, "edited_at") } return cols, nil |