mirror of
1
Fork 0

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

This commit is contained in:
Sam Lade 2023-02-07 08:58:36 +00:00 committed by GitHub
parent ac2bdbbc62
commit ad6ab037e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 19 deletions

View File

@ -53,13 +53,16 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
return nil, gtserror.NewErrorBadRequest(err) return nil, gtserror.NewErrorBadRequest(err)
} }
account.DisplayName = text.SanitizePlaintext(*form.DisplayName) account.DisplayName = text.SanitizePlaintext(*form.DisplayName)
}
// 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) formatResult := p.formatter.FromPlainEmojiOnly(ctx, p.parseMention, account.ID, "", account.DisplayName)
for _, emoji := range formatResult.Emojis { for _, emoji := range formatResult.Emojis {
account.Emojis = append(account.Emojis, emoji) account.Emojis = append(account.Emojis, emoji)
account.EmojiIDs = append(account.EmojiIDs, emoji.ID) account.EmojiIDs = append(account.EmojiIDs, emoji.ID)
} }
}
if form.Note != nil { if form.Note != nil {
if err := validate.Note(*form.Note); err != nil { if err := validate.Note(*form.Note); err != nil {
@ -68,7 +71,9 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
// Set the raw note before processing // Set the raw note before processing
account.NoteRaw = *form.Note account.NoteRaw = *form.Note
}
// As per DisplayName, we need to reparse regardless to keep emojis straight
// Process note to generate a valid HTML representation // Process note to generate a valid HTML representation
var f text.FormatFunc var f text.FormatFunc
if account.StatusFormat == "markdown" { if account.StatusFormat == "markdown" {
@ -76,7 +81,7 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
} else { } else {
f = p.formatter.FromPlain f = p.formatter.FromPlain
} }
formatted := f(ctx, p.parseMention, account.ID, "", *form.Note) formatted := f(ctx, p.parseMention, account.ID, "", account.NoteRaw)
// Set updated HTML-ified note // Set updated HTML-ified note
account.Note = formatted.HTML account.Note = formatted.HTML
@ -84,7 +89,6 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, form
account.Emojis = append(account.Emojis, emoji) account.Emojis = append(account.Emojis, emoji)
account.EmojiIDs = append(account.EmojiIDs, emoji.ID) account.EmojiIDs = append(account.EmojiIDs, emoji.ID)
} }
}
if form.Avatar != nil && form.Avatar.Size != 0 { if form.Avatar != nil && form.Avatar.Size != 0 {
avatarInfo, err := p.UpdateAvatar(ctx, form.Avatar, nil, account.ID) avatarInfo, err := p.UpdateAvatar(ctx, form.Avatar, nil, account.ID)