summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/astointernal.go22
-rw-r--r--internal/typeutils/internal.go24
-rw-r--r--internal/typeutils/internaltoas.go7
-rw-r--r--internal/typeutils/internaltoas_test.go4
-rw-r--r--internal/typeutils/internaltofrontend.go16
-rw-r--r--internal/typeutils/internaltofrontend_test.go100
-rw-r--r--internal/typeutils/wrap_test.go1
7 files changed, 95 insertions, 79 deletions
diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go
index cf0c0719a..1a7098673 100644
--- a/internal/typeutils/astointernal.go
+++ b/internal/typeutils/astointernal.go
@@ -111,6 +111,13 @@ func (c *Converter) ASRepresentationToAccount(
acct.UpdatedAt = pub
}
+ // Extract updated time if possible, i.e. last edited.
+ if upd := ap.GetUpdated(accountable); !upd.IsZero() {
+ acct.UpdatedAt = upd
+ } else {
+ acct.UpdatedAt = acct.CreatedAt
+ }
+
// Extract a preferred name (display name), fallback to username.
if displayName := ap.ExtractName(accountable); displayName != "" {
acct.DisplayName = displayName
@@ -348,18 +355,25 @@ func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
// zero-time will fall back to db defaults.
if pub := ap.GetPublished(statusable); !pub.IsZero() {
status.CreatedAt = pub
- status.UpdatedAt = pub
} else {
log.Warnf(ctx, "unusable published property on %s", uri)
}
+ // status.Updated
+ //
+ // Extract updated time for status, defaults to Published.
+ if upd := ap.GetUpdated(statusable); !upd.IsZero() {
+ status.UpdatedAt = upd
+ } else {
+ status.UpdatedAt = status.CreatedAt
+ }
+
// status.AccountURI
// status.AccountID
// status.Account
//
- // Account that created the status. Assume we have
- // this in the db by the time this function is called,
- // error if we don't.
+ // Account that created the status. Assume we have this
+ // in the db by the time this function is called, else error.
status.Account, err = c.getASAttributedToAccount(ctx,
status.URI,
statusable,
diff --git a/internal/typeutils/internal.go b/internal/typeutils/internal.go
index ccde6a38f..573495e0a 100644
--- a/internal/typeutils/internal.go
+++ b/internal/typeutils/internal.go
@@ -104,14 +104,8 @@ func (c *Converter) StatusToBoost(
return boost, nil
}
-func StatusToInteractionRequest(
- ctx context.Context,
- status *gtsmodel.Status,
-) (*gtsmodel.InteractionRequest, error) {
- reqID, err := id.NewULIDFromTime(status.CreatedAt)
- if err != nil {
- return nil, gtserror.Newf("error generating ID: %w", err)
- }
+func StatusToInteractionRequest(status *gtsmodel.Status) *gtsmodel.InteractionRequest {
+ reqID := id.NewULIDFromTime(status.CreatedAt)
var (
targetID string
@@ -154,17 +148,11 @@ func StatusToInteractionRequest(
InteractionType: interactionType,
Reply: reply,
Announce: announce,
- }, nil
+ }
}
-func StatusFaveToInteractionRequest(
- ctx context.Context,
- fave *gtsmodel.StatusFave,
-) (*gtsmodel.InteractionRequest, error) {
- reqID, err := id.NewULIDFromTime(fave.CreatedAt)
- if err != nil {
- return nil, gtserror.Newf("error generating ID: %w", err)
- }
+func StatusFaveToInteractionRequest(fave *gtsmodel.StatusFave) *gtsmodel.InteractionRequest {
+ reqID := id.NewULIDFromTime(fave.CreatedAt)
return &gtsmodel.InteractionRequest{
ID: reqID,
@@ -178,7 +166,7 @@ func StatusFaveToInteractionRequest(
InteractionURI: fave.URI,
InteractionType: gtsmodel.InteractionLike,
Like: fave,
- }, nil
+ }
}
func (c *Converter) StatusToSinBinStatus(
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index d46ce64e2..7d0c483dd 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -484,10 +484,9 @@ func (c *Converter) StatusToAS(ctx context.Context, s *gtsmodel.Status) (ap.Stat
status.SetActivityStreamsInReplyTo(inReplyToProp)
}
- // published
- publishedProp := streams.NewActivityStreamsPublishedProperty()
- publishedProp.Set(s.CreatedAt)
- status.SetActivityStreamsPublished(publishedProp)
+ // Set created / updated at properties.
+ ap.SetPublished(status, s.CreatedAt)
+ ap.SetUpdated(status, s.UpdatedAt)
// url
if s.URL != "" {
diff --git a/internal/typeutils/internaltoas_test.go b/internal/typeutils/internaltoas_test.go
index c847cfc93..9870c760a 100644
--- a/internal/typeutils/internaltoas_test.go
+++ b/internal/typeutils/internaltoas_test.go
@@ -499,6 +499,7 @@ 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))
}
@@ -598,6 +599,7 @@ 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))
}
@@ -698,6 +700,7 @@ 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))
}
@@ -778,6 +781,7 @@ 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 fda59610b..e0276a53b 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -1399,17 +1399,13 @@ func (c *Converter) baseStatusToFrontend(
}
// Nullable fields.
- if s.InReplyToID != "" {
- apiStatus.InReplyToID = util.Ptr(s.InReplyToID)
- }
-
- if s.InReplyToAccountID != "" {
- apiStatus.InReplyToAccountID = util.Ptr(s.InReplyToAccountID)
- }
-
- if s.Language != "" {
- apiStatus.Language = util.Ptr(s.Language)
+ if !s.UpdatedAt.Equal(s.CreatedAt) {
+ 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)
if app := s.CreatedWithApplication; app != nil {
apiStatus.Application, err = c.AppToAPIAppPublic(ctx, app)
diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go
index db37d3abd..0ec9ea05f 100644
--- a/internal/typeutils/internaltofrontend_test.go
+++ b/internal/typeutils/internaltofrontend_test.go
@@ -67,8 +67,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontend() {
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [],
"enable_rss": true
@@ -119,8 +119,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendAliasedAndMoved()
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [],
"source": {
@@ -162,8 +162,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendAliasedAndMoved()
"header_description": "Flat gray background (default header).",
"followers_count": 1,
"following_count": 1,
- "statuses_count": 8,
- "last_status_at": "2021-07-28",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [
{
@@ -217,8 +217,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendWithEmojiStruct()
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [
{
"shortcode": "rainbow",
@@ -266,8 +266,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendWithEmojiIDs() {
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [
{
"shortcode": "rainbow",
@@ -311,8 +311,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendSensitive() {
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [],
"source": {
@@ -463,6 +463,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontend() {
suite.Equal(`{
"id": "01F8MH75CBF9JFX4ZAD54N0W0R",
"created_at": "2021-10-20T11:36:45.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
@@ -641,6 +642,7 @@ func (suite *InternalToFrontendTestSuite) TestWarnFilteredStatusToFrontend() {
suite.Equal(`{
"id": "01F8MH75CBF9JFX4ZAD54N0W0R",
"created_at": "2021-10-20T11:36:45.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
@@ -807,6 +809,7 @@ func (suite *InternalToFrontendTestSuite) TestWarnFilteredBoostToFrontend() {
suite.Equal(`{
"id": "01G36SF3V6Y6V5BF9P4R7PQG7G",
"created_at": "2021-10-20T10:41:37.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
@@ -827,6 +830,7 @@ func (suite *InternalToFrontendTestSuite) TestWarnFilteredBoostToFrontend() {
"reblog": {
"id": "01F8MH75CBF9JFX4ZAD54N0W0R",
"created_at": "2021-10-20T11:36:45.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
@@ -870,8 +874,8 @@ func (suite *InternalToFrontendTestSuite) TestWarnFilteredBoostToFrontend() {
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [],
"enable_rss": true
@@ -1218,6 +1222,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendUnknownAttachments
suite.Equal(`{
"id": "01HE7XJ1CG84TBKH5V9XKBVGF5",
"created_at": "2023-11-02T10:44:25.000Z",
+ "edited_at": null,
"in_reply_to_id": "01F8MH75CBF9JFX4ZAD54N0W0R",
"in_reply_to_account_id": "01F8MH17FWEB39HZJ76B6VXSKF",
"sensitive": true,
@@ -1350,6 +1355,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToWebStatus() {
suite.Equal(`{
"id": "01HE7XJ1CG84TBKH5V9XKBVGF5",
"created_at": "2023-11-02T10:44:25.000Z",
+ "edited_at": null,
"in_reply_to_id": "01F8MH75CBF9JFX4ZAD54N0W0R",
"in_reply_to_account_id": "01F8MH17FWEB39HZJ76B6VXSKF",
"sensitive": true,
@@ -1511,6 +1517,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendUnknownLanguage()
suite.Equal(`{
"id": "01F8MH75CBF9JFX4ZAD54N0W0R",
"created_at": "2021-10-20T11:36:45.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
@@ -1654,6 +1661,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendPartialInteraction
suite.Equal(`{
"id": "01F8MHBBN8120SYH7D5S050MGK",
"created_at": "2021-10-20T10:40:37.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
@@ -1697,8 +1705,8 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendPartialInteraction
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [],
"enable_rss": true
@@ -1764,6 +1772,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToAPIStatusPendingApproval()
suite.Equal(`{
"id": "01J5QVB9VC76NPPRQ207GG4DRZ",
"created_at": "2024-02-20T10:41:37.000Z",
+ "edited_at": null,
"in_reply_to_id": "01F8MHC8VWDRBQR0N1BATDDEM5",
"in_reply_to_account_id": "01F8MH5NBDF2MV7CTC4Q5128HF",
"sensitive": false,
@@ -1993,7 +2002,7 @@ func (suite *InternalToFrontendTestSuite) TestInstanceV1ToFrontend() {
},
"stats": {
"domain_count": 2,
- "status_count": 19,
+ "status_count": 21,
"user_count": 4
},
"thumbnail": "http://localhost:8080/assets/logo.webp",
@@ -2277,8 +2286,8 @@ func (suite *InternalToFrontendTestSuite) TestReportToFrontend1() {
"header_description": "Flat gray background (default header).",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 3,
- "last_status_at": "2021-09-11",
+ "statuses_count": 4,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": []
}
@@ -2321,8 +2330,8 @@ func (suite *InternalToFrontendTestSuite) TestReportToFrontend2() {
"header_description": "Flat gray background (default header).",
"followers_count": 1,
"following_count": 1,
- "statuses_count": 8,
- "last_status_at": "2021-07-28",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [
{
@@ -2398,8 +2407,8 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend1() {
"header_description": "Flat gray background (default header).",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 3,
- "last_status_at": "2021-09-11",
+ "statuses_count": 4,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": []
}
@@ -2444,8 +2453,8 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend1() {
"header_description": "Flat gray background (default header).",
"followers_count": 1,
"following_count": 1,
- "statuses_count": 8,
- "last_status_at": "2021-07-28",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [
{
@@ -2636,8 +2645,8 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() {
"header_description": "Flat gray background (default header).",
"followers_count": 1,
"following_count": 1,
- "statuses_count": 8,
- "last_status_at": "2021-07-28",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [
{
@@ -2695,8 +2704,8 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() {
"header_description": "Flat gray background (default header).",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 3,
- "last_status_at": "2021-09-11",
+ "statuses_count": 4,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": []
}
@@ -2707,6 +2716,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() {
{
"id": "01FVW7JHQFSFK166WWKR8CBA6M",
"created_at": "2021-09-20T10:40:37.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": false,
@@ -2743,8 +2753,8 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() {
"header_description": "Flat gray background (default header).",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 3,
- "last_status_at": "2021-09-11",
+ "statuses_count": 4,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": []
},
@@ -2902,8 +2912,8 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontendSuspendedLoca
"header_description": "Flat gray background (default header).",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 3,
- "last_status_at": "2021-09-11",
+ "statuses_count": 4,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": []
}
@@ -3214,6 +3224,7 @@ func (suite *InternalToFrontendTestSuite) TestIntReqToAPI() {
"status": {
"id": "01F8MHC8VWDRBQR0N1BATDDEM5",
"created_at": "2021-10-20T10:40:37.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": true,
@@ -3254,8 +3265,8 @@ func (suite *InternalToFrontendTestSuite) TestIntReqToAPI() {
"header_description": "Flat gray background (default header).",
"followers_count": 1,
"following_count": 1,
- "statuses_count": 8,
- "last_status_at": "2021-07-28",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [
{
@@ -3307,6 +3318,7 @@ func (suite *InternalToFrontendTestSuite) TestIntReqToAPI() {
"reply": {
"id": "01J5QVB9VC76NPPRQ207GG4DRZ",
"created_at": "2024-02-20T10:41:37.000Z",
+ "edited_at": null,
"in_reply_to_id": "01F8MHC8VWDRBQR0N1BATDDEM5",
"in_reply_to_account_id": "01F8MH5NBDF2MV7CTC4Q5128HF",
"sensitive": false,
@@ -3464,8 +3476,8 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPISelfConvo() {
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [],
"enable_rss": true
@@ -3474,6 +3486,7 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPISelfConvo() {
"last_status": {
"id": "01F8MHAMCHF6Y650WCRSCP4WMY",
"created_at": "2021-10-20T10:40:37.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": true,
@@ -3517,8 +3530,8 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPISelfConvo() {
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [],
"enable_rss": true
@@ -3619,8 +3632,8 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPI() {
"header_description": "Flat gray background (default header).",
"followers_count": 1,
"following_count": 1,
- "statuses_count": 8,
- "last_status_at": "2021-07-28",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [
{
@@ -3640,6 +3653,7 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPI() {
"last_status": {
"id": "01F8MHAMCHF6Y650WCRSCP4WMY",
"created_at": "2021-10-20T10:40:37.000Z",
+ "edited_at": null,
"in_reply_to_id": null,
"in_reply_to_account_id": null,
"sensitive": true,
@@ -3683,8 +3697,8 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPI() {
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
"followers_count": 2,
"following_count": 2,
- "statuses_count": 8,
- "last_status_at": "2024-01-10",
+ "statuses_count": 9,
+ "last_status_at": "2024-11-01",
"emojis": [],
"fields": [],
"enable_rss": true
diff --git a/internal/typeutils/wrap_test.go b/internal/typeutils/wrap_test.go
index 1085c8c66..c2c9c9464 100644
--- a/internal/typeutils/wrap_test.go
+++ b/internal/typeutils/wrap_test.go
@@ -131,6 +131,7 @@ 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",