mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-30 06:16:15 -06:00
modify 'freshest' freshness window to be 5s, add typeutils test for status -> api edits
This commit is contained in:
parent
c8a465f9a0
commit
a2d2443103
6 changed files with 240 additions and 10 deletions
|
|
@ -1494,10 +1494,37 @@ func (c *Converter) StatusToAPIEdits(ctx context.Context, status *gtsmodel.Statu
|
|||
return nil, gtserror.Newf("error converting emojis: %w", err)
|
||||
}
|
||||
|
||||
// Iterate through status edits, starting at newest (highest index).
|
||||
apiEdits := make([]*apimodel.StatusEdit, 0, len(status.Edits))
|
||||
for i := len(status.Edits) - 1; i >= 0; i-- {
|
||||
edit := status.Edits[i]
|
||||
var votes []int
|
||||
var options []string
|
||||
|
||||
if status.Poll != nil {
|
||||
// Extract status poll options.
|
||||
options = status.Poll.Options
|
||||
|
||||
// Show votes only if closed / allowed.
|
||||
if !status.Poll.ClosedAt.IsZero() ||
|
||||
!*status.Poll.HideCounts {
|
||||
votes = status.Poll.Votes
|
||||
}
|
||||
}
|
||||
|
||||
// Append status itself to final slot in the edits
|
||||
// so we can add its revision using the below loop.
|
||||
edits := append(status.Edits, >smodel.StatusEdit{ //nolint:gocritic
|
||||
Content: status.Content,
|
||||
ContentWarning: status.ContentWarning,
|
||||
Sensitive: status.Sensitive,
|
||||
PollOptions: options,
|
||||
PollVotes: votes,
|
||||
AttachmentIDs: status.AttachmentIDs,
|
||||
AttachmentDescriptions: nil, // no change from current
|
||||
CreatedAt: status.UpdatedAt,
|
||||
})
|
||||
|
||||
// Iterate through status edits, starting at newest.
|
||||
apiEdits := make([]*apimodel.StatusEdit, 0, len(edits))
|
||||
for i := len(edits) - 1; i >= 0; i-- {
|
||||
edit := edits[i]
|
||||
|
||||
// Iterate through edit attachment IDs, getting model from 'media' lookup.
|
||||
apiAttachments := make([]*apimodel.Attachment, 0, len(edit.AttachmentIDs))
|
||||
|
|
@ -1564,7 +1591,7 @@ func (c *Converter) StatusToAPIEdits(ctx context.Context, status *gtsmodel.Statu
|
|||
Account: apiAccount,
|
||||
Poll: apiPoll,
|
||||
MediaAttachments: apiAttachments,
|
||||
Emojis: apiEmojis,
|
||||
Emojis: apiEmojis, // todo
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3737,6 +3737,133 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPI() {
|
|||
}`, string(b))
|
||||
}
|
||||
|
||||
func (suite *InternalToFrontendTestSuite) TestStatusToAPIEdits() {
|
||||
ctx, cncl := context.WithCancel(context.Background())
|
||||
defer cncl()
|
||||
|
||||
statusID := suite.testStatuses["local_account_1_status_9"].ID
|
||||
|
||||
status, err := suite.state.DB.GetStatusByID(ctx, statusID)
|
||||
suite.NoError(err)
|
||||
|
||||
apiEdits, err := suite.typeconverter.StatusToAPIEdits(ctx, status)
|
||||
suite.NoError(err)
|
||||
|
||||
b, err := json.MarshalIndent(apiEdits, "", " ")
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal(`[
|
||||
{
|
||||
"content": "\u003cp\u003ethis is the latest revision of the status, with a content-warning\u003c/p\u003e",
|
||||
"spoiler_text": "edited status",
|
||||
"sensitive": false,
|
||||
"created_at": "2024-11-01T09:02:00.000Z",
|
||||
"account": {
|
||||
"id": "01F8MH1H7YV1Z7D2C8K2730QBF",
|
||||
"username": "the_mighty_zork",
|
||||
"acct": "the_mighty_zork",
|
||||
"display_name": "original zork (he/they)",
|
||||
"locked": false,
|
||||
"discoverable": true,
|
||||
"bot": false,
|
||||
"created_at": "2022-05-20T11:09:18.000Z",
|
||||
"note": "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e",
|
||||
"url": "http://localhost:8080/@the_mighty_zork",
|
||||
"avatar": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg",
|
||||
"avatar_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.webp",
|
||||
"avatar_description": "a green goblin looking nasty",
|
||||
"avatar_media_id": "01F8MH58A357CV5K7R7TJMSH6S",
|
||||
"header": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg",
|
||||
"header_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/small/01PFPMWK2FF0D9WMHEJHR07C3Q.webp",
|
||||
"header_description": "A very old-school screenshot of the original team fortress mod for quake",
|
||||
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
|
||||
"followers_count": 2,
|
||||
"following_count": 2,
|
||||
"statuses_count": 9,
|
||||
"last_status_at": "2024-11-01",
|
||||
"emojis": [],
|
||||
"fields": [],
|
||||
"enable_rss": true
|
||||
},
|
||||
"poll": null,
|
||||
"media_attachments": [],
|
||||
"emojis": []
|
||||
},
|
||||
{
|
||||
"content": "\u003cp\u003ethis is the first status edit! now with content-warning\u003c/p\u003e",
|
||||
"spoiler_text": "edited status",
|
||||
"sensitive": false,
|
||||
"created_at": "2024-11-01T09:01:00.000Z",
|
||||
"account": {
|
||||
"id": "01F8MH1H7YV1Z7D2C8K2730QBF",
|
||||
"username": "the_mighty_zork",
|
||||
"acct": "the_mighty_zork",
|
||||
"display_name": "original zork (he/they)",
|
||||
"locked": false,
|
||||
"discoverable": true,
|
||||
"bot": false,
|
||||
"created_at": "2022-05-20T11:09:18.000Z",
|
||||
"note": "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e",
|
||||
"url": "http://localhost:8080/@the_mighty_zork",
|
||||
"avatar": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg",
|
||||
"avatar_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.webp",
|
||||
"avatar_description": "a green goblin looking nasty",
|
||||
"avatar_media_id": "01F8MH58A357CV5K7R7TJMSH6S",
|
||||
"header": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg",
|
||||
"header_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/small/01PFPMWK2FF0D9WMHEJHR07C3Q.webp",
|
||||
"header_description": "A very old-school screenshot of the original team fortress mod for quake",
|
||||
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
|
||||
"followers_count": 2,
|
||||
"following_count": 2,
|
||||
"statuses_count": 9,
|
||||
"last_status_at": "2024-11-01",
|
||||
"emojis": [],
|
||||
"fields": [],
|
||||
"enable_rss": true
|
||||
},
|
||||
"poll": null,
|
||||
"media_attachments": [],
|
||||
"emojis": []
|
||||
},
|
||||
{
|
||||
"content": "\u003cp\u003ethis is the original status\u003c/p\u003e",
|
||||
"spoiler_text": "",
|
||||
"sensitive": false,
|
||||
"created_at": "2024-11-01T09:00:00.000Z",
|
||||
"account": {
|
||||
"id": "01F8MH1H7YV1Z7D2C8K2730QBF",
|
||||
"username": "the_mighty_zork",
|
||||
"acct": "the_mighty_zork",
|
||||
"display_name": "original zork (he/they)",
|
||||
"locked": false,
|
||||
"discoverable": true,
|
||||
"bot": false,
|
||||
"created_at": "2022-05-20T11:09:18.000Z",
|
||||
"note": "\u003cp\u003ehey yo this is my profile!\u003c/p\u003e",
|
||||
"url": "http://localhost:8080/@the_mighty_zork",
|
||||
"avatar": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/original/01F8MH58A357CV5K7R7TJMSH6S.jpg",
|
||||
"avatar_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.webp",
|
||||
"avatar_description": "a green goblin looking nasty",
|
||||
"avatar_media_id": "01F8MH58A357CV5K7R7TJMSH6S",
|
||||
"header": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/original/01PFPMWK2FF0D9WMHEJHR07C3Q.jpg",
|
||||
"header_static": "http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/header/small/01PFPMWK2FF0D9WMHEJHR07C3Q.webp",
|
||||
"header_description": "A very old-school screenshot of the original team fortress mod for quake",
|
||||
"header_media_id": "01PFPMWK2FF0D9WMHEJHR07C3Q",
|
||||
"followers_count": 2,
|
||||
"following_count": 2,
|
||||
"statuses_count": 9,
|
||||
"last_status_at": "2024-11-01",
|
||||
"emojis": [],
|
||||
"fields": [],
|
||||
"enable_rss": true
|
||||
},
|
||||
"poll": null,
|
||||
"media_attachments": [],
|
||||
"emojis": []
|
||||
}
|
||||
]`, string(b))
|
||||
}
|
||||
|
||||
func TestInternalToFrontendTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(InternalToFrontendTestSuite))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue