diff options
Diffstat (limited to 'internal/typeutils')
| -rw-r--r-- | internal/typeutils/frontendtointernal.go | 10 | ||||
| -rw-r--r-- | internal/typeutils/internaltofrontend.go | 12 | ||||
| -rw-r--r-- | internal/typeutils/internaltofrontend_test.go | 10 |
3 files changed, 32 insertions, 0 deletions
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": [ |
