diff options
Diffstat (limited to 'internal/typeutils')
-rw-r--r-- | internal/typeutils/internaltofrontend.go | 32 | ||||
-rw-r--r-- | internal/typeutils/internaltofrontend_test.go | 58 |
2 files changed, 59 insertions, 31 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 9d99205f6..d24ae3ea5 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -624,7 +624,7 @@ func (c *Converter) AttachmentToAPIAttachment(ctx context.Context, a *gtsmodel.M Y: a.FileMeta.Focus.Y, } - case gtsmodel.FileTypeVideo: + case gtsmodel.FileTypeVideo, gtsmodel.FileTypeAudio: if i := a.FileMeta.Original.Duration; i != nil { apiAttachment.Meta.Original.Duration = *i } @@ -1062,14 +1062,36 @@ func (c *Converter) StatusToWebStatus( webStatus.PollOptions = PollOptions } + // Mark local. + webStatus.Local = *s.Local + // Set additional templating // variables on media attachments. - for _, a := range webStatus.MediaAttachments { - a.Sensitive = webStatus.Sensitive + + // Get gtsmodel attachments + // into a convenient map. + ogAttachments := make( + map[string]*gtsmodel.MediaAttachment, + len(s.Attachments), + ) + for _, a := range s.Attachments { + ogAttachments[a.ID] = a } - // Mark this as a local status. - webStatus.Local = *s.Local + // Convert each API attachment + // into a web attachment. + webStatus.MediaAttachments = make( + []*apimodel.WebAttachment, + len(apiStatus.MediaAttachments), + ) + for i, apiAttachment := range apiStatus.MediaAttachments { + ogAttachment := ogAttachments[apiAttachment.ID] + webStatus.MediaAttachments[i] = &apimodel.WebAttachment{ + Attachment: apiAttachment, + Sensitive: apiStatus.Sensitive, + MIMEType: ogAttachment.File.ContentType, + } + } return webStatus, nil } diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go index 7bbca8ae7..6429df4fa 100644 --- a/internal/typeutils/internaltofrontend_test.go +++ b/internal/typeutils/internaltofrontend_test.go @@ -63,8 +63,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontend() { "header_description": "A very old-school screenshot of the original team fortress mod for quake", "followers_count": 2, "following_count": 2, - "statuses_count": 7, - "last_status_at": "2023-12-10T09:24:00.000Z", + "statuses_count": 8, + "last_status_at": "2024-01-10T09:24:00.000Z", "emojis": [], "fields": [], "enable_rss": true, @@ -116,8 +116,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendAliasedAndMoved() "header_description": "A very old-school screenshot of the original team fortress mod for quake", "followers_count": 2, "following_count": 2, - "statuses_count": 7, - "last_status_at": "2023-12-10T09:24:00.000Z", + "statuses_count": 8, + "last_status_at": "2024-01-10T09:24:00.000Z", "emojis": [], "fields": [], "source": { @@ -209,8 +209,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendWithEmojiStruct() "header_description": "A very old-school screenshot of the original team fortress mod for quake", "followers_count": 2, "following_count": 2, - "statuses_count": 7, - "last_status_at": "2023-12-10T09:24:00.000Z", + "statuses_count": 8, + "last_status_at": "2024-01-10T09:24:00.000Z", "emojis": [ { "shortcode": "rainbow", @@ -259,8 +259,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendWithEmojiIDs() { "header_description": "A very old-school screenshot of the original team fortress mod for quake", "followers_count": 2, "following_count": 2, - "statuses_count": 7, - "last_status_at": "2023-12-10T09:24:00.000Z", + "statuses_count": 8, + "last_status_at": "2024-01-10T09:24:00.000Z", "emojis": [ { "shortcode": "rainbow", @@ -305,8 +305,8 @@ func (suite *InternalToFrontendTestSuite) TestAccountToFrontendSensitive() { "header_description": "A very old-school screenshot of the original team fortress mod for quake", "followers_count": 2, "following_count": 2, - "statuses_count": 7, - "last_status_at": "2023-12-10T09:24:00.000Z", + "statuses_count": 8, + "last_status_at": "2024-01-10T09:24:00.000Z", "emojis": [], "fields": [], "source": { @@ -943,6 +943,18 @@ func (suite *InternalToFrontendTestSuite) TestStatusToWebStatus() { "emojis": [], "fields": [] }, + "mentions": [ + { + "id": "01F8MH17FWEB39HZJ76B6VXSKF", + "username": "admin", + "url": "http://localhost:8080/@admin", + "acct": "admin" + } + ], + "tags": [], + "emojis": [], + "card": null, + "poll": null, "media_attachments": [ { "id": "01HE7Y3C432WRSNS10EZM86SA5", @@ -971,7 +983,9 @@ func (suite *InternalToFrontendTestSuite) TestStatusToWebStatus() { } }, "description": "Photograph of a sloth, Public Domain.", - "blurhash": "LNEC{|w}0K9GsEtPM|j[NFbHoeof" + "blurhash": "LNEC{|w}0K9GsEtPM|j[NFbHoeof", + "Sensitive": true, + "MIMEType": "image/jpg" }, { "id": "01HE7ZFX9GKA5ZZVD4FACABSS9", @@ -983,7 +997,9 @@ func (suite *InternalToFrontendTestSuite) TestStatusToWebStatus() { "preview_remote_url": null, "meta": null, "description": "SVG line art of a sloth, public domain", - "blurhash": "L26*j+~qE1RP?wxut7ofRlM{R*of" + "blurhash": "L26*j+~qE1RP?wxut7ofRlM{R*of", + "Sensitive": true, + "MIMEType": "image/svg" }, { "id": "01HE88YG74PVAB81PX2XA9F3FG", @@ -995,21 +1011,11 @@ func (suite *InternalToFrontendTestSuite) TestStatusToWebStatus() { "preview_remote_url": null, "meta": null, "description": "Jolly salsa song, public domain.", - "blurhash": null + "blurhash": null, + "Sensitive": true, + "MIMEType": "audio/mpeg" } ], - "mentions": [ - { - "id": "01F8MH17FWEB39HZJ76B6VXSKF", - "username": "admin", - "url": "http://localhost:8080/@admin", - "acct": "admin" - } - ], - "tags": [], - "emojis": [], - "card": null, - "poll": null, "LanguageTag": "en", "PollOptions": null, "Local": false, @@ -1249,7 +1255,7 @@ func (suite *InternalToFrontendTestSuite) TestInstanceV1ToFrontend() { }, "stats": { "domain_count": 2, - "status_count": 19, + "status_count": 20, "user_count": 4 }, "thumbnail": "http://localhost:8080/assets/logo.png", |