[bugfix] small editing tweaks (#3631)

* ensure edited_at isn't set on boost wrapper statuses

* improve handling of remote status updated_at to fix previous cases

* formatting

* add remote status published / updated field validation checks, handle appropriately in handleStatusEdit()

* specifically allowed updated to be equal to published

* only check creation date change when an existing status
This commit is contained in:
kim 2024-12-24 21:16:49 +00:00 committed by GitHub
parent fe8d5f2307
commit 0784aa3218
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 12 deletions

View file

@ -505,6 +505,12 @@ func (d *Dereferencer) enrichStatus(
latestStatus.ID = id.NewULIDFromTime(latestStatus.CreatedAt) latestStatus.ID = id.NewULIDFromTime(latestStatus.CreatedAt)
} else { } else {
// Ensure that status isn't trying to re-date itself.
if !latestStatus.CreatedAt.Equal(status.CreatedAt) {
err := gtserror.Newf("status %s 'published' changed", uri)
return nil, nil, gtserror.SetMalformed(err)
}
// Reuse existing status ID. // Reuse existing status ID.
latestStatus.ID = status.ID latestStatus.ID = status.ID
} }
@ -1210,12 +1216,12 @@ func (d *Dereferencer) handleStatusEdit(
} }
if edited { if edited {
// We prefer to use provided 'upated_at', but ensure // ensure that updated_at hasn't remained the same
// it fits chronologically with creation / last update. // but an edit was received. manually intervene here.
if !status.UpdatedAt.After(status.CreatedAt) || if status.UpdatedAt.Equal(existing.UpdatedAt) ||
!status.UpdatedAt.After(existing.UpdatedAt) { status.CreatedAt.Equal(status.UpdatedAt) {
// Else fallback to now as update time. // Simply use current fetching time.
status.UpdatedAt = status.FetchedAt status.UpdatedAt = status.FetchedAt
} }
@ -1265,8 +1271,14 @@ func (d *Dereferencer) handleStatusEdit(
status.EditIDs = append(status.EditIDs, edit.ID) status.EditIDs = append(status.EditIDs, edit.ID)
status.Edits = append(status.Edits, &edit) status.Edits = append(status.Edits, &edit)
// Add updated_at and edits to list of cols. // Add edit to list of cols.
cols = append(cols, "updated_at", "edits") cols = append(cols, "edits")
}
if !existing.UpdatedAt.Equal(status.UpdatedAt) {
// Whether status edited or not,
// updated_at column has changed.
cols = append(cols, "updated_at")
} }
return cols, nil return cols, nil

View file

@ -22,6 +22,7 @@
"context" "context"
"errors" "errors"
"net/url" "net/url"
"time"
"github.com/miekg/dns" "github.com/miekg/dns"
"github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/ap"
@ -357,15 +358,21 @@ func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
status.CreatedAt = pub status.CreatedAt = pub
} else { } else {
log.Warnf(ctx, "unusable published property on %s", uri) log.Warnf(ctx, "unusable published property on %s", uri)
status.CreatedAt = time.Now()
} }
// status.Updated // status.Updated
// //
// Extract updated time for status, defaults to Published. // Extract and validate update time for status. Defaults to published.
if upd := ap.GetUpdated(statusable); !upd.IsZero() { if upd := ap.GetUpdated(statusable); !upd.Before(status.CreatedAt) {
status.UpdatedAt = upd status.UpdatedAt = upd
} else { } else if upd.IsZero() {
status.UpdatedAt = status.CreatedAt status.UpdatedAt = status.CreatedAt
} else {
// This is a malformed status that will likely break our systems.
err := gtserror.Newf("status %s 'updated' predates 'published'", uri)
return nil, gtserror.SetMalformed(err)
} }
// status.AccountURI // status.AccountURI

View file

@ -1383,11 +1383,13 @@ func (c *Converter) baseStatusToFrontend(
InteractionPolicy: *apiInteractionPolicy, InteractionPolicy: *apiInteractionPolicy,
} }
// Nullable fields. // Only set edited_at if this is a non-boost-wrapper
if !s.UpdatedAt.Equal(s.CreatedAt) { // with an updated_at date different to creation date.
if !s.UpdatedAt.Equal(s.CreatedAt) && s.BoostOfID == "" {
timestamp := util.FormatISO8601(s.UpdatedAt) timestamp := util.FormatISO8601(s.UpdatedAt)
apiStatus.EditedAt = util.Ptr(timestamp) apiStatus.EditedAt = util.Ptr(timestamp)
} }
apiStatus.InReplyToID = util.PtrIf(s.InReplyToID) apiStatus.InReplyToID = util.PtrIf(s.InReplyToID)
apiStatus.InReplyToAccountID = util.PtrIf(s.InReplyToAccountID) apiStatus.InReplyToAccountID = util.PtrIf(s.InReplyToAccountID)
apiStatus.Language = util.PtrIf(s.Language) apiStatus.Language = util.PtrIf(s.Language)