Skip to content

Commit

Permalink
fix: ignore negative mention index (#2274)
Browse files Browse the repository at this point in the history
Co-authored-by: Tommaso Piazza <[email protected]>
  • Loading branch information
Garzas and tmspzz authored Sep 26, 2023
1 parent b9388a2 commit 6135347
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,20 @@ internal fun MessageGenericAsset(
private fun mapToDisplayMentions(uiText: UIText, resources: Resources): Pair<List<DisplayMention>, String> {
return if (uiText is UIText.DynamicString) {
val stringBuilder: StringBuilder = StringBuilder(uiText.value)
val mentions = uiText.mentions.sortedBy { it.start }.reversed()
val mentionList = mentions.mapNotNull {
val mentions = uiText.mentions
.filter { it.start >= 0 && it.length > 0 }
.sortedBy { it.start }
.reversed()
val mentionList = mentions.mapNotNull { mention ->
// secured crash for mentions caused by web when text without mentions contains mention data
if (it.start + it.length < uiText.value.length && uiText.value.elementAt(it.start) == '@') {
val mentionName = uiText.value.substring(it.start, it.start + it.length)
stringBuilder.insert(it.start + it.length, MENTION_MARK)
stringBuilder.insert(it.start, MENTION_MARK)
if (mention.start + mention.length <= uiText.value.length && uiText.value.elementAt(mention.start) == '@') {
val mentionName = uiText.value.substring(mention.start, mention.start + mention.length)
stringBuilder.insert(mention.start + mention.length, MENTION_MARK)
stringBuilder.insert(mention.start, MENTION_MARK)
DisplayMention(
it.userId,
it.length,
it.isSelfMention,
mention.userId,
mention.length,
mention.isSelfMention,
mentionName
)
} else {
Expand Down

0 comments on commit 6135347

Please sign in to comment.