Skip to content

Commit

Permalink
Fix reply mentions not getting removed occasionally
Browse files Browse the repository at this point in the history
  • Loading branch information
wingio committed Dec 5, 2023
1 parent 7de2de4 commit 50a5a87
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/src/main/java/xyz/wingio/dimett/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ fun getLogger(): Logger = GlobalContext.get().get(named("default"))

fun String.toAnnotatedString() = AnnotatedString(this)

/**
* Removes the mention for the replied user from the start of the text
*/
fun processPostContent(post: Post): String {
val repliedTo = post.mentions.firstOrNull { mention ->
mention.id == post.userRepliedTo
}
return post.content?.plain?.run {
if (repliedTo != null) replaceFirst("@${repliedTo.username} ", "") else this
if (repliedTo != null)
this
.replaceFirst("@${repliedTo.username} ", "")
.replaceFirst("@${repliedTo.acct}", "")
else
this
} ?: ""
}

Expand Down

0 comments on commit 50a5a87

Please sign in to comment.