Commit 893de9f3 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Make LinkVisitor to visit at document scope instead of text, since long blocks...

Make LinkVisitor to visit at document scope instead of text, since long blocks of text with multiple paragraphs can lead to bad perf
parent 7ab7be11
......@@ -13,7 +13,6 @@ import android.text.style.ReplacementSpan
import android.view.View
import androidx.core.content.res.ResourcesCompat
import androidx.core.util.PatternsCompat
import chat.rocket.android.R
import chat.rocket.android.chatroom.ui.StrikethroughDelimiterProcessor
import chat.rocket.android.emoji.EmojiParser
import chat.rocket.android.emoji.EmojiRepository
......@@ -33,12 +32,7 @@ import org.commonmark.node.ListItem
import org.commonmark.node.Node
import org.commonmark.node.OrderedList
import org.commonmark.node.StrongEmphasis
import org.commonmark.node.Text
import org.commonmark.parser.Parser
import ru.noties.markwon.SpannableBuilder
import ru.noties.markwon.SpannableConfiguration
import ru.noties.markwon.renderer.SpannableMarkdownVisitor
import ru.noties.markwon.tasklist.TaskListExtension
import java.util.*
import javax.inject.Inject
......@@ -223,16 +217,7 @@ class MessageParser @Inject constructor(
class LinkVisitor(private val builder: SpannableBuilder) : AbstractVisitor() {
var parsed = false
override fun visit(text: Text) {
// XXX - Gambiarra ahead.
// This visitor visitis the text line by line, but we process all the document.
// So we don't parse again if it visited at least one line.
if (parsed) {
return
}
override fun visit(document: Document) {
// Replace all url links to markdown url syntax.
val matcher = PatternsCompat.AUTOLINK_WEB_URL.matcher(builder.text())
val consumed = mutableListOf<String>()
......@@ -249,8 +234,6 @@ class MessageParser @Inject constructor(
consumed.add(link)
}
}
parsed = true
}
}
......
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