Commit 031a27fa authored by Leonardo Aramaki's avatar Leonardo Aramaki

Fix the logic to render multiple mentions to the same user and @all or @here

parent 123d05d2
...@@ -143,23 +143,19 @@ class MessageParser @Inject constructor( ...@@ -143,23 +143,19 @@ class MessageParser @Inject constructor(
override fun visit(document: Document) { override fun visit(document: Document) {
val text = builder.text() val text = builder.text()
val mentionsList = mentions.toMutableList().also {
it.add("@all")
it.add("@here")
}.distinct()
mentionsList.forEach { var offset = 0
mentions.forEach {
val mentionMe = it == currentUser || it == "@all" || it == "@here" val mentionMe = it == currentUser || it == "@all" || it == "@here"
var offset = text.indexOf(string = it, startIndex = 0, ignoreCase = false) offset = text.indexOf(string = it, startIndex = offset, ignoreCase = false)
while (offset > -1) { while (offset > -1) {
val textColor = if (mentionMe) myselfTextColor else othersTextColor val textColor = if (mentionMe) myselfTextColor else othersTextColor
val backgroundColor = if (mentionMe) myselfBackgroundColor else othersBackgroundColor val backgroundColor = if (mentionMe) myselfBackgroundColor else othersBackgroundColor
val usernameSpan = MentionSpan(backgroundColor, textColor, radius, padding, val usernameSpan = MentionSpan(backgroundColor, textColor, radius, padding,
mentionMe) mentionMe)
// Add 1 to end offset to include the @.
val end = offset + it.length val end = offset + it.length
builder.setSpan(usernameSpan, offset, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) builder.setSpan(usernameSpan, offset, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
offset = text.indexOf(string = "@$it", startIndex = end, ignoreCase = false) offset = text.indexOf(string = it, startIndex = end, ignoreCase = false)
} }
} }
} }
......
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