diff options
| author | 2025-03-07 15:04:34 +0100 | |
|---|---|---|
| committer | 2025-03-07 14:04:34 +0000 | |
| commit | d8113c11e4d84a6d04d56b58d337c235154a535b (patch) | |
| tree | 3ed983cbb8f95c9ef51a02a51a50ab89c42abd14 /internal/typeutils/internaltofrontend.go | |
| parent | [bugfix] Store and expose status content type (#3870) (diff) | |
| download | gotosocial-d8113c11e4d84a6d04d56b58d337c235154a535b.tar.xz | |
[feature] Parse content warning to HTML, serialize via client API as plaintext (#3876)
* [feature] Parse content warning as HTML, serialize via API to plaintext
* tidy up some cruft
* whoops
* oops
* i'm da joker baybee
* clemency muy lorde
* rename some of the text functions for clarity
* jiggle the opts
* fiddle de deee
* hopefully the last test fix i ever have to do in my beautiful life
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
| -rw-r--r-- | internal/typeutils/internaltofrontend.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 3c5bd5ca0..537eeb6db 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -40,6 +40,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/language" "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/media" + "github.com/superseriousbusiness/gotosocial/internal/text" "github.com/superseriousbusiness/gotosocial/internal/uris" "github.com/superseriousbusiness/gotosocial/internal/util" ) @@ -1125,13 +1126,16 @@ func (c *Converter) StatusToWebStatus( } webStatus := &apimodel.WebStatus{ - Status: apiStatus, - Account: acct, + Status: apiStatus, + SpoilerContent: s.ContentWarning, + Account: acct, } // Whack a newline before and after each "pre" to make it easier to outdent it. webStatus.Content = strings.ReplaceAll(webStatus.Content, "<pre>", "\n<pre>") webStatus.Content = strings.ReplaceAll(webStatus.Content, "</pre>", "</pre>\n") + webStatus.SpoilerContent = strings.ReplaceAll(webStatus.SpoilerContent, "<pre>", "\n<pre>") + webStatus.SpoilerContent = strings.ReplaceAll(webStatus.SpoilerContent, "</pre>", "</pre>\n") // Add additional information for template. // Assume empty langs, hope for not empty language. @@ -1372,7 +1376,6 @@ func (c *Converter) baseStatusToFrontend( InReplyToID: nil, // Set below. InReplyToAccountID: nil, // Set below. Sensitive: *s.Sensitive, - SpoilerText: s.ContentWarning, Visibility: c.VisToAPIVis(ctx, s.Visibility), LocalOnly: s.IsLocalOnly(), Language: nil, // Set below. @@ -1393,6 +1396,11 @@ func (c *Converter) baseStatusToFrontend( Text: s.Text, ContentType: ContentTypeToAPIContentType(s.ContentType), InteractionPolicy: *apiInteractionPolicy, + + // Mastodon API says spoiler_text should be *text*, not HTML, so + // parse any HTML back to plaintext when serializing via the API, + // attempting to preserve semantic intent to keep it readable. + SpoilerText: text.ParseHTMLToPlain(s.ContentWarning), } if at := s.EditedAt; !at.IsZero() { |
