Remove extra space in <mx-reply>

This commit is contained in:
Benoit Marty 2019-07-10 10:07:45 +02:00
parent e6c74dc1fe
commit 228ee52563

View File

@ -250,31 +250,29 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
val permalink = PermalinkFactory.createPermalink(eventReplied) ?: return null val permalink = PermalinkFactory.createPermalink(eventReplied) ?: return null
val userId = eventReplied.senderId ?: return null val userId = eventReplied.senderId ?: return null
val userLink = PermalinkFactory.createPermalink(userId) ?: return null val userLink = PermalinkFactory.createPermalink(userId) ?: return null
// <mx-reply> // <mx-reply>
// <blockquote> // <blockquote>
// <a href="https://matrix.to/#/!somewhere:domain.com/$event:domain.com">In reply to</a> // <a href="https://matrix.to/#/!somewhere:domain.com/$event:domain.com">In reply to</a>
// <a href="https://matrix.to/#/@alice:example.org">@alice:example.org</a> // <a href="https://matrix.to/#/@alice:example.org">@alice:example.org</a>
// <br /> // <br />
// <!-- This is where the related event's HTML would be. --> // <!-- This is where the related event's HTML would be. -->
// </blockquote> // </blockquote>
// </mx-reply> // </mx-reply>
// This is where the reply goes. // This is where the reply goes.
val body = bodyForReply(eventReplied.getClearContent().toModel<MessageContent>()) val body = bodyForReply(eventReplied.getClearContent().toModel<MessageContent>())
val replyFallbackTemplateFormatted = """<mx-reply> val replyFallbackTemplateFormatted = REPLY_PATTERN.format(
<blockquote> permalink,
<a href="%s">${stringProvider.getString(R.string.message_reply_to_prefix)}</a> stringProvider.getString(R.string.message_reply_to_prefix),
<a href="%s">%s</a> userLink,
<br /> userId,
%s body.second ?: body.first,
</blockquote> replyText
</mx-reply> )
%s""".trimIndent().format(permalink, userLink, userId, body.second ?: body.first, replyText) //
// // > <@alice:example.org> This is the original body
// > <@alice:example.org> This is the original body //
//
// This is where the reply goes
val lines = body.first.split("\n") val lines = body.first.split("\n")
val plainTextBody = StringBuffer("><${userId}>") val plainTextBody = StringBuffer("><$userId>")
lines.firstOrNull()?.also { plainTextBody.append(" $it") } lines.firstOrNull()?.also { plainTextBody.append(" $it") }
lines.forEachIndexed { index, s -> lines.forEachIndexed { index, s ->
if (index > 0) { if (index > 0) {
@ -365,6 +363,9 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
companion object { companion object {
const val LOCAL_ID_PREFIX = "local." const val LOCAL_ID_PREFIX = "local."


// No whitespace
const val REPLY_PATTERN = """<mx-reply><blockquote><a href="%s">%s</a><a href="%s">%s</a><br />%s</blockquote></mx-reply>%s"""

fun isLocalEchoId(eventId: String): Boolean = eventId.startsWith(LOCAL_ID_PREFIX) fun isLocalEchoId(eventId: String): Boolean = eventId.startsWith(LOCAL_ID_PREFIX)
} }
} }