Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] don't trash emoji in profile fields on edit #1440

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions internal/processing/account/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down