summaryrefslogtreecommitdiff
path: root/internal/processing/status/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing/status/common.go')
-rw-r--r--internal/processing/status/common.go41
1 files changed, 32 insertions, 9 deletions
diff --git a/internal/processing/status/common.go b/internal/processing/status/common.go
index 3f2b7b6cb..6a4851f51 100644
--- a/internal/processing/status/common.go
+++ b/internal/processing/status/common.go
@@ -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,
@@ -146,20 +175,14 @@ func (p *Processor) processContent(
// function, according to the provided content-type.
var format 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
// Format status according to text/markdown.
- case string(apimodel.StatusContentTypeMarkdown):
+ case gtsmodel.StatusContentTypeMarkdown:
format = p.formatter.FromMarkdown
// Unknown.