From 921ba6481bc46e7a9c726bcd3e2797811cee93fd Mon Sep 17 00:00:00 2001 From: ewin Date: Wed, 5 Mar 2025 13:19:39 -0500 Subject: [PATCH] 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 --- internal/processing/status/common.go | 6 ++--- internal/processing/status/create.go | 2 +- internal/processing/status/edit.go | 34 ++++++++++++---------------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/internal/processing/status/common.go b/internal/processing/status/common.go index aaf310c2c..88d950584 100644 --- a/internal/processing/status/common.go +++ b/internal/processing/status/common.go @@ -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. diff --git a/internal/processing/status/create.go b/internal/processing/status/create.go index c2c2da675..60b320e1c 100644 --- a/internal/processing/status/create.go +++ b/internal/processing/status/create.go @@ -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, diff --git a/internal/processing/status/edit.go b/internal/processing/status/edit.go index 710a5b726..abc0dbfc1 100644 --- a/internal/processing/status/edit.go +++ b/internal/processing/status/edit.go @@ -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 } }