mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-23 10:16:14 -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,
|
ctx context.Context,
|
||||||
author *gtsmodel.Account,
|
author *gtsmodel.Account,
|
||||||
statusID string,
|
statusID string,
|
||||||
contentType string,
|
contentType apimodel.StatusContentType,
|
||||||
content string,
|
content string,
|
||||||
contentWarning string,
|
contentWarning string,
|
||||||
language string,
|
language string,
|
||||||
|
|
@ -146,20 +146,14 @@ func (p *Processor) processContent(
|
||||||
// function, according to the provided content-type.
|
// function, according to the provided content-type.
|
||||||
var format text.FormatFunc
|
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 {
|
switch contentType {
|
||||||
|
|
||||||
// Format status according to text/plain.
|
// Format status according to text/plain.
|
||||||
case "", string(apimodel.StatusContentTypePlain):
|
case apimodel.StatusContentTypePlain:
|
||||||
format = p.formatter.FromPlain
|
format = p.formatter.FromPlain
|
||||||
|
|
||||||
// Format status according to text/markdown.
|
// Format status according to text/markdown.
|
||||||
case string(apimodel.StatusContentTypeMarkdown):
|
case apimodel.StatusContentTypeMarkdown:
|
||||||
format = p.formatter.FromMarkdown
|
format = p.formatter.FromMarkdown
|
||||||
|
|
||||||
// Unknown.
|
// Unknown.
|
||||||
|
|
|
||||||
|
|
@ -66,11 +66,22 @@ func (p *Processor) Create(
|
||||||
// Generate new ID for status.
|
// Generate new ID for status.
|
||||||
statusID := id.NewULID()
|
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.
|
// Process incoming status content fields.
|
||||||
content, errWithCode := p.processContent(ctx,
|
content, errWithCode := p.processContent(ctx,
|
||||||
requester,
|
requester,
|
||||||
statusID,
|
statusID,
|
||||||
string(form.ContentType),
|
contentType,
|
||||||
form.Status,
|
form.Status,
|
||||||
form.SpoilerText,
|
form.SpoilerText,
|
||||||
form.Language,
|
form.Language,
|
||||||
|
|
@ -159,6 +170,9 @@ func (p *Processor) Create(
|
||||||
// Set validated language.
|
// Set validated language.
|
||||||
Language: content.Language,
|
Language: content.Language,
|
||||||
|
|
||||||
|
// Set resolved content type.
|
||||||
|
ContentType: typeutils.APIContentTypeToContentType(contentType),
|
||||||
|
|
||||||
// Set formatted status content.
|
// Set formatted status content.
|
||||||
Content: content.Content,
|
Content: content.Content,
|
||||||
ContentWarning: content.ContentWarning,
|
ContentWarning: content.ContentWarning,
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -84,11 +85,14 @@ func (p *Processor) Edit(
|
||||||
return nil, errWithCode
|
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.
|
// Process incoming status edit content fields.
|
||||||
content, errWithCode := p.processContent(ctx,
|
content, errWithCode := p.processContent(ctx,
|
||||||
requester,
|
requester,
|
||||||
statusID,
|
statusID,
|
||||||
string(form.ContentType),
|
form.ContentType,
|
||||||
form.Status,
|
form.Status,
|
||||||
form.SpoilerText,
|
form.SpoilerText,
|
||||||
form.Language,
|
form.Language,
|
||||||
|
|
@ -256,6 +260,7 @@ func (p *Processor) Edit(
|
||||||
edit.Content = status.Content
|
edit.Content = status.Content
|
||||||
edit.ContentWarning = status.ContentWarning
|
edit.ContentWarning = status.ContentWarning
|
||||||
edit.Text = status.Text
|
edit.Text = status.Text
|
||||||
|
edit.ContentType = status.ContentType
|
||||||
edit.Language = status.Language
|
edit.Language = status.Language
|
||||||
edit.Sensitive = status.Sensitive
|
edit.Sensitive = status.Sensitive
|
||||||
edit.StatusID = status.ID
|
edit.StatusID = status.ID
|
||||||
|
|
@ -342,6 +347,38 @@ func (p *Processor) Edit(
|
||||||
return p.c.GetAPIStatus(ctx, requester, status)
|
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.
|
// 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,
|
||||||
|
|
|
||||||
|
|
@ -56,5 +56,6 @@ func (p *Processor) SourceGet(ctx context.Context, requester *gtsmodel.Account,
|
||||||
ID: status.ID,
|
ID: status.ID,
|
||||||
Text: status.Text,
|
Text: status.Text,
|
||||||
SpoilerText: status.ContentWarning,
|
SpoilerText: status.ContentWarning,
|
||||||
|
ContentType: p.converter.ContentTypeToAPIContentType(ctx, status.ContentType),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue