Fix for extra newline in emotes (#2778)

This commit is contained in:
Mauro 2024-05-03 20:44:57 +02:00 committed by GitHub
parent e9d690450e
commit 7d06b471ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -570,7 +570,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
var formattedBody: AttributedString?
if let htmlBody {
formattedBody = attributedStringBuilder.fromHTML(L10n.commonEmote(name, htmlBody))
formattedBody = buildEmoteFormattedBodyFromHTML(html: htmlBody, name: name)
} else {
formattedBody = attributedStringBuilder.fromPlain(L10n.commonEmote(name, messageContent.body))
}
@ -578,6 +578,17 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
return .init(body: messageContent.body, formattedBody: formattedBody, formattedBodyHTMLString: htmlBody)
}
// This fixes the issue of the name not belonging to the first <p> defined paragraph
private func buildEmoteFormattedBodyFromHTML(html: String, name: String) -> AttributedString? {
let htmlBodyPlaceholder = "{htmlBodyPlaceholder}"
var finalString = AttributedString(L10n.commonEmote(name, htmlBodyPlaceholder))
guard let htmlBodyString = attributedStringBuilder.fromHTML(html) else {
return nil
}
finalString.replace(htmlBodyPlaceholder, with: htmlBodyString)
return finalString
}
// MARK: - State Events
private func buildStateTimelineItem(for eventItemProxy: EventTimelineItemProxy,

1
changelog.d/2503.bugfix Normal file
View File

@ -0,0 +1 @@
Fixed a bug that added an extra newline between the name and a formatted text in an emote.