mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-23 10:16:14 -06:00
Move processContentType to common.go and use for creation as well
This commit is contained in:
parent
3050c2930a
commit
d83cf7ed9b
3 changed files with 34 additions and 42 deletions
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/text"
|
"github.com/superseriousbusiness/gotosocial/internal/text"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/validate"
|
"github.com/superseriousbusiness/gotosocial/internal/validate"
|
||||||
)
|
)
|
||||||
|
|
@ -106,6 +107,34 @@ type statusContent struct {
|
||||||
Tags []*gtsmodel.Tag
|
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(
|
func (p *Processor) processContent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
author *gtsmodel.Account,
|
author *gtsmodel.Account,
|
||||||
|
|
|
||||||
|
|
@ -66,22 +66,14 @@ func (p *Processor) Create(
|
||||||
// Generate new ID for status.
|
// Generate new ID for status.
|
||||||
statusID := id.NewULID()
|
statusID := id.NewULID()
|
||||||
|
|
||||||
// Process incoming content type
|
// Process incoming content type.
|
||||||
contentType := form.ContentType
|
contentType := processContentType(form.ContentType, nil, requester.Settings.StatusContentType)
|
||||||
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 status content fields.
|
// Process incoming status content fields.
|
||||||
content, errWithCode := p.processContent(ctx,
|
content, errWithCode := p.processContent(ctx,
|
||||||
requester,
|
requester,
|
||||||
statusID,
|
statusID,
|
||||||
typeutils.APIContentTypeToContentType(contentType),
|
contentType,
|
||||||
form.Status,
|
form.Status,
|
||||||
form.SpoilerText,
|
form.SpoilerText,
|
||||||
form.Language,
|
form.Language,
|
||||||
|
|
@ -174,7 +166,7 @@ func (p *Processor) Create(
|
||||||
Content: content.Content,
|
Content: content.Content,
|
||||||
ContentWarning: content.ContentWarning,
|
ContentWarning: content.ContentWarning,
|
||||||
Text: form.Status, // raw
|
Text: form.Status, // raw
|
||||||
ContentType: typeutils.APIContentTypeToContentType(contentType),
|
ContentType: contentType,
|
||||||
|
|
||||||
// Set gathered mentions.
|
// Set gathered mentions.
|
||||||
MentionIDs: content.MentionIDs,
|
MentionIDs: content.MentionIDs,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
"github.com/superseriousbusiness/gotosocial/internal/util/xslices"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -85,7 +84,7 @@ func (p *Processor) Edit(
|
||||||
return nil, errWithCode
|
return nil, errWithCode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process incoming content type
|
// Process incoming content type.
|
||||||
contentType := processContentType(form.ContentType, status, requester.Settings.StatusContentType)
|
contentType := processContentType(form.ContentType, status, requester.Settings.StatusContentType)
|
||||||
|
|
||||||
// Process incoming status edit content fields.
|
// Process incoming status edit content fields.
|
||||||
|
|
@ -348,34 +347,6 @@ func (p *Processor) Edit(
|
||||||
return p.c.GetAPIStatus(ctx, requester, status)
|
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.
|
// 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) {
|
func (p *Processor) HistoryGet(ctx context.Context, requester *gtsmodel.Account, targetStatusID string) ([]*apimodel.StatusEdit, gtserror.WithCode) {
|
||||||
target, errWithCode := p.c.GetVisibleTargetStatus(ctx,
|
target, errWithCode := p.c.GetVisibleTargetStatus(ctx,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue