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
parent 2f26878e33
commit 5188de34d5
2 changed files with 13 additions and 7 deletions
internal/federation/dereferencing

View file

@ -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

View file

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