Extract reply formatting

This commit is contained in:
David Langley 2021-12-16 12:47:06 +00:00
parent 13dc2d5b76
commit a3a8a5b0b5

View file

@ -208,12 +208,11 @@ internal class LocalEchoEventFactory @Inject constructor(
val newBodyFormatted = markdownParser.parse(newBodyText, force = true, advanced = false).takeFormatted() val newBodyFormatted = markdownParser.parse(newBodyText, force = true, advanced = false).takeFormatted()
// Body of the original message may not have formatted version, so may also have to convert to html. // Body of the original message may not have formatted version, so may also have to convert to html.
val bodyFormatted = body.formattedText ?: markdownParser.parse(newBodyText, force = true, advanced = false).takeFormatted() val bodyFormatted = body.formattedText ?: markdownParser.parse(newBodyText, force = true, advanced = false).takeFormatted()
val replyFormatted = REPLY_PATTERN.format( val replyFormatted = buildFormattedReply(
permalink, permalink,
userLink, userLink,
originalEvent.senderInfo.disambiguatedDisplayName, originalEvent.senderInfo.disambiguatedDisplayName,
// Remove inner mx_reply tags if any bodyFormatted,
bodyFormatted.replace(MX_REPLY_REGEX, ""),
newBodyFormatted newBodyFormatted
) )
// //
@ -398,12 +397,11 @@ internal class LocalEchoEventFactory @Inject constructor(
val replyTextFormatted = markdownParser.parse(replyText, force = true, advanced = false).takeFormatted() val replyTextFormatted = markdownParser.parse(replyText, force = true, advanced = false).takeFormatted()
// Body of the original message may not have formatted version, so may also have to convert to html. // Body of the original message may not have formatted version, so may also have to convert to html.
val bodyFormatted = body.formattedText ?: markdownParser.parse(replyText, force = true, advanced = false).takeFormatted() val bodyFormatted = body.formattedText ?: markdownParser.parse(replyText, force = true, advanced = false).takeFormatted()
val replyFormatted = REPLY_PATTERN.format( val replyFormatted = buildFormattedReply(
permalink, permalink,
userLink, userLink,
userId, userId,
// Remove inner mx_reply tags if any bodyFormatted,
bodyFormatted.replace(MX_REPLY_REGEX, ""),
replyTextFormatted replyTextFormatted
) )
// //
@ -422,6 +420,16 @@ internal class LocalEchoEventFactory @Inject constructor(
return createMessageEvent(roomId, content) return createMessageEvent(roomId, content)
} }
private fun buildFormattedReply(permalink: String, userLink: String, userId: String, bodyFormatted: String, newBodyFormatted: String): String {
return REPLY_PATTERN.format(
permalink,
userLink,
userId,
// Remove inner mx_reply tags if any
bodyFormatted.replace(MX_REPLY_REGEX, ""),
newBodyFormatted
)
}
private fun buildReplyFallback(body: TextContent, originalSenderId: String?, newBodyText: String): String { private fun buildReplyFallback(body: TextContent, originalSenderId: String?, newBodyText: String): String {
return buildString { return buildString {
append("> <") append("> <")