mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-10 20:57:31 -06:00
Merge branch 'main' into content_warning_fixes
This commit is contained in:
commit
aa5713fc38
26 changed files with 572 additions and 26 deletions
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/text"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/validate"
|
||||
)
|
||||
|
|
@ -106,11 +107,39 @@ type statusContent struct {
|
|||
Tags []*gtsmodel.Tag
|
||||
}
|
||||
|
||||
// Returns the final content type to use when creating or editing a status.
|
||||
func processContentType(
|
||||
requestContentType apimodel.StatusContentType,
|
||||
existingStatus *gtsmodel.Status,
|
||||
accountDefaultContentType string,
|
||||
) gtsmodel.StatusContentType {
|
||||
switch {
|
||||
// Content type set in the request, return the new value.
|
||||
case requestContentType != "":
|
||||
return typeutils.APIContentTypeToContentType(requestContentType)
|
||||
|
||||
// No content type in the request, return the existing
|
||||
// status's current content type if we know of one.
|
||||
case existingStatus != nil && existingStatus.ContentType != 0:
|
||||
return existingStatus.ContentType
|
||||
|
||||
// We aren't editing an existing status, or if we are
|
||||
// it's an old one that doesn't have a saved content
|
||||
// type. Use the user's default content type setting.
|
||||
case accountDefaultContentType != "":
|
||||
return typeutils.APIContentTypeToContentType(apimodel.StatusContentType(accountDefaultContentType))
|
||||
|
||||
// uhh.. Fall back to global default.
|
||||
default:
|
||||
return gtsmodel.StatusContentTypeDefault
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Processor) processContent(
|
||||
ctx context.Context,
|
||||
author *gtsmodel.Account,
|
||||
statusID string,
|
||||
contentType string,
|
||||
contentType gtsmodel.StatusContentType,
|
||||
content string,
|
||||
contentWarning string,
|
||||
language string,
|
||||
|
|
@ -150,21 +179,15 @@ func (p *Processor) processContent(
|
|||
formatCW text.FormatFunc
|
||||
)
|
||||
|
||||
if contentType == "" {
|
||||
// If content type wasn't specified, use
|
||||
// the author's preferred content-type.
|
||||
contentType = author.Settings.StatusContentType
|
||||
}
|
||||
|
||||
switch contentType {
|
||||
|
||||
// Format status according to text/plain.
|
||||
case "", string(apimodel.StatusContentTypePlain):
|
||||
case gtsmodel.StatusContentTypePlain:
|
||||
format = p.formatter.FromPlain
|
||||
formatCW = p.formatter.FromPlainBasic
|
||||
|
||||
// Format status according to text/markdown.
|
||||
case string(apimodel.StatusContentTypeMarkdown):
|
||||
case gtsmodel.StatusContentTypeMarkdown:
|
||||
format = p.formatter.FromMarkdown
|
||||
formatCW = p.formatter.FromMarkdownBasic
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue