mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-21 13:18:52 +01:00
Do some cleanups to emoji reaction code
This commit is contained in:
@@ -20,7 +20,6 @@ package dev.octoshrimpy.quik.repository
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import dev.octoshrimpy.quik.extensions.insertOrUpdate
|
|
||||||
import dev.octoshrimpy.quik.manager.KeyManager
|
import dev.octoshrimpy.quik.manager.KeyManager
|
||||||
import dev.octoshrimpy.quik.model.EmojiReaction
|
import dev.octoshrimpy.quik.model.EmojiReaction
|
||||||
import dev.octoshrimpy.quik.model.Message
|
import dev.octoshrimpy.quik.model.Message
|
||||||
@@ -39,12 +38,20 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
|||||||
private val reactionPatterns: LinkedHashMap<Regex, (MatchResult) -> ParsedEmojiReaction?> = linkedMapOf(
|
private val reactionPatterns: LinkedHashMap<Regex, (MatchResult) -> ParsedEmojiReaction?> = linkedMapOf(
|
||||||
Regex( // Google Messages
|
Regex( // Google Messages
|
||||||
"(?s)^\u200a[^\u200b\u200a]*\u200b([^\u200b]*)\u200b[^\u200b\u200a]*\u200a(.*)\u200a[^\u200b\u200a]*\u200a\\Z"
|
"(?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<Regex, (MatchResult) -> ParsedEmojiReaction?> = linkedMapOf(
|
private val removalPatterns: LinkedHashMap<Regex, (MatchResult) -> ParsedEmojiReaction?> = linkedMapOf(
|
||||||
Regex( // Google Messages
|
Regex( // Google Messages
|
||||||
"(?s)^\u200a[^\u200c\u200a]*\u200c([^\u200c]*)\u200c[^\u200c\u200a]*\u200a(.*)\u200a[^\u200c\u200a]*\u200a\\Z"
|
"(?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 {
|
init {
|
||||||
@@ -107,7 +114,10 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
|||||||
.mapNotNull { filename ->
|
.mapNotNull { filename ->
|
||||||
val localeTag = filename.removeSuffix(".json")
|
val localeTag = filename.removeSuffix(".json")
|
||||||
try {
|
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)
|
val data = parseEmojiPatternsJson(json)
|
||||||
localeTag to data
|
localeTag to data
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -127,11 +137,8 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
|||||||
if (removal != null) return removal
|
if (removal != null) return removal
|
||||||
|
|
||||||
for ((pattern, parser) in reactionPatterns) {
|
for ((pattern, parser) in reactionPatterns) {
|
||||||
val match = pattern.find(body)
|
val match = pattern.find(body) ?: continue
|
||||||
if (match == null) continue;
|
val result = parser(match) ?: continue
|
||||||
|
|
||||||
val result = parser(match)
|
|
||||||
if (result == null) continue
|
|
||||||
|
|
||||||
Timber.d("Reaction found with ${result.emoji}")
|
Timber.d("Reaction found with ${result.emoji}")
|
||||||
return result
|
return result
|
||||||
@@ -142,11 +149,8 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
private fun parseRemoval(body: String): ParsedEmojiReaction? {
|
private fun parseRemoval(body: String): ParsedEmojiReaction? {
|
||||||
for ((pattern, parser) in removalPatterns) {
|
for ((pattern, parser) in removalPatterns) {
|
||||||
val match = pattern.find(body)
|
val match = pattern.find(body) ?: continue
|
||||||
if (match == null) continue;
|
val result = parser(match) ?: continue
|
||||||
|
|
||||||
val result = parser(match)
|
|
||||||
if (result == null) continue
|
|
||||||
|
|
||||||
Timber.d("Removal found with ${result.emoji}")
|
Timber.d("Removal found with ${result.emoji}")
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user