diff --git a/docs/api/swagger.yaml b/docs/api/swagger.yaml index 25b23770c..6d9ca2f95 100644 --- a/docs/api/swagger.yaml +++ b/docs/api/swagger.yaml @@ -2840,6 +2840,13 @@ definitions: example:
Hey this is a status!
type: string x-go-name: Content + content_type: + description: |- + Content type that was used to parse the status's text. Returned when + status is deleted, so if the user is redrafting the message the client + can default to the same content type. + type: string + x-go-name: ContentType created_at: description: The date when this status was created (ISO 8601 Datetime). example: "2021-07-30T09:20:25+00:00" @@ -3042,6 +3049,13 @@ definitions: example:Hey this is a status!
type: string x-go-name: Content + content_type: + description: |- + Content type that was used to parse the status's text. Returned when + status is deleted, so if the user is redrafting the message the client + can default to the same content type. + type: string + x-go-name: ContentType created_at: description: The date when this status was created (ISO 8601 Datetime). example: "2021-07-30T09:20:25+00:00" @@ -3186,6 +3200,10 @@ definitions: StatusSource represents the source text of a status as submitted to the API when it was created. properties: + content_type: + description: Content type that was used to parse the text. + type: string + x-go-name: ContentType id: description: ID of the status. example: 01FBVD42CQ3ZEEVMW180SBX03B diff --git a/internal/api/client/statuses/statusboost_test.go b/internal/api/client/statuses/statusboost_test.go index 51b7d7652..fc750ca38 100644 --- a/internal/api/client/statuses/statusboost_test.go +++ b/internal/api/client/statuses/statusboost_test.go @@ -145,6 +145,7 @@ func (suite *StatusBoostTestSuite) TestPostBoost() { "bookmarked": true, "card": null, "content": "hello world! #welcome ! first post on the instance :rainbow: !", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [ @@ -331,6 +332,7 @@ func (suite *StatusBoostTestSuite) TestPostBoostOwnFollowersOnly() { "bookmarked": false, "card": null, "content": "hi!", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -543,6 +545,7 @@ func (suite *StatusBoostTestSuite) TestPostBoostImplicitAccept() { "bookmarked": false, "card": null, "content": "Hi @1happyturtle, can I reply?
", + "content_type": "text/markdown", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], diff --git a/internal/api/client/statuses/statuscreate_test.go b/internal/api/client/statuses/statuscreate_test.go index 53e517a6e..aba39ba23 100644 --- a/internal/api/client/statuses/statuscreate_test.go +++ b/internal/api/client/statuses/statuscreate_test.go @@ -139,6 +139,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatus() { "bookmarked": false, "card": null, "content": "this is a brand new status! #helloworld
", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -225,6 +226,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusIntPolicy() { "bookmarked": false, "card": null, "content": "this is a brand new status! #helloworld
", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -321,6 +323,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusIntPolicyJSON() { "bookmarked": false, "card": null, "content": "this is a brand new status! #helloworld
", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -535,6 +538,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusMarkdown() { "bookmarked": false, "card": null, "content": "This is a post written in markdown
", + "content_type": "text/markdown", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -619,6 +623,7 @@ func (suite *StatusCreateTestSuite) TestMentionUnknownAccount() { "bookmarked": false, "card": null, "content": "hello @brand_new_person
", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -697,6 +702,7 @@ func (suite *StatusCreateTestSuite) TestPostStatusWithLinksAndTags() { "bookmarked": false, "card": null, "content": "#test alright, should be able to post #links with fragments in them now, let's see........
https://docs.gotosocial.org/en/latest/user_guide/posts/#links
#gotosocial
(tobi remember to pull the docker image challenge)
here is a rainbow emoji a few times! :rainbow: :rainbow: :rainbow:
here's an emoji that isn't in the db: :test_emoji:
hello @1happyturtle this reply should work!
", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -962,6 +970,7 @@ func (suite *StatusCreateTestSuite) TestAttachNewMediaSuccess() { "bookmarked": false, "card": null, "content": "here's an image attachment
", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -1067,6 +1076,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusWithNoncanonicalLanguageTag "bookmarked": false, "card": null, "content": "English? what's English? i speak American
", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -1142,6 +1152,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusWithPollForm() { "bookmarked": false, "card": null, "content": "this is a status with a poll!
", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -1239,6 +1250,7 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusWithPollJSON() { "bookmarked": false, "card": null, "content": "this is a status with a poll!
", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], diff --git a/internal/api/client/statuses/statusdelete_test.go b/internal/api/client/statuses/statusdelete_test.go index 6f62ef45f..d7efd5725 100644 --- a/internal/api/client/statuses/statusdelete_test.go +++ b/internal/api/client/statuses/statusdelete_test.go @@ -77,6 +77,10 @@ func (suite *StatusDeleteTestSuite) TestPostDelete() { suite.NoError(err) suite.NotNil(statusReply) + // Check that text and content type are returned for delete and redraft + suite.Equal("hello everyone!", statusReply.Text) + suite.Equal(apimodel.StatusContentTypePlain, statusReply.ContentType) + if !testrig.WaitFor(func() bool { _, err := suite.db.GetStatusByID(ctx, targetStatus.ID) return errors.Is(err, db.ErrNoEntries) diff --git a/internal/api/client/statuses/statusfave_test.go b/internal/api/client/statuses/statusfave_test.go index 8851b4d58..42b812fdf 100644 --- a/internal/api/client/statuses/statusfave_test.go +++ b/internal/api/client/statuses/statusfave_test.go @@ -104,6 +104,7 @@ func (suite *StatusFaveTestSuite) TestPostFave() { "bookmarked": false, "card": null, "content": "🐕🐕🐕🐕🐕", + "content_type": "text/plain", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], @@ -228,6 +229,7 @@ func (suite *StatusFaveTestSuite) TestPostFaveImplicitAccept() { "bookmarked": false, "card": null, "content": "Hi @1happyturtle, can I reply?
", + "content_type": "text/markdown", "created_at": "right the hell just now babyee", "edited_at": null, "emojis": [], diff --git a/internal/api/client/statuses/statusmute_test.go b/internal/api/client/statuses/statusmute_test.go index 20ee590f8..174ac14dc 100644 --- a/internal/api/client/statuses/statusmute_test.go +++ b/internal/api/client/statuses/statusmute_test.go @@ -149,6 +149,7 @@ func (suite *StatusMuteTestSuite) TestMuteUnmuteStatus() { "card": null, "poll": null, "text": "hello everyone!", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ @@ -238,6 +239,7 @@ func (suite *StatusMuteTestSuite) TestMuteUnmuteStatus() { "card": null, "poll": null, "text": "hello everyone!", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ diff --git a/internal/api/client/statuses/statussource_test.go b/internal/api/client/statuses/statussource_test.go index 797a462ed..e36a939ef 100644 --- a/internal/api/client/statuses/statussource_test.go +++ b/internal/api/client/statuses/statussource_test.go @@ -92,7 +92,8 @@ func (suite *StatusSourceTestSuite) TestGetSource() { suite.Equal(`{ "id": "01F8MHAMCHF6Y650WCRSCP4WMY", "text": "hello everyone!", - "spoiler_text": "introduction post" + "spoiler_text": "introduction post", + "content_type": "text/plain" }`, dst.String()) } diff --git a/internal/api/model/status.go b/internal/api/model/status.go index 2ee3123e6..fe82f09e3 100644 --- a/internal/api/model/status.go +++ b/internal/api/model/status.go @@ -110,6 +110,10 @@ type Status struct { // so the user may redraft from the source text without the client having to reverse-engineer // the original text from the HTML content. Text string `json:"text,omitempty"` + // Content type that was used to parse the status's text. Returned when + // status is deleted, so if the user is redrafting the message the client + // can default to the same content type. + ContentType StatusContentType `json:"content_type,omitempty"` // A list of filters that matched this status and why they matched, if there are any such filters. Filtered []FilterResult `json:"filtered,omitempty"` // The interaction policy for this status, as set by the status author. @@ -320,6 +324,9 @@ type StatusSource struct { // Plain-text version of spoiler text. SpoilerText string `json:"spoiler_text"` + + // Content type that was used to parse the text. + ContentType StatusContentType `json:"content_type,omitempty"` } // StatusEdit represents one historical revision of a status, containing diff --git a/internal/cache/size.go b/internal/cache/size.go index 1c8c5fe2e..3920a6f19 100644 --- a/internal/cache/size.go +++ b/internal/cache/size.go @@ -649,6 +649,7 @@ func sizeofStatus() uintptr { URL: exampleURI, Content: exampleText, Text: exampleText, + ContentType: gtsmodel.StatusContentTypePlain, AttachmentIDs: []string{exampleID, exampleID, exampleID}, TagIDs: []string{exampleID, exampleID, exampleID}, MentionIDs: []string{}, @@ -694,6 +695,7 @@ func sizeofStatusEdit() uintptr { Content: exampleText, ContentWarning: exampleUsername, // similar length Text: exampleText, + ContentType: gtsmodel.StatusContentTypePlain, Language: "en", Sensitive: func() *bool { ok := false; return &ok }(), AttachmentIDs: []string{exampleID, exampleID, exampleID}, diff --git a/internal/db/bundb/migrations/20250226013442_add_status_content_type.go b/internal/db/bundb/migrations/20250226013442_add_status_content_type.go new file mode 100644 index 000000000..ba9584ac2 --- /dev/null +++ b/internal/db/bundb/migrations/20250226013442_add_status_content_type.go @@ -0,0 +1,78 @@ +// GoToSocial +// Copyright (C) GoToSocial Authors admin@gotosocial.org +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, seepoopoo peepee
", apiStatus.Content) + + // the test accounts don't have settings, so we're comparing to + // the global default value instead of the requester's default + suite.Equal(apimodel.StatusContentTypeDefault, apiStatus.ContentType) +} + func TestStatusCreateTestSuite(t *testing.T) { suite.Run(t, new(StatusCreateTestSuite)) } diff --git a/internal/processing/status/edit.go b/internal/processing/status/edit.go index 95665074e..590fe565a 100644 --- a/internal/processing/status/edit.go +++ b/internal/processing/status/edit.go @@ -84,11 +84,14 @@ func (p *Processor) Edit( return nil, errWithCode } + // Process incoming content type. + contentType := processContentType(form.ContentType, status, requester.Settings.StatusContentType) + // Process incoming status edit content fields. content, errWithCode := p.processContent(ctx, requester, statusID, - string(form.ContentType), + contentType, form.Status, form.SpoilerText, form.Language, @@ -256,6 +259,7 @@ func (p *Processor) Edit( edit.Content = status.Content edit.ContentWarning = status.ContentWarning edit.Text = status.Text + edit.ContentType = status.ContentType edit.Language = status.Language edit.Sensitive = status.Sensitive edit.StatusID = status.ID @@ -298,6 +302,7 @@ func (p *Processor) Edit( status.Content = content.Content status.ContentWarning = content.ContentWarning status.Text = form.Status + status.ContentType = contentType status.Language = content.Language status.Sensitive = &form.Sensitive status.AttachmentIDs = form.MediaIDs diff --git a/internal/processing/status/edit_test.go b/internal/processing/status/edit_test.go index 36ebf2765..e6673c3cc 100644 --- a/internal/processing/status/edit_test.go +++ b/internal/processing/status/edit_test.go @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/suite" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/internal/util" "github.com/superseriousbusiness/gotosocial/internal/util/xslices" ) @@ -90,6 +91,142 @@ func (suite *StatusEditTestSuite) TestSimpleEdit() { previousEdit := latestStatus.Edits[len(latestStatus.Edits)-1] suite.Equal(status.Content, previousEdit.Content) suite.Equal(status.Text, previousEdit.Text) + suite.Equal(status.ContentType, previousEdit.ContentType) + suite.Equal(status.ContentWarning, previousEdit.ContentWarning) + suite.Equal(*status.Sensitive, *previousEdit.Sensitive) + suite.Equal(status.Language, previousEdit.Language) + suite.Equal(status.UpdatedAt(), previousEdit.CreatedAt) +} + +func (suite *StatusEditTestSuite) TestEditChangeContentType() { + // Create cancellable context to use for test. + ctx, cncl := context.WithCancel(context.Background()) + defer cncl() + + // Get a local account to use as test requester. + requester := suite.testAccounts["local_account_1"] + requester, _ = suite.state.DB.GetAccountByID(ctx, requester.ID) + + // Get requester's existing plain text status to perform an edit on. + status := suite.testStatuses["local_account_1_status_6"] + status, _ = suite.state.DB.GetStatusByID(ctx, status.ID) + + // Prepare edit with a Markdown body. + form := &apimodel.StatusEditRequest{ + Status: "ooh the status is *fancy* now!", + ContentType: apimodel.StatusContentTypeMarkdown, + SpoilerText: "shhhhh", + Sensitive: true, + Language: "fr", // hoh hoh hoh + MediaIDs: nil, + MediaAttributes: nil, + Poll: nil, + } + + // Pass the prepared form to the status processor to perform the edit. + apiStatus, errWithCode := suite.status.Edit(ctx, requester, status.ID, form) + suite.NotNil(apiStatus) + suite.NoError(errWithCode) + + // Check response against input form data. + suite.Equal(form.Status, apiStatus.Text) + suite.Equal(form.ContentType, apiStatus.ContentType) + suite.Equal(form.SpoilerText, apiStatus.SpoilerText) + suite.Equal(form.Sensitive, apiStatus.Sensitive) + suite.Equal(form.Language, *apiStatus.Language) + suite.NotEqual(util.FormatISO8601(status.EditedAt), *apiStatus.EditedAt) + + // Fetched the latest version of edited status from the database. + latestStatus, err := suite.state.DB.GetStatusByID(ctx, status.ID) + suite.NoError(err) + + // Check latest status against input form data. + suite.Equal(form.Status, latestStatus.Text) + suite.Equal(typeutils.APIContentTypeToContentType(form.ContentType), latestStatus.ContentType) + suite.Equal(form.SpoilerText, latestStatus.ContentWarning) + suite.Equal(form.Sensitive, *latestStatus.Sensitive) + suite.Equal(form.Language, latestStatus.Language) + suite.Equal(len(status.EditIDs)+1, len(latestStatus.EditIDs)) + suite.NotEqual(status.UpdatedAt(), latestStatus.UpdatedAt()) + + // Populate all historical edits for this status. + err = suite.state.DB.PopulateStatusEdits(ctx, latestStatus) + suite.NoError(err) + + // Check previous status edit matches original status content. + previousEdit := latestStatus.Edits[len(latestStatus.Edits)-1] + suite.Equal(status.Content, previousEdit.Content) + suite.Equal(status.Text, previousEdit.Text) + suite.Equal(status.ContentType, previousEdit.ContentType) + suite.Equal(status.ContentWarning, previousEdit.ContentWarning) + suite.Equal(*status.Sensitive, *previousEdit.Sensitive) + suite.Equal(status.Language, previousEdit.Language) + suite.Equal(status.UpdatedAt(), previousEdit.CreatedAt) +} + +func (suite *StatusEditTestSuite) TestEditOnStatusWithNoContentType() { + // Create cancellable context to use for test. + ctx, cncl := context.WithCancel(context.Background()) + defer cncl() + + // Get a local account to use as test requester. + requester := suite.testAccounts["local_account_1"] + requester, _ = suite.state.DB.GetAccountByID(ctx, requester.ID) + + // Get requester's existing status, which has no + // stored content type, to perform an edit on. + status := suite.testStatuses["local_account_1_status_2"] + status, _ = suite.state.DB.GetStatusByID(ctx, status.ID) + + // Prepare edit without setting a new content type. + form := &apimodel.StatusEditRequest{ + Status: "how will this text be parsed? it is a mystery", + SpoilerText: "shhhhh", + Sensitive: true, + Language: "fr", // hoh hoh hoh + MediaIDs: nil, + MediaAttributes: nil, + Poll: nil, + } + + // Pass the prepared form to the status processor to perform the edit. + apiStatus, errWithCode := suite.status.Edit(ctx, requester, status.ID, form) + suite.NotNil(apiStatus) + suite.NoError(errWithCode) + + // Check response against input form data. + suite.Equal(form.Status, apiStatus.Text) + suite.NotEqual(util.FormatISO8601(status.EditedAt), *apiStatus.EditedAt) + + // Check response against requester's default content type setting + // (the test accounts don't actually have settings on them, so + // instead we check that the global default content type is used) + suite.Equal(apimodel.StatusContentTypeDefault, apiStatus.ContentType) + + // Fetched the latest version of edited status from the database. + latestStatus, err := suite.state.DB.GetStatusByID(ctx, status.ID) + suite.NoError(err) + + // Check latest status against input form data + suite.Equal(form.Status, latestStatus.Text) + suite.Equal(form.Sensitive, *latestStatus.Sensitive) + suite.Equal(form.Language, latestStatus.Language) + suite.Equal(len(status.EditIDs)+1, len(latestStatus.EditIDs)) + suite.NotEqual(status.UpdatedAt(), latestStatus.UpdatedAt()) + + // Check latest status against requester's default content + // type (again, actually just checking for the global default) + suite.Equal(gtsmodel.StatusContentTypeDefault, latestStatus.ContentType) + + // Populate all historical edits for this status. + err = suite.state.DB.PopulateStatusEdits(ctx, latestStatus) + suite.NoError(err) + + // Check previous status edit matches original status content. + previousEdit := latestStatus.Edits[len(latestStatus.Edits)-1] + suite.Equal(status.Content, previousEdit.Content) + suite.Equal(status.Text, previousEdit.Text) + suite.Equal(status.ContentType, previousEdit.ContentType) suite.Equal(status.ContentWarning, previousEdit.ContentWarning) suite.Equal(*status.Sensitive, *previousEdit.Sensitive) suite.Equal(status.Language, previousEdit.Language) diff --git a/internal/processing/status/get.go b/internal/processing/status/get.go index 812f01683..6065c7cfe 100644 --- a/internal/processing/status/get.go +++ b/internal/processing/status/get.go @@ -24,6 +24,7 @@ import ( apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/typeutils" ) // Get gets the given status, taking account of privacy settings and blocks etc. @@ -56,5 +57,6 @@ func (p *Processor) SourceGet(ctx context.Context, requester *gtsmodel.Account, ID: status.ID, Text: status.Text, SpoilerText: status.ContentWarning, + ContentType: typeutils.ContentTypeToAPIContentType(status.ContentType), }, nil } diff --git a/internal/typeutils/frontendtointernal.go b/internal/typeutils/frontendtointernal.go index b341aa6ae..eb60c548e 100644 --- a/internal/typeutils/frontendtointernal.go +++ b/internal/typeutils/frontendtointernal.go @@ -44,6 +44,16 @@ func APIVisToVis(m apimodel.Visibility) gtsmodel.Visibility { return 0 } +func APIContentTypeToContentType(m apimodel.StatusContentType) gtsmodel.StatusContentType { + switch m { + case apimodel.StatusContentTypePlain: + return gtsmodel.StatusContentTypePlain + case apimodel.StatusContentTypeMarkdown: + return gtsmodel.StatusContentTypeMarkdown + } + return 0 +} + func APIMarkerNameToMarkerName(m apimodel.MarkerName) gtsmodel.MarkerName { switch m { case apimodel.MarkerNameHome: diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 8bd92512a..3c5bd5ca0 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -1391,6 +1391,7 @@ func (c *Converter) baseStatusToFrontend( Emojis: apiEmojis, Card: nil, // TODO: implement cards Text: s.Text, + ContentType: ContentTypeToAPIContentType(s.ContentType), InteractionPolicy: *apiInteractionPolicy, } @@ -1626,6 +1627,17 @@ func (c *Converter) VisToAPIVis(ctx context.Context, m gtsmodel.Visibility) apim return "" } +// Converts a gts status content type into its api equivalent +func ContentTypeToAPIContentType(m gtsmodel.StatusContentType) apimodel.StatusContentType { + switch m { + case gtsmodel.StatusContentTypePlain: + return apimodel.StatusContentTypePlain + case gtsmodel.StatusContentTypeMarkdown: + return apimodel.StatusContentTypeMarkdown + } + return "" +} + // InstanceRuleToAdminAPIRule converts a local instance rule into its api equivalent for serving at /api/v1/admin/instance/rules/:id func InstanceRuleToAPIRule(r gtsmodel.Rule) apimodel.InstanceRule { return apimodel.InstanceRule{ diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go index e749dafe4..7ff08711b 100644 --- a/internal/typeutils/internaltofrontend_test.go +++ b/internal/typeutils/internaltofrontend_test.go @@ -578,6 +578,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontend() { "card": null, "poll": null, "text": "hello world! #welcome ! first post on the instance :rainbow: !", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ @@ -758,6 +759,7 @@ func (suite *InternalToFrontendTestSuite) TestWarnFilteredStatusToFrontend() { "card": null, "poll": null, "text": "hello world! #welcome ! first post on the instance :rainbow: ! fnord", + "content_type": "text/plain", "filtered": [ { "filter": { @@ -943,6 +945,7 @@ func (suite *InternalToFrontendTestSuite) TestWarnFilteredBoostToFrontend() { "card": null, "poll": null, "text": "hello world! #welcome ! first post on the instance :rainbow: ! fnord", + "content_type": "text/plain", "filtered": [ { "filter": { @@ -1676,6 +1679,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendUnknownLanguage() "card": null, "poll": null, "text": "hello world! #welcome ! first post on the instance :rainbow: !", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ @@ -1774,6 +1778,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendPartialInteraction "card": null, "poll": null, "text": "this is a very personal post that I don't want anyone to interact with at all, and i only want mutuals to see it", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ @@ -1897,6 +1902,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToAPIStatusPendingApproval() "card": null, "poll": null, "text": "Hi @1happyturtle, can I reply?", + "content_type": "text/markdown", "interaction_policy": { "can_favourite": { "always": [ @@ -3375,6 +3381,7 @@ func (suite *InternalToFrontendTestSuite) TestIntReqToAPI() { "card": null, "poll": null, "text": "🐢 i don't mind people sharing and liking this one but I want to moderate replies to it 🐢", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ @@ -3473,6 +3480,7 @@ func (suite *InternalToFrontendTestSuite) TestIntReqToAPI() { "card": null, "poll": null, "text": "Hi @1happyturtle, can I reply?", + "content_type": "text/markdown", "interaction_policy": { "can_favourite": { "always": [ @@ -3632,6 +3640,7 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPISelfConvo() { "card": null, "poll": null, "text": "hello everyone!", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ @@ -3801,6 +3810,7 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPI() { "card": null, "poll": null, "text": "hello everyone!", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ diff --git a/testrig/testmodels.go b/testrig/testmodels.go index 42b2150dc..fcd976446 100644 --- a/testrig/testmodels.go +++ b/testrig/testmodels.go @@ -1408,6 +1408,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R", Content: "hello world! #welcome ! first post on the instance :rainbow: !", Text: "hello world! #welcome ! first post on the instance :rainbow: !", + ContentType: gtsmodel.StatusContentTypePlain, AttachmentIDs: []string{"01F8MH6NEM8D7527KZAECTCR76"}, TagIDs: []string{"01F8MHA1A2NF9MJ3WCCQ3K8BSZ"}, MentionIDs: []string{}, @@ -1436,6 +1437,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37", Content: "🐕🐕🐕🐕🐕", Text: "🐕🐕🐕🐕🐕", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-10-20T12:36:45Z"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1459,6 +1461,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0", Content: "hi @the_mighty_zork welcome to the instance!", Text: "hi @the_mighty_zork welcome to the instance!", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-11-20T13:32:16Z"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1506,6 +1509,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@admin/statuses/01J5QVB9VC76NPPRQ207GG4DRZ", Content: `Hi @1happyturtle, can I reply?
`, Text: "Hi @1happyturtle, can I reply?", + ContentType: gtsmodel.StatusContentTypeMarkdown, CreatedAt: TimeMustParse("2024-02-20T12:41:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1531,6 +1535,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY", Content: "hello everyone!", Text: "hello everyone!", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1552,8 +1557,9 @@ func NewTestStatuses() map[string]*gtsmodel.Status { ID: "01F8MHAYFKS4KMXF8K5Y1C0KRN", URI: "http://localhost:8080/users/the_mighty_zork/statuses/01F8MHAYFKS4KMXF8K5Y1C0KRN", URL: "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAYFKS4KMXF8K5Y1C0KRN", - Content: "this is a Public local-only post that shouldn't federate, but it's still boostable, replyable, and likeable", - Text: "this is a Public local-only post that shouldn't federate, but it's still boostable, replyable, and likeable", + Content: "this is a Public local-only post that shouldn't federate, but it's still boostable, replyable, and likeable. also it has no stored content type", + Text: "this is a Public local-only post that shouldn't federate, but it's still boostable, replyable, and likeable. also it has no stored content type", + ContentType: 0, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1577,6 +1583,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@the_mighty_zork/statuses/01F8MHBBN8120SYH7D5S050MGK", Content: "this is a very personal post that I don't want anyone to interact with at all, and i only want mutuals to see it", Text: "this is a very personal post that I don't want anyone to interact with at all, and i only want mutuals to see it", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1611,6 +1618,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@the_mighty_zork/statuses/01F8MH82FYRXD2RC6108DAJ5HB", Content: "here's a little gif of trent.... and also a cow", Text: "here's a little gif of trent.... and also a cow", + ContentType: gtsmodel.StatusContentTypePlain, AttachmentIDs: []string{"01F8MH7TDVANYKWVE8VVKFPJTJ", "01CDR64G398ADCHXK08WWTHEZ5"}, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, @@ -1635,6 +1643,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@the_mighty_zork/statuses/01FCTA44PW9H1TB328S9AQXKDS", Content: "hi!", Text: "hi!", + ContentType: gtsmodel.StatusContentTypePlain, AttachmentIDs: []string{}, CreatedAt: TimeMustParse("2022-05-20T11:37:55Z"), EditedAt: time.Time{}, @@ -1659,6 +1668,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@the_mighty_zork/statuses/065TKBPE0H2AH8S5X8JCK4XC58", Content: "what do you think of sloths?", Text: "what do you think of sloths?", + ContentType: gtsmodel.StatusContentTypePlain, AttachmentIDs: nil, CreatedAt: TimeMustParse("2022-05-20T11:41:10Z"), EditedAt: time.Time{}, @@ -1684,6 +1694,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@the_mighty_zork/statuses/01HH9KYNQPA416TNJ53NSATP40", Content: "Here's a bunch of HTML, read it and weep, weep then!
<section class="about-user">\n <div class="col-header">\n <h2>About</h2>\n </div> \n <div class="fields">\n <h3 class="sr-only">Fields</h3>\n <dl>\n <div class="field">\n <dt>should you follow me?</dt>\n <dd>maybe!</dd>\n </div>\n <div class="field">\n <dt>age</dt>\n <dd>120</dd>\n </div>\n </dl>\n </div>\n <div class="bio">\n <h3 class="sr-only">Bio</h3>\n <p>i post about things that concern me</p>\n </div>\n <div class="sr-only" role="group">\n <h3 class="sr-only">Stats</h3>\n <span>Joined in Jun, 2022.</span>\n <span>8 posts.</span>\n <span>Followed by 1.</span>\n <span>Following 1.</span>\n </div>\n <div class="accountstats" aria-hidden="true">\n <b>Joined</b><time datetime="2022-06-04T13:12:00.000Z">Jun, 2022</time>\n <b>Posts</b><span>8</span>\n <b>Followed by</b><span>1</span>\n <b>Following</b><span>1</span>\n </div>\n</section>\n
There, hope you liked that!
", Text: "Here's a bunch of HTML, read it and weep, weep then!\n\n```html\nThanks! Here's a NIN track
", Text: "Thanks! Here's a NIN track", + ContentType: gtsmodel.StatusContentTypeMarkdown, AttachmentIDs: []string{"01J2M20K6K9XQC4WSB961YJHV6"}, CreatedAt: TimeMustParse("2024-01-10T11:24:00+02:00"), EditedAt: time.Time{}, @@ -1732,6 +1744,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@the_mighty_zork/statuses/01JDPZC707CKDN8N4QVWM4Z1NR", Content: "this is the latest revision of the status, with a content-warning
", Text: "this is the latest revision of the status, with a content-warning", + ContentType: gtsmodel.StatusContentTypeMarkdown, ContentWarning: "edited status", AttachmentIDs: nil, CreatedAt: TimeMustParse("2024-11-01T11:00:00+02:00"), @@ -1758,6 +1771,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@1happyturtle/statuses/01F8MHBQCBTDKN6X5VHGMMN4MA", Content: "🐢 hi everyone i post about turtles 🐢", Text: "🐢 hi everyone i post about turtles 🐢", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1781,6 +1795,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@1happyturtle/statuses/01F8MHC0H0A7XHTVH5F596ZKBM", Content: "🐢 this one is federated, likeable, and boostable but not replyable 🐢", Text: "🐢 this one is federated, likeable, and boostable but not replyable 🐢", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1815,6 +1830,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@1happyturtle/statuses/01F8MHC8VWDRBQR0N1BATDDEM5", Content: "🐢 i don't mind people sharing and liking this one but I want to moderate replies to it 🐢", Text: "🐢 i don't mind people sharing and liking this one but I want to moderate replies to it 🐢", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1850,6 +1866,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@1happyturtle/statuses/01F8MHCP5P2NWYQ416SBA0XSEV", Content: "🐢 this is a public status but I want it local only and not boostable 🐢", Text: "🐢 this is a public status but I want it local only and not boostable 🐢", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1884,6 +1901,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@1happyturtle/statuses/01FCQSQ667XHJ9AV9T27SJJSX5", Content: "🐢 @the_mighty_zork hi zork! 🐢", Text: "🐢 @the_mighty_zork hi zork! 🐢", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1910,6 +1928,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@1happyturtle/statuses/01FN3VJGFH10KR7S2PB0GFJZYG", Content: "🐢 @the_mighty_zork hi zork, this is a direct message, shhhhhh! 🐢", Text: "🐢 @the_mighty_zork hi zork, this is a direct message, shhhhhh! 🐢", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1937,6 +1956,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@1happyturtle/statuses/01G20ZM733MGN8J344T4ZDDFY1", Content: "🐢 hi followers! did u know i'm a turtle? 🐢", Text: "🐢 hi followers! did u know i'm a turtle? 🐢", + ContentType: gtsmodel.StatusContentTypePlain, AttachmentIDs: []string{}, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, @@ -1961,6 +1981,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@1happyturtle/statuses/01HEN2PRXT0TF4YDRA64FZZRN7", Content: "hey everyone i got stuck in a shed. any ideas for how to get out?", Text: "hey everyone i got stuck in a shed. any ideas for how to get out?", + ContentType: gtsmodel.StatusContentTypePlain, AttachmentIDs: nil, CreatedAt: TimeMustParse("2021-07-28T10:40:37+02:00"), EditedAt: time.Time{}, @@ -1986,6 +2007,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@1happyturtle/statuses/01JDPZEZ77X1NX0TY9M10BK1HM", Content: "now edited to bring back the previous edit's media!
", Text: "now edited to bring back the previous edit's media!", + ContentType: gtsmodel.StatusContentTypeMarkdown, ContentWarning: "edit with media attachments", AttachmentIDs: []string{"01JDQ164HM08SGJ7ZEK9003Z4B"}, CreatedAt: TimeMustParse("2024-11-01T10:00:00+02:00"), @@ -2087,6 +2109,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://fossbros-anonymous.io/@foss_satan/statuses/______", Content: "this is the latest status edit without poll change
", Text: "this is the latest status edit without poll change", + ContentType: gtsmodel.StatusContentTypeMarkdown, ContentWarning: "", AttachmentIDs: nil, CreatedAt: TimeMustParse("2024-11-01T09:00:00+02:00"), @@ -3617,6 +3640,7 @@ func NewTestStatusEdits() map[string]*gtsmodel.StatusEdit { Content: "this is the original status
", ContentWarning: "", Text: "this is the original status", + ContentType: gtsmodel.StatusContentTypeMarkdown, Language: "en", Sensitive: util.Ptr(false), AttachmentIDs: nil, @@ -3630,6 +3654,7 @@ func NewTestStatusEdits() map[string]*gtsmodel.StatusEdit { Content: "this is the first status edit! now with content-warning
", ContentWarning: "edited status", Text: "this is the first status edit! now with content-warning", + ContentType: gtsmodel.StatusContentTypeMarkdown, Language: "en", Sensitive: util.Ptr(false), AttachmentIDs: nil, @@ -3643,6 +3668,7 @@ func NewTestStatusEdits() map[string]*gtsmodel.StatusEdit { Content: "this is the original status
", ContentWarning: "", Text: "this is the original status", + ContentType: gtsmodel.StatusContentTypeMarkdown, Language: "en", Sensitive: util.Ptr(false), AttachmentIDs: nil, @@ -3656,6 +3682,7 @@ func NewTestStatusEdits() map[string]*gtsmodel.StatusEdit { Content: "now edited to have some media!
", ContentWarning: "edit with media attachments", Text: "now edited to have some media!", + ContentType: gtsmodel.StatusContentTypeMarkdown, Language: "en", Sensitive: util.Ptr(true), AttachmentIDs: []string{"01JDQ164HM08SGJ7ZEK9003Z4B"}, @@ -3669,6 +3696,7 @@ func NewTestStatusEdits() map[string]*gtsmodel.StatusEdit { Content: "now edited to remove the media
", ContentWarning: "edit missing previous media attachments", Text: "now edited to remove the media", + ContentType: gtsmodel.StatusContentTypeMarkdown, Language: "en", Sensitive: util.Ptr(false), AttachmentIDs: nil, @@ -3682,6 +3710,7 @@ func NewTestStatusEdits() map[string]*gtsmodel.StatusEdit { Content: "this is the original status, with a poll!
", ContentWarning: "", Text: "this is the original status, with a poll!", + ContentType: gtsmodel.StatusContentTypeMarkdown, Language: "en", Sensitive: util.Ptr(false), AttachmentIDs: nil, @@ -3695,6 +3724,7 @@ func NewTestStatusEdits() map[string]*gtsmodel.StatusEdit { Content: "this is the first status edit! now with a different poll!
", ContentWarning: "edited status", Text: "this is the first status edit! now with a different poll!", + ContentType: gtsmodel.StatusContentTypeMarkdown, Language: "en", Sensitive: util.Ptr(false), AttachmentIDs: nil,