mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-23 01:46:16 -06:00
Return a value from processContentType instead of modifying the existing status
Fixes an issue that was caught by the test I just added - the recorded edit would be marked with the *new* content type instead of the old one, which is obviously bad
This commit is contained in:
parent
8634358278
commit
921ba6481b
3 changed files with 19 additions and 23 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 apimodel.StatusContentType,
|
contentType gtsmodel.StatusContentType,
|
||||||
content string,
|
content string,
|
||||||
contentWarning string,
|
contentWarning string,
|
||||||
language string,
|
language string,
|
||||||
|
|
@ -149,11 +149,11 @@ func (p *Processor) processContent(
|
||||||
switch contentType {
|
switch contentType {
|
||||||
|
|
||||||
// Format status according to text/plain.
|
// Format status according to text/plain.
|
||||||
case apimodel.StatusContentTypePlain:
|
case gtsmodel.StatusContentTypePlain:
|
||||||
format = p.formatter.FromPlain
|
format = p.formatter.FromPlain
|
||||||
|
|
||||||
// Format status according to text/markdown.
|
// Format status according to text/markdown.
|
||||||
case apimodel.StatusContentTypeMarkdown:
|
case gtsmodel.StatusContentTypeMarkdown:
|
||||||
format = p.formatter.FromMarkdown
|
format = p.formatter.FromMarkdown
|
||||||
|
|
||||||
// Unknown.
|
// Unknown.
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ func (p *Processor) Create(
|
||||||
content, errWithCode := p.processContent(ctx,
|
content, errWithCode := p.processContent(ctx,
|
||||||
requester,
|
requester,
|
||||||
statusID,
|
statusID,
|
||||||
contentType,
|
typeutils.APIContentTypeToContentType(contentType),
|
||||||
form.Status,
|
form.Status,
|
||||||
form.SpoilerText,
|
form.SpoilerText,
|
||||||
form.Language,
|
form.Language,
|
||||||
|
|
|
||||||
|
|
@ -85,14 +85,14 @@ func (p *Processor) Edit(
|
||||||
return nil, errWithCode
|
return nil, errWithCode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process incoming content type and update as needed
|
// Process incoming content type
|
||||||
p.processContentType(ctx, form, status, requester.Settings.StatusContentType)
|
contentType := 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,
|
||||||
form.ContentType,
|
contentType,
|
||||||
form.Status,
|
form.Status,
|
||||||
form.SpoilerText,
|
form.SpoilerText,
|
||||||
form.Language,
|
form.Language,
|
||||||
|
|
@ -303,7 +303,7 @@ func (p *Processor) Edit(
|
||||||
status.Content = content.Content
|
status.Content = content.Content
|
||||||
status.ContentWarning = content.ContentWarning
|
status.ContentWarning = content.ContentWarning
|
||||||
status.Text = form.Status
|
status.Text = form.Status
|
||||||
status.ContentType = typeutils.APIContentTypeToContentType(form.ContentType)
|
status.ContentType = contentType
|
||||||
status.Language = content.Language
|
status.Language = content.Language
|
||||||
status.Sensitive = &form.Sensitive
|
status.Sensitive = &form.Sensitive
|
||||||
status.AttachmentIDs = form.MediaIDs
|
status.AttachmentIDs = form.MediaIDs
|
||||||
|
|
@ -348,34 +348,30 @@ 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
|
// Returns the new content type of the status when applying an edit.
|
||||||
func (p *Processor) processContentType(
|
func (p *Processor) processContentType(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
form *apimodel.StatusEditRequest,
|
form *apimodel.StatusEditRequest,
|
||||||
status *gtsmodel.Status,
|
status *gtsmodel.Status,
|
||||||
accountDefaultContentType string,
|
accountDefaultContentType string,
|
||||||
) {
|
) gtsmodel.StatusContentType {
|
||||||
switch {
|
switch {
|
||||||
// Content type set on form, update the status with the new value.
|
// Content type set on form, return the new value.
|
||||||
case form.ContentType != "":
|
case form.ContentType != "":
|
||||||
status.ContentType = typeutils.APIContentTypeToContentType(form.ContentType)
|
return typeutils.APIContentTypeToContentType(form.ContentType)
|
||||||
|
|
||||||
// No content type on the form, get the status's current content type and
|
// No content type on the form, return the status's current content type.
|
||||||
// set it back on the form for later use.
|
|
||||||
case status.ContentType != 0:
|
case status.ContentType != 0:
|
||||||
form.ContentType = p.converter.ContentTypeToAPIContentType(ctx, status.ContentType)
|
return status.ContentType
|
||||||
|
|
||||||
// Old statuses may not have a saved content type; update the status to the
|
// Old statuses may not have a saved content type;
|
||||||
// user's preference and set this back on the form for later use.
|
// return the user's default content type preference.
|
||||||
case accountDefaultContentType != "":
|
case accountDefaultContentType != "":
|
||||||
status.ContentType = typeutils.APIContentTypeToContentType(apimodel.StatusContentType(accountDefaultContentType))
|
return typeutils.APIContentTypeToContentType(apimodel.StatusContentType(accountDefaultContentType))
|
||||||
form.ContentType = apimodel.StatusContentType(accountDefaultContentType)
|
|
||||||
|
|
||||||
// uhh.. Fall back to global default, set
|
// uhh.. Fall back to global default.
|
||||||
// this back on the form for later use.
|
|
||||||
default:
|
default:
|
||||||
status.ContentType = gtsmodel.StatusContentTypeDefault
|
return gtsmodel.StatusContentTypeDefault
|
||||||
form.ContentType = apimodel.StatusContentTypeDefault
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue