moezbhatti/qksms

App hangs when lots of emoticons are sent

Opened this issue ยท 2 comments

DESCRIPTION

My son was playing with my wife's phone. He sent me an SMS with lots of emojis. Now, when I open the conversation with my wife, QKSMS hangs and doesn't seem to respond. I even can't go back to list view.

STEPS

  1. Send lots of emojis to yourself like you're 4.
  2. Open the conversation
  3. App hangs

EXPECTED

Don't hang.

OBSERVATIONS

I can send couple of normal SMS from my wife's phone to fill up my screen, then the conversation does open. However, when scrolling up and revealing that monstrous message, the app hangs again.

I'm having a similar issue. Here's my specifics

  • Phone: Pixel 5
  • OS: iode, version: 4.4-20230824-redfin
  • Build number: TQ3A.230805.001 dev-keys
  • App version: 3.10.1

Specific message
๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•๐Ÿค๐Ÿ’•!!!!!!!!!!!!!!

Remove EMOJI_REGEX from MessagesAdapter:
Remove the declaration and usage of EMOJI_REGEX from your MessagesAdapter class. This means you no longer need the Regex pattern EMOJI_REGEX in your adapter.

Update emojiOnly variable:
Change the line
val emojiOnly = messageText.isNotBlank() && messageText.matches(EMOJI_REGEX)
to :
val emojiOnly = messageText.isNotBlank() && containsOnlyEmoji(messageText.toString())
This means you're now calling the containsOnlyEmoji function to check if the message contains only emojis.

Add containsOnlyEmoji function:
Add the following function to your code:

fun containsOnlyEmoji(text: String): Boolean {
    val regexPattern = Regex("^[\\p{So}]+$")
    return regexPattern.matches(text)
}

This function checks if the given text contains only emojis by using the Regex pattern ^[\p{So}]+$. If the text matches this pattern (i.e., contains only emojis), it returns true; otherwise, it returns false.

         // Update emojiOnly variable
        val emojiOnly = messageText.isNotBlank() && containsOnlyEmoji(messageText.toString())

By following these steps, you'll remove the EMOJI_REGEX, update the emojiOnly variable, and add the containsOnlyEmoji function to your MessagesAdapter class.