summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2025-01-08 10:29:23 +0000
committerLibravatar GitHub <noreply@github.com>2025-01-08 11:29:23 +0100
commitc013892ca22fe6bface8dc580571b2f0527cd1db (patch)
tree8eccf44e188b2d906aa0bafc9fb37640f1526844 /internal/typeutils
parent[feature] Create/update/remove domain permission subscriptions (#3623) (diff)
downloadgotosocial-c013892ca22fe6bface8dc580571b2f0527cd1db.tar.xz
[chore] replace statuses.updated_at column with statuses.edited_at (#3636)
* update statuses table to replace updated_at column with edited_at * code comment * better code comments, fix setting of status + edit + mention + poll database times * fix log to logf call * fix status.EditIDs not being carried over in dereferencer.encrichStatus() * move status.EditID setting into handleStatusEdit()
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/astointernal.go12
-rw-r--r--internal/typeutils/internaltoas.go4
-rw-r--r--internal/typeutils/internaltoas_test.go4
-rw-r--r--internal/typeutils/internaltofrontend.go12
-rw-r--r--internal/typeutils/internaltorss.go2
-rw-r--r--internal/typeutils/internaltorss_test.go2
-rw-r--r--internal/typeutils/wrap_test.go1
7 files changed, 14 insertions, 23 deletions
diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go
index a473317ff..0ad9a6ff7 100644
--- a/internal/typeutils/astointernal.go
+++ b/internal/typeutils/astointernal.go
@@ -361,14 +361,12 @@ func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
status.CreatedAt = time.Now()
}
- // status.Updated
+ // status.Edited
//
- // Extract and validate update time for status. Defaults to published.
+ // Extract and validate update time for status. Defaults to none.
if upd := ap.GetUpdated(statusable); !upd.Before(status.CreatedAt) {
- status.UpdatedAt = upd
- } else if upd.IsZero() {
- status.UpdatedAt = status.CreatedAt
- } else {
+ status.EditedAt = upd
+ } else if !upd.IsZero() {
// This is a malformed status that will likely break our systems.
err := gtserror.Newf("status %s 'updated' predates 'published'", uri)
@@ -649,9 +647,9 @@ func (c *Converter) ASAnnounceToStatus(
// zero-time will fall back to db defaults.
if pub := ap.GetPublished(announceable); !pub.IsZero() {
boost.CreatedAt = pub
- boost.UpdatedAt = pub
} else {
log.Warnf(ctx, "unusable published property on %s", uri)
+ boost.CreatedAt = time.Now()
}
// Extract and load the boost actor account,
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index 7d0c483dd..644d832f5 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -486,7 +486,9 @@ func (c *Converter) StatusToAS(ctx context.Context, s *gtsmodel.Status) (ap.Stat
// Set created / updated at properties.
ap.SetPublished(status, s.CreatedAt)
- ap.SetUpdated(status, s.UpdatedAt)
+ if at := s.EditedAt; !at.IsZero() {
+ ap.SetUpdated(status, at)
+ }
// url
if s.URL != "" {
diff --git a/internal/typeutils/internaltoas_test.go b/internal/typeutils/internaltoas_test.go
index 9870c760a..c847cfc93 100644
--- a/internal/typeutils/internaltoas_test.go
+++ b/internal/typeutils/internaltoas_test.go
@@ -499,7 +499,6 @@ func (suite *InternalToASTestSuite) TestStatusToAS() {
"tag": [],
"to": "https://www.w3.org/ns/activitystreams#Public",
"type": "Note",
- "updated": "2021-10-20T12:40:37+02:00",
"url": "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY"
}`, string(bytes))
}
@@ -599,7 +598,6 @@ func (suite *InternalToASTestSuite) TestStatusWithTagsToASWithIDs() {
],
"to": "https://www.w3.org/ns/activitystreams#Public",
"type": "Note",
- "updated": "2021-10-20T11:36:45Z",
"url": "http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R"
}`, string(bytes))
}
@@ -700,7 +698,6 @@ func (suite *InternalToASTestSuite) TestStatusWithTagsToASFromDB() {
],
"to": "https://www.w3.org/ns/activitystreams#Public",
"type": "Note",
- "updated": "2021-10-20T11:36:45Z",
"url": "http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R"
}`, string(bytes))
}
@@ -781,7 +778,6 @@ func (suite *InternalToASTestSuite) TestStatusToASWithMentions() {
},
"to": "https://www.w3.org/ns/activitystreams#Public",
"type": "Note",
- "updated": "2021-11-20T13:32:16Z",
"url": "http://localhost:8080/@admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0"
}`, string(bytes))
}
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 9fb69b438..a90e88a70 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -997,7 +997,7 @@ func (c *Converter) statusToAPIFilterResults(
// Key this status based on ID + last updated time,
// to ensure we always filter on latest version.
- statusKey := s.ID + strconv.FormatInt(s.UpdatedAt.Unix(), 10)
+ statusKey := s.ID + strconv.FormatInt(s.UpdatedAt().Unix(), 10)
// Check if we have filterable fields cached for this status.
cache := c.state.Caches.StatusesFilterableFields
@@ -1384,10 +1384,8 @@ func (c *Converter) baseStatusToFrontend(
InteractionPolicy: *apiInteractionPolicy,
}
- // 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)
+ if at := s.EditedAt; !at.IsZero() {
+ timestamp := util.FormatISO8601(at)
apiStatus.EditedAt = util.Ptr(timestamp)
}
@@ -1522,8 +1520,8 @@ func (c *Converter) StatusToAPIEdits(ctx context.Context, status *gtsmodel.Statu
PollOptions: options,
PollVotes: votes,
AttachmentIDs: status.AttachmentIDs,
- AttachmentDescriptions: nil, // no change from current
- CreatedAt: status.UpdatedAt,
+ AttachmentDescriptions: nil, // no change from current
+ CreatedAt: status.UpdatedAt(), // falls back to creation
})
// Iterate through status edits, starting at newest.
diff --git a/internal/typeutils/internaltorss.go b/internal/typeutils/internaltorss.go
index 4f4b2b93a..43ca7ba48 100644
--- a/internal/typeutils/internaltorss.go
+++ b/internal/typeutils/internaltorss.go
@@ -161,7 +161,7 @@ func (c *Converter) StatusToRSSItem(ctx context.Context, s *gtsmodel.Status) (*f
Description: description,
Id: id,
IsPermaLink: "true",
- Updated: s.UpdatedAt,
+ Updated: s.EditedAt,
Created: s.CreatedAt,
Enclosure: enclosure,
Content: content,
diff --git a/internal/typeutils/internaltorss_test.go b/internal/typeutils/internaltorss_test.go
index 5c4d27208..188f63762 100644
--- a/internal/typeutils/internaltorss_test.go
+++ b/internal/typeutils/internaltorss_test.go
@@ -50,7 +50,6 @@ func (suite *InternalToRSSTestSuite) TestStatusToRSSItem1() {
suite.Equal("@the_mighty_zork@localhost:8080", item.Author.Name)
suite.Equal("@the_mighty_zork@localhost:8080 made a new post: \"hello everyone!\"", item.Description)
suite.Equal("http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY", item.Id)
- suite.EqualValues(1634726437, item.Updated.Unix())
suite.EqualValues(1634726437, item.Created.Unix())
suite.Equal("", item.Enclosure.Length)
suite.Equal("", item.Enclosure.Type)
@@ -76,7 +75,6 @@ func (suite *InternalToRSSTestSuite) TestStatusToRSSItem2() {
suite.Equal("@admin@localhost:8080", item.Author.Name)
suite.Equal("@admin@localhost:8080 posted 1 attachment: \"hello world! #welcome ! first post on the instance :rainbow: !\"", item.Description)
suite.Equal("http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R", item.Id)
- suite.EqualValues(1634729805, item.Updated.Unix())
suite.EqualValues(1634729805, item.Created.Unix())
suite.Equal("62529", item.Enclosure.Length)
suite.Equal("image/jpeg", item.Enclosure.Type)
diff --git a/internal/typeutils/wrap_test.go b/internal/typeutils/wrap_test.go
index c2c9c9464..1085c8c66 100644
--- a/internal/typeutils/wrap_test.go
+++ b/internal/typeutils/wrap_test.go
@@ -131,7 +131,6 @@ func (suite *WrapTestSuite) TestWrapNoteInCreate() {
"tag": [],
"to": "https://www.w3.org/ns/activitystreams#Public",
"type": "Note",
- "updated": "2021-10-20T12:40:37+02:00",
"url": "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY"
},
"published": "2021-10-20T12:40:37+02:00",