Commit ec92246e authored by Leonardo Aramaki's avatar Leonardo Aramaki

Fix quotes markdown parsing

parent c1871a62
......@@ -130,6 +130,7 @@ class ViewModelMapper @Inject constructor(private val context: Context,
var quote: Message? = null
val urls = ArrayList<Url>()
var messageWithQuote: Message? = null
message.urls?.let {
if (it.isEmpty()) return@let
for (url in it) {
......@@ -139,12 +140,20 @@ class ViewModelMapper @Inject constructor(private val context: Context,
val serverUrl = HttpUrl.parse(baseUrl)
if (quoteUrl != null && serverUrl != null) {
quote = makeQuote(quoteUrl, serverUrl)
if (quote != null) {
if (quote != null) {
messageWithQuote = message.copy(
message = message.message.replace("[ ](${url.url})", "").trim()
)
}
}
}
}
}
}
val content = getContent(context, message, quote)
val content = getContent(context, messageWithQuote ?: message, quote)
MessageViewModel(message = message, rawData = message, messageId = message.id,
avatar = avatar!!, time = time, senderName = sender,
content = content, isPinned = message.pinned)
......@@ -194,7 +203,7 @@ class ViewModelMapper @Inject constructor(private val context: Context,
var quoteViewModel: MessageViewModel? = null
if (quote != null) {
val quoteMessage: Message = quote
quoteViewModel = map(quoteMessage).first { it is MessageViewModel } as MessageViewModel
quoteViewModel = mapMessage(quoteMessage)
}
return parser.renderMarkdown(message.message, quoteViewModel, currentUsername)
}
......
......@@ -59,6 +59,7 @@ class MessageParser @Inject constructor(val context: Application, private val co
parentNode.appendChild(quoteNode)
quoteNode.accept(QuoteMessageSenderVisitor(context, configuration, builder, senderName.length))
quoteNode = parser.parse("> ${toLenientMarkdown(quote.rawData.message)}")
quoteNode.accept(EmojiVisitor(builder))
quoteNode.accept(QuoteMessageBodyVisitor(context, configuration, builder))
}
parentNode.accept(LinkVisitor(builder))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment