From 67bbe0e83191f4b264dcf93050a2815697b900f0 Mon Sep 17 00:00:00 2001 From: Inhishonor Date: Wed, 17 Dec 2025 16:34:04 -0800 Subject: [PATCH 1/2] Do some cleanups to emoji reaction code --- .../repository/EmojiReactionRepositoryImpl.kt | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/data/src/main/java/com/moez/QKSMS/repository/EmojiReactionRepositoryImpl.kt b/data/src/main/java/com/moez/QKSMS/repository/EmojiReactionRepositoryImpl.kt index 81aba099..f0d597a7 100644 --- a/data/src/main/java/com/moez/QKSMS/repository/EmojiReactionRepositoryImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/repository/EmojiReactionRepositoryImpl.kt @@ -20,7 +20,6 @@ package dev.octoshrimpy.quik.repository import android.content.Context import com.squareup.moshi.Moshi -import dev.octoshrimpy.quik.extensions.insertOrUpdate import dev.octoshrimpy.quik.manager.KeyManager import dev.octoshrimpy.quik.model.EmojiReaction import dev.octoshrimpy.quik.model.Message @@ -39,12 +38,20 @@ class EmojiReactionRepositoryImpl @Inject constructor( private val reactionPatterns: LinkedHashMap ParsedEmojiReaction?> = linkedMapOf( Regex( // Google Messages "(?s)^\u200a[^\u200b\u200a]*\u200b([^\u200b]*)\u200b[^\u200b\u200a]*\u200a(.*)\u200a[^\u200b\u200a]*\u200a\\Z" - ) to { match -> ParsedEmojiReaction(match.groupValues[1], match.groupValues[2]) } + ) to { match -> + ParsedEmojiReaction( + match.groupValues[1], match.groupValues[2] + ) + } ) private val removalPatterns: LinkedHashMap ParsedEmojiReaction?> = linkedMapOf( Regex( // Google Messages "(?s)^\u200a[^\u200c\u200a]*\u200c([^\u200c]*)\u200c[^\u200c\u200a]*\u200a(.*)\u200a[^\u200c\u200a]*\u200a\\Z" - ) to { match -> ParsedEmojiReaction(match.groupValues[1], match.groupValues[2], isRemoval = true) } + ) to { match -> + ParsedEmojiReaction( + match.groupValues[1], match.groupValues[2], isRemoval = true + ) + } ) init { @@ -107,7 +114,10 @@ class EmojiReactionRepositoryImpl @Inject constructor( .mapNotNull { filename -> val localeTag = filename.removeSuffix(".json") try { - val json = context.assets.open("$dir/$filename").bufferedReader().use { it.readText() } + val json = context.assets.open("$dir/$filename") + .bufferedReader().use { + it.readText() + } val data = parseEmojiPatternsJson(json) localeTag to data } catch (e: Exception) { @@ -127,11 +137,8 @@ class EmojiReactionRepositoryImpl @Inject constructor( if (removal != null) return removal for ((pattern, parser) in reactionPatterns) { - val match = pattern.find(body) - if (match == null) continue; - - val result = parser(match) - if (result == null) continue + val match = pattern.find(body) ?: continue + val result = parser(match) ?: continue Timber.d("Reaction found with ${result.emoji}") return result @@ -142,11 +149,8 @@ class EmojiReactionRepositoryImpl @Inject constructor( private fun parseRemoval(body: String): ParsedEmojiReaction? { for ((pattern, parser) in removalPatterns) { - val match = pattern.find(body) - if (match == null) continue; - - val result = parser(match) - if (result == null) continue + val match = pattern.find(body) ?: continue + val result = parser(match) ?: continue Timber.d("Removal found with ${result.emoji}") return result From d23b35bfe918ade9a8210750ab26de82fb2e7f44 Mon Sep 17 00:00:00 2001 From: Inhishonor Date: Wed, 17 Dec 2025 16:37:40 -0800 Subject: [PATCH 2/2] Support matching message reactions that are truncated Some emoji reactions will appear as "Liked 'message...'" with the message cut off. This change uses a regex to match all ellipsis at the end of messages to any other message with the same content. --- .../repository/EmojiReactionRepositoryImpl.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/data/src/main/java/com/moez/QKSMS/repository/EmojiReactionRepositoryImpl.kt b/data/src/main/java/com/moez/QKSMS/repository/EmojiReactionRepositoryImpl.kt index f0d597a7..8367ffd5 100644 --- a/data/src/main/java/com/moez/QKSMS/repository/EmojiReactionRepositoryImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/repository/EmojiReactionRepositoryImpl.kt @@ -159,6 +159,20 @@ class EmojiReactionRepositoryImpl @Inject constructor( return null } + private fun parseTruncatedMessages(originalMessageText: String): Regex { + val reactionText = originalMessageText.trim() + + val delimiter = "\u2026" + val index = reactionText.lastIndexOf(delimiter) + val regexPattern = if (index == -1) { + Regex.escape(reactionText) + } else { + val before = reactionText.take(index) + Regex.escape(before) + ".*" + } + return Regex("^$regexPattern$", RegexOption.DOT_MATCHES_ALL) + } + /** * Search for messages in the same thread with matching text content * We'll search recent messages first @@ -176,8 +190,9 @@ class EmojiReactionRepositoryImpl @Inject constructor( val endTime = System.currentTimeMillis() Timber.d("Found ${messages.size} messages as potential emoji targets in ${endTime - startTime}ms") + val originalMessageRegex = parseTruncatedMessages(originalMessageText) val match = messages.find { message -> - message.getText(false).trim() == originalMessageText.trim() + originalMessageRegex.matches(message.getText(false).trim()) } if (match != null) { Timber.d("Found match for reaction target: message ID ${match.id}")