diff options
author | 2023-02-07 08:58:36 +0000 | |
---|---|---|
committer | 2023-02-07 09:58:36 +0100 | |
commit | ad6ab037e45264e4100f70675da1d12bbc3d555d (patch) | |
tree | 5c3eb5fd99f7ff38d5a781a07d2a637b12af0a29 /internal/processing/account/update.go | |
parent | [bugfix] fix file range length calculation being off by 1 (#1448) (diff) | |
download | gotosocial-ad6ab037e45264e4100f70675da1d12bbc3d555d.tar.xz |
[bugfix] don't trash emoji in profile fields on edit (#1440)
Diffstat (limited to 'internal/processing/account/update.go')
-rw-r--r-- | internal/processing/account/update.go | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go index c7939034e..370e661ed 100644 --- a/internal/processing/account/update.go +++ b/internal/processing/account/update.go @@ -53,12 +53,15 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form return nil, gtserror.NewErrorBadRequest(err) } account.DisplayName = text.SanitizePlaintext(*form.DisplayName) + } - formatResult := p.formatter.FromPlainEmojiOnly(ctx, p.parseMention, account.ID, "", account.DisplayName) - for _, emoji := range formatResult.Emojis { - account.Emojis = append(account.Emojis, emoji) - account.EmojiIDs = append(account.EmojiIDs, emoji.ID) - } + // Re-parse for emojis regardless of whether the DisplayName changed + // because we can't otherwise tell which emojis belong to DisplayName + // and which belong to Note + formatResult := p.formatter.FromPlainEmojiOnly(ctx, p.parseMention, account.ID, "", account.DisplayName) + for _, emoji := range formatResult.Emojis { + account.Emojis = append(account.Emojis, emoji) + account.EmojiIDs = append(account.EmojiIDs, emoji.ID) } if form.Note != nil { @@ -68,22 +71,23 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form // Set the raw note before processing account.NoteRaw = *form.Note + } - // Process note to generate a valid HTML representation - var f text.FormatFunc - if account.StatusFormat == "markdown" { - f = p.formatter.FromMarkdown - } else { - f = p.formatter.FromPlain - } - formatted := f(ctx, p.parseMention, account.ID, "", *form.Note) + // As per DisplayName, we need to reparse regardless to keep emojis straight + // Process note to generate a valid HTML representation + var f text.FormatFunc + if account.StatusFormat == "markdown" { + f = p.formatter.FromMarkdown + } else { + f = p.formatter.FromPlain + } + formatted := f(ctx, p.parseMention, account.ID, "", account.NoteRaw) - // Set updated HTML-ified note - account.Note = formatted.HTML - for _, emoji := range formatted.Emojis { - account.Emojis = append(account.Emojis, emoji) - account.EmojiIDs = append(account.EmojiIDs, emoji.ID) - } + // Set updated HTML-ified note + account.Note = formatted.HTML + for _, emoji := range formatted.Emojis { + account.Emojis = append(account.Emojis, emoji) + account.EmojiIDs = append(account.EmojiIDs, emoji.ID) } if form.Avatar != nil && form.Avatar.Size != 0 { |