From 7d06b471ec33304b1db6ea93b74bc525d2ab086c Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Fri, 3 May 2024 20:44:57 +0200 Subject: [PATCH] Fix for extra newline in emotes (#2778) --- .../TimelineItems/RoomTimelineItemFactory.swift | 13 ++++++++++++- changelog.d/2503.bugfix | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelog.d/2503.bugfix diff --git a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift index 43dcf36f7..5b6d2fd27 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift @@ -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
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, diff --git a/changelog.d/2503.bugfix b/changelog.d/2503.bugfix new file mode 100644 index 000000000..aad6a6b2c --- /dev/null +++ b/changelog.d/2503.bugfix @@ -0,0 +1 @@ +Fixed a bug that added an extra newline between the name and a formatted text in an emote. \ No newline at end of file