Commit 9bcb5346 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Fix username regex

parent c3307c64
...@@ -28,7 +28,7 @@ import javax.inject.Inject ...@@ -28,7 +28,7 @@ import javax.inject.Inject
class MessageParser @Inject constructor(val context: Application, private val configuration: SpannableConfiguration) { class MessageParser @Inject constructor(val context: Application, private val configuration: SpannableConfiguration) {
private val parser = Markwon.createParser() private val parser = Markwon.createParser()
private val userPattern = Pattern.compile("(@[\\w.]+)", private val usernameRegex = Pattern.compile("([^\\S]|^)+(@[\\w.]+)",
Pattern.MULTILINE or Pattern.CASE_INSENSITIVE) Pattern.MULTILINE or Pattern.CASE_INSENSITIVE)
/** /**
...@@ -65,11 +65,11 @@ class MessageParser @Inject constructor(val context: Application, private val co ...@@ -65,11 +65,11 @@ class MessageParser @Inject constructor(val context: Application, private val co
} }
private fun applySpans(text: CharSequence) { private fun applySpans(text: CharSequence) {
val matcher = userPattern.matcher(text) val matcher = usernameRegex.matcher(text)
val result = text as Spannable val result = text as Spannable
while (matcher.find()) { while (matcher.find()) {
val user = matcher.group(1) val user = matcher.group(2)
val start = matcher.start() val start = matcher.start(2)
//TODO: should check if username actually exists prior to applying. //TODO: should check if username actually exists prior to applying.
result.setSpan(UsernameClickableSpan(), start, start + user.length, 0) result.setSpan(UsernameClickableSpan(), start, start + user.length, 0)
} }
......
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