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:
ewin 2025-03-05 13:19:39 -05:00
commit 921ba6481b
No known key found for this signature in database
3 changed files with 19 additions and 23 deletions

View file

@ -110,7 +110,7 @@ func (p *Processor) processContent(
ctx context.Context,
author *gtsmodel.Account,
statusID string,
contentType apimodel.StatusContentType,
contentType gtsmodel.StatusContentType,
content string,
contentWarning string,
language string,
@ -149,11 +149,11 @@ func (p *Processor) processContent(
switch contentType {
// Format status according to text/plain.
case apimodel.StatusContentTypePlain:
case gtsmodel.StatusContentTypePlain:
format = p.formatter.FromPlain
// Format status according to text/markdown.
case apimodel.StatusContentTypeMarkdown:
case gtsmodel.StatusContentTypeMarkdown:
format = p.formatter.FromMarkdown
// Unknown.

View file

@ -81,7 +81,7 @@ func (p *Processor) Create(
content, errWithCode := p.processContent(ctx,
requester,
statusID,
contentType,
typeutils.APIContentTypeToContentType(contentType),
form.Status,
form.SpoilerText,
form.Language,

View file

@ -85,14 +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 content type
contentType := p.processContentType(ctx, form, status, requester.Settings.StatusContentType)
// Process incoming status edit content fields.
content, errWithCode := p.processContent(ctx,
requester,
statusID,
form.ContentType,
contentType,
form.Status,
form.SpoilerText,
form.Language,
@ -303,7 +303,7 @@ func (p *Processor) Edit(
status.Content = content.Content
status.ContentWarning = content.ContentWarning
status.Text = form.Status
status.ContentType = typeutils.APIContentTypeToContentType(form.ContentType)
status.ContentType = contentType
status.Language = content.Language
status.Sensitive = &form.Sensitive
status.AttachmentIDs = form.MediaIDs
@ -348,34 +348,30 @@ func (p *Processor) Edit(
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(
ctx context.Context,
form *apimodel.StatusEditRequest,
status *gtsmodel.Status,
accountDefaultContentType string,
) {
) gtsmodel.StatusContentType {
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 != "":
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
// set it back on the form for later use.
// No content type on the form, return the status's current content type.
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
// user's preference and set this back on the form for later use.
// Old statuses may not have a saved content type;
// return the user's default content type preference.
case accountDefaultContentType != "":
status.ContentType = typeutils.APIContentTypeToContentType(apimodel.StatusContentType(accountDefaultContentType))
form.ContentType = apimodel.StatusContentType(accountDefaultContentType)
return typeutils.APIContentTypeToContentType(apimodel.StatusContentType(accountDefaultContentType))
// uhh.. Fall back to global default, set
// this back on the form for later use.
// uhh.. Fall back to global default.
default:
status.ContentType = gtsmodel.StatusContentTypeDefault
form.ContentType = apimodel.StatusContentTypeDefault
return gtsmodel.StatusContentTypeDefault
}
}