diff --git a/internal/processing/status/common.go b/internal/processing/status/common.go index 88d950584..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,6 +107,34 @@ 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, diff --git a/internal/processing/status/create.go b/internal/processing/status/create.go index 60b320e1c..73ac8d677 100644 --- a/internal/processing/status/create.go +++ b/internal/processing/status/create.go @@ -66,22 +66,14 @@ func (p *Processor) Create( // Generate new ID for status. statusID := id.NewULID() - // Process incoming content type - contentType := form.ContentType - if contentType == "" { - // If not set in the form, use the user's default - contentType = apimodel.StatusContentType(requester.Settings.StatusContentType) - if contentType == "" { - // ??? use the global default value - contentType = apimodel.StatusContentTypeDefault - } - } + // Process incoming content type. + contentType := processContentType(form.ContentType, nil, requester.Settings.StatusContentType) // Process incoming status content fields. content, errWithCode := p.processContent(ctx, requester, statusID, - typeutils.APIContentTypeToContentType(contentType), + contentType, form.Status, form.SpoilerText, form.Language, @@ -174,7 +166,7 @@ func (p *Processor) Create( Content: content.Content, ContentWarning: content.ContentWarning, Text: form.Status, // raw - ContentType: typeutils.APIContentTypeToContentType(contentType), + ContentType: contentType, // Set gathered mentions. MentionIDs: content.MentionIDs, diff --git a/internal/processing/status/edit.go b/internal/processing/status/edit.go index 8327d538e..590fe565a 100644 --- a/internal/processing/status/edit.go +++ b/internal/processing/status/edit.go @@ -33,7 +33,6 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/id" "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/messages" - "github.com/superseriousbusiness/gotosocial/internal/typeutils" "github.com/superseriousbusiness/gotosocial/internal/util/xslices" ) @@ -85,7 +84,7 @@ func (p *Processor) Edit( return nil, errWithCode } - // Process incoming content type + // Process incoming content type. contentType := processContentType(form.ContentType, status, requester.Settings.StatusContentType) // Process incoming status edit content fields. @@ -348,34 +347,6 @@ func (p *Processor) Edit( return p.c.GetAPIStatus(ctx, requester, status) } -// 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 - } -} - // HistoryGet gets edit history for the target status, taking account of privacy settings and blocks etc. func (p *Processor) HistoryGet(ctx context.Context, requester *gtsmodel.Account, targetStatusID string) ([]*apimodel.StatusEdit, gtserror.WithCode) { target, errWithCode := p.c.GetVisibleTargetStatus(ctx,