summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/federation/dereferencing/status.go26
-rw-r--r--internal/typeutils/astointernal.go13
-rw-r--r--internal/typeutils/internaltofrontend.go6
3 files changed, 33 insertions, 12 deletions
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go
index 0a75a4802..223389ad7 100644
--- a/internal/federation/dereferencing/status.go
+++ b/internal/federation/dereferencing/status.go
@@ -505,6 +505,12 @@ func (d *Dereferencer) enrichStatus(
latestStatus.ID = id.NewULIDFromTime(latestStatus.CreatedAt)
} 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.
latestStatus.ID = status.ID
}
@@ -1210,12 +1216,12 @@ func (d *Dereferencer) handleStatusEdit(
}
if edited {
- // We prefer to use provided 'upated_at', but ensure
- // it fits chronologically with creation / last update.
- if !status.UpdatedAt.After(status.CreatedAt) ||
- !status.UpdatedAt.After(existing.UpdatedAt) {
+ // 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) {
- // Else fallback to now as update time.
+ // Simply use current fetching time.
status.UpdatedAt = status.FetchedAt
}
@@ -1265,8 +1271,14 @@ func (d *Dereferencer) handleStatusEdit(
status.EditIDs = append(status.EditIDs, edit.ID)
status.Edits = append(status.Edits, &edit)
- // Add updated_at and edits to list of cols.
- cols = append(cols, "updated_at", "edits")
+ // Add edit to list of cols.
+ 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
diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go
index 1a7098673..a473317ff 100644
--- a/internal/typeutils/astointernal.go
+++ b/internal/typeutils/astointernal.go
@@ -22,6 +22,7 @@ import (
"context"
"errors"
"net/url"
+ "time"
"github.com/miekg/dns"
"github.com/superseriousbusiness/gotosocial/internal/ap"
@@ -357,15 +358,21 @@ func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
status.CreatedAt = pub
} else {
log.Warnf(ctx, "unusable published property on %s", uri)
+ status.CreatedAt = time.Now()
}
// status.Updated
//
- // Extract updated time for status, defaults to Published.
- if upd := ap.GetUpdated(statusable); !upd.IsZero() {
+ // Extract and validate update time for status. Defaults to published.
+ if upd := ap.GetUpdated(statusable); !upd.Before(status.CreatedAt) {
status.UpdatedAt = upd
- } else {
+ } else if upd.IsZero() {
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
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 3208fcb51..0d5e15078 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -1383,11 +1383,13 @@ func (c *Converter) baseStatusToFrontend(
InteractionPolicy: *apiInteractionPolicy,
}
- // Nullable fields.
- if !s.UpdatedAt.Equal(s.CreatedAt) {
+ // Only set edited_at if this is a non-boost-wrapper
+ // with an updated_at date different to creation date.
+ if !s.UpdatedAt.Equal(s.CreatedAt) && s.BoostOfID == "" {
timestamp := util.FormatISO8601(s.UpdatedAt)
apiStatus.EditedAt = util.Ptr(timestamp)
}
+
apiStatus.InReplyToID = util.PtrIf(s.InReplyToID)
apiStatus.InReplyToAccountID = util.PtrIf(s.InReplyToAccountID)
apiStatus.Language = util.PtrIf(s.Language)