mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-23 01:46:16 -06:00
Write status content type on create/edit
This commit is contained in:
parent
49e649068c
commit
e51a787162
4 changed files with 57 additions and 11 deletions
|
|
@ -110,7 +110,7 @@ func (p *Processor) processContent(
|
|||
ctx context.Context,
|
||||
author *gtsmodel.Account,
|
||||
statusID string,
|
||||
contentType string,
|
||||
contentType apimodel.StatusContentType,
|
||||
content string,
|
||||
contentWarning string,
|
||||
language string,
|
||||
|
|
@ -146,20 +146,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 apimodel.StatusContentTypePlain:
|
||||
format = p.formatter.FromPlain
|
||||
|
||||
// Format status according to text/markdown.
|
||||
case string(apimodel.StatusContentTypeMarkdown):
|
||||
case apimodel.StatusContentTypeMarkdown:
|
||||
format = p.formatter.FromMarkdown
|
||||
|
||||
// Unknown.
|
||||
|
|
|
|||
|
|
@ -66,11 +66,22 @@ 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 status content fields.
|
||||
content, errWithCode := p.processContent(ctx,
|
||||
requester,
|
||||
statusID,
|
||||
string(form.ContentType),
|
||||
contentType,
|
||||
form.Status,
|
||||
form.SpoilerText,
|
||||
form.Language,
|
||||
|
|
@ -159,6 +170,9 @@ func (p *Processor) Create(
|
|||
// Set validated language.
|
||||
Language: content.Language,
|
||||
|
||||
// Set resolved content type.
|
||||
ContentType: typeutils.APIContentTypeToContentType(contentType),
|
||||
|
||||
// Set formatted status content.
|
||||
Content: content.Content,
|
||||
ContentWarning: content.ContentWarning,
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ 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"
|
||||
)
|
||||
|
||||
|
|
@ -84,11 +85,14 @@ func (p *Processor) Edit(
|
|||
return nil, errWithCode
|
||||
}
|
||||
|
||||
// Process incoming content type and update as needed
|
||||
p.processContentType(ctx, form, status, requester.Settings.StatusContentType)
|
||||
|
||||
// Process incoming status edit content fields.
|
||||
content, errWithCode := p.processContent(ctx,
|
||||
requester,
|
||||
statusID,
|
||||
string(form.ContentType),
|
||||
form.ContentType,
|
||||
form.Status,
|
||||
form.SpoilerText,
|
||||
form.Language,
|
||||
|
|
@ -256,6 +260,7 @@ func (p *Processor) Edit(
|
|||
edit.Content = status.Content
|
||||
edit.ContentWarning = status.ContentWarning
|
||||
edit.Text = status.Text
|
||||
edit.ContentType = status.ContentType
|
||||
edit.Language = status.Language
|
||||
edit.Sensitive = status.Sensitive
|
||||
edit.StatusID = status.ID
|
||||
|
|
@ -342,6 +347,38 @@ func (p *Processor) Edit(
|
|||
return p.c.GetAPIStatus(ctx, requester, status)
|
||||
}
|
||||
|
||||
// Updates the content type of the status
|
||||
func (p *Processor) processContentType(
|
||||
ctx context.Context,
|
||||
form *apimodel.StatusEditRequest,
|
||||
status *gtsmodel.Status,
|
||||
accountDefaultContentType string,
|
||||
) {
|
||||
switch {
|
||||
// Content type set on form, update the status with the new value.
|
||||
case form.ContentType != "":
|
||||
status.ContentType = typeutils.APIContentTypeToContentType(form.ContentType)
|
||||
|
||||
// No content type on the form, get the status's current content type and
|
||||
// set it back on the form for later use.
|
||||
case status.ContentType != 0:
|
||||
form.ContentType = p.converter.ContentTypeToAPIContentType(ctx, status.ContentType)
|
||||
|
||||
// Old statuses may not have a saved content type; update the status to the
|
||||
// user's preference and set this back on the form for later use.
|
||||
case accountDefaultContentType != "":
|
||||
// TODO: is this conversion from string to StatusContentType safe
|
||||
status.ContentType = typeutils.APIContentTypeToContentType(apimodel.StatusContentType(accountDefaultContentType))
|
||||
form.ContentType = apimodel.StatusContentType(accountDefaultContentType)
|
||||
|
||||
// uhh.. Fall back to global default, set
|
||||
// this back on the form for later use.
|
||||
default:
|
||||
status.ContentType = gtsmodel.StatusContentTypeDefault
|
||||
form.ContentType = apimodel.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,
|
||||
|
|
|
|||
|
|
@ -56,5 +56,6 @@ func (p *Processor) SourceGet(ctx context.Context, requester *gtsmodel.Account,
|
|||
ID: status.ID,
|
||||
Text: status.Text,
|
||||
SpoilerText: status.ContentWarning,
|
||||
ContentType: p.converter.ContentTypeToAPIContentType(ctx, status.ContentType),
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue