better code comments, fix setting of status + edit + mention + poll database times

This commit is contained in:
kim 2025-01-06 15:23:14 +00:00
commit 5188de34d5
2 changed files with 13 additions and 7 deletions

View file

@ -1100,8 +1100,12 @@ func (d *Dereferencer) handleStatusPoll(
func (d *Dereferencer) insertStatusPoll(ctx context.Context, status *gtsmodel.Status) error { func (d *Dereferencer) insertStatusPoll(ctx context.Context, status *gtsmodel.Status) error {
var err error var err error
// Generate new ID for poll from latest updated time. // Get most-recent modified time
status.Poll.ID = id.NewULIDFromTime(status.UpdatedAt()) // 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. // Update the status<->poll links.
status.PollID = status.Poll.ID status.PollID = status.Poll.ID
@ -1220,16 +1224,21 @@ func (d *Dereferencer) handleStatusEdit(
} }
if edited { 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 // Status has been editted since last
// we saw it, take snapshot of existing. // we saw it, take snapshot of existing.
var edit gtsmodel.StatusEdit var edit gtsmodel.StatusEdit
edit.ID = id.NewULIDFromTime(status.EditedAt) edit.ID = id.NewULIDFromTime(createdAt)
edit.Content = existing.Content edit.Content = existing.Content
edit.ContentWarning = existing.ContentWarning edit.ContentWarning = existing.ContentWarning
edit.Text = existing.Text edit.Text = existing.Text
edit.Language = existing.Language edit.Language = existing.Language
edit.Sensitive = existing.Sensitive edit.Sensitive = existing.Sensitive
edit.StatusID = status.ID edit.StatusID = status.ID
edit.CreatedAt = createdAt
// Copy existing attachments and descriptions. // Copy existing attachments and descriptions.
edit.AttachmentIDs = existing.AttachmentIDs 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 { if existing.Poll != nil {
// Poll only set if existing contained them. // Poll only set if existing contained them.
edit.PollOptions = existing.Poll.Options edit.PollOptions = existing.Poll.Options

View file

@ -337,7 +337,7 @@ func (suite *StatusTestSuite) TestDereferencerRefreshStatusUpdated() {
AttachmentIDs: testStatus.AttachmentIDs, AttachmentIDs: testStatus.AttachmentIDs,
PollOptions: getPollOptions(testStatus), PollOptions: getPollOptions(testStatus),
PollVotes: getPollVotes(testStatus), PollVotes: getPollVotes(testStatus),
CreatedAt: testStatus.EditedAt, CreatedAt: testStatus.UpdatedAt(),
}, },
) )
} }