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 03bc10513..a9fee34f7 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 5862039f7..983935184 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 bdc0cc0ad..a98eff78a 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 a461b945f..ec09f702d 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. @@ -324,6 +328,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 7641d6cf8..cdaf3a03b 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{}, @@ -695,6 +696,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 96fbbee27..661c12d5f 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 // raw + 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 9ef52e0a6..e97d9e1b2 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. @@ -67,5 +68,6 @@ func (p *Processor) SourceGet(ctx context.Context, requester *gtsmodel.Account, ID: status.ID, Text: status.Text, SpoilerText: spoilerText, + 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 341161b67..81ee98863 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -1395,6 +1395,7 @@ func (c *Converter) baseStatusToFrontend( Emojis: apiEmojis, Card: nil, // TODO: implement cards Text: s.Text, + ContentType: ContentTypeToAPIContentType(s.ContentType), InteractionPolicy: *apiInteractionPolicy, } @@ -1630,6 +1631,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 e4b7f82ba..eccb0fd81 100644 --- a/internal/typeutils/internaltofrontend_test.go +++ b/internal/typeutils/internaltofrontend_test.go @@ -725,6 +725,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToFrontendHTMLContentWarning "card": null, "poll": null, "text": "hello world! #welcome ! first post on the instance :rainbow: !", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ @@ -905,6 +906,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": { @@ -1090,6 +1092,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": { @@ -1823,6 +1826,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": [ @@ -1921,6 +1925,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": [ @@ -2044,6 +2049,7 @@ func (suite *InternalToFrontendTestSuite) TestStatusToAPIStatusPendingApproval() "card": null, "poll": null, "text": "Hi @1happyturtle, can I reply?", + "content_type": "text/markdown", "interaction_policy": { "can_favourite": { "always": [ @@ -3522,6 +3528,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": [ @@ -3620,6 +3627,7 @@ func (suite *InternalToFrontendTestSuite) TestIntReqToAPI() { "card": null, "poll": null, "text": "Hi @1happyturtle, can I reply?", + "content_type": "text/markdown", "interaction_policy": { "can_favourite": { "always": [ @@ -3779,6 +3787,7 @@ func (suite *InternalToFrontendTestSuite) TestConversationToAPISelfConvo() { "card": null, "poll": null, "text": "hello everyone!", + "content_type": "text/plain", "interaction_policy": { "can_favourite": { "always": [ @@ -3948,6 +3957,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 924344dfe..d8c91b611 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"}, EmojiIDs: []string{"01F8MH9H8E4VG3KDYJR9EGPXCQ"}, @@ -1432,6 +1433,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/admin", @@ -1453,6 +1455,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/admin", @@ -1493,6 +1496,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/admin", @@ -1515,6 +1519,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/the_mighty_zork", @@ -1535,6 +1540,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { 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", + ContentType: 0, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/the_mighty_zork", @@ -1554,6 +1560,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/the_mighty_zork", @@ -1585,6 +1592,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{}, @@ -1607,6 +1615,7 @@ func NewTestStatuses() map[string]*gtsmodel.Status { URL: "http://localhost:8080/@the_mighty_zork/statuses/01FCTA44PW9H1TB328S9AQXKDS", Content: "hi!
", Text: "hi!", + ContentType: gtsmodel.StatusContentTypePlain, CreatedAt: TimeMustParse("2022-05-20T11:37:55Z"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1627,6 +1636,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, CreatedAt: TimeMustParse("2022-05-20T11:41:10Z"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/the_mighty_zork", @@ -1646,6 +1656,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>\nThere, 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"), Local: util.Ptr(true), @@ -1688,6 +1700,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", CreatedAt: TimeMustParse("2024-11-01T11:00:00+02:00"), EditedAt: TimeMustParse("2024-11-01T11:02:00+02:00"), @@ -1708,6 +1721,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/1happyturtle", @@ -1728,6 +1742,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/1happyturtle", @@ -1758,6 +1773,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/1happyturtle", @@ -1790,6 +1806,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/1happyturtle", @@ -1820,6 +1837,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/1happyturtle", @@ -1843,6 +1861,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"), Local: util.Ptr(true), AccountURI: "http://localhost:8080/users/1happyturtle", @@ -1864,6 +1883,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, CreatedAt: TimeMustParse("2021-10-20T12:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1884,6 +1904,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, CreatedAt: TimeMustParse("2021-07-28T10:40:37+02:00"), EditedAt: time.Time{}, Local: util.Ptr(true), @@ -1904,6 +1925,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"), @@ -1978,6 +2000,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, CreatedAt: TimeMustParse("2024-11-01T09:00:00+02:00"), EditedAt: TimeMustParse("2024-11-01T09:02:00+02:00"), Local: util.Ptr(false), @@ -3494,38 +3517,42 @@ func NewTestInteractionRequests() map[string]*gtsmodel.InteractionRequest { func NewTestStatusEdits() map[string]*gtsmodel.StatusEdit { return map[string]*gtsmodel.StatusEdit{ "local_account_1_status_9_edit_1": { - ID: "01JDPZCZ2Y9KSGZW0R7ZG8T8Y2", - Content: "this is the original status
", - Text: "this is the original status", - Language: "en", - Sensitive: util.Ptr(false), - StatusID: "01JDPZC707CKDN8N4QVWM4Z1NR", - CreatedAt: TimeMustParse("2024-11-01T11:00:00+02:00"), + ID: "01JDPZCZ2Y9KSGZW0R7ZG8T8Y2", + Content: "this is the original status
", + Text: "this is the original status", + ContentType: gtsmodel.StatusContentTypeMarkdown, + Language: "en", + Sensitive: util.Ptr(false), + StatusID: "01JDPZC707CKDN8N4QVWM4Z1NR", + CreatedAt: TimeMustParse("2024-11-01T11:00:00+02:00"), }, "local_account_1_status_9_edit_2": { ID: "01JDPZDADMD1T9HKF94RECF7PP", 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), StatusID: "01JDPZC707CKDN8N4QVWM4Z1NR", CreatedAt: TimeMustParse("2024-11-01T11:01:00+02:00"), }, "local_account_2_status_9_edit_1": { - ID: "01JDPZPBXAX0M02YSEPB21KX4R", - Content: "this is the original status
", - Text: "this is the original status", - Language: "en", - Sensitive: util.Ptr(false), - StatusID: "01JDPZEZ77X1NX0TY9M10BK1HM", - CreatedAt: TimeMustParse("2024-11-01T10:00:00+02:00"), + ID: "01JDPZPBXAX0M02YSEPB21KX4R", + Content: "this is the original status
", + Text: "this is the original status", + ContentType: gtsmodel.StatusContentTypeMarkdown, + Language: "en", + Sensitive: util.Ptr(false), + StatusID: "01JDPZEZ77X1NX0TY9M10BK1HM", + CreatedAt: TimeMustParse("2024-11-01T10:00:00+02:00"), }, "local_account_2_status_9_edit_2": { ID: "01JDPZPJHKP7E3M0YQXEXPS1YT", 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"}, @@ -3537,6 +3564,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), StatusID: "01JDPZEZ77X1NX0TY9M10BK1HM", @@ -3546,6 +3574,7 @@ func NewTestStatusEdits() map[string]*gtsmodel.StatusEdit { ID: "01JDQ07ZZ4FGP13YN8TF63P5A6", Content: "this is the original status, with a poll!
", Text: "this is the original status, with a poll!", + ContentType: gtsmodel.StatusContentTypeMarkdown, Language: "en", Sensitive: util.Ptr(false), PollOptions: []string{"yes", "no", "spiderman"}, @@ -3558,6 +3587,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), PollOptions: []string{"yes", "no", "maybe", "i don't know", "can you repeat the question"},