forked from upstream-mirrors/quik
Parse and render emoji reactions
Fixes part of #152 To keep this PR simple, I've left out: - when long-pressing on the emoji in a group MMS, a popup should come up listing which contact sent each emoji - notifications (untested) - sending emoji reactions
This commit is contained in:
@@ -36,7 +36,7 @@ class QkRealmMigration @Inject constructor(
|
|||||||
) : RealmMigration {
|
) : RealmMigration {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SchemaVersion: Long = 12
|
const val SchemaVersion: Long = 13
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
@@ -253,6 +253,28 @@ class QkRealmMigration @Inject constructor(
|
|||||||
version++
|
version++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version == 12L) {
|
||||||
|
realm.schema.create("EmojiReaction")
|
||||||
|
.addField("id", Long::class.java, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED)
|
||||||
|
.addField("targetMessageId", Long::class.java, FieldAttribute.INDEXED, FieldAttribute.REQUIRED)
|
||||||
|
.addField("reactionMessageId", Long::class.java, FieldAttribute.INDEXED, FieldAttribute.REQUIRED)
|
||||||
|
.addField("senderAddress", String::class.java, FieldAttribute.REQUIRED)
|
||||||
|
.addField("emoji", String::class.java, FieldAttribute.REQUIRED)
|
||||||
|
.addField("originalMessageText", String::class.java, FieldAttribute.REQUIRED)
|
||||||
|
.addField("threadId", Long::class.java, FieldAttribute.INDEXED, FieldAttribute.REQUIRED)
|
||||||
|
.addField("patternType", String::class.java, FieldAttribute.REQUIRED)
|
||||||
|
|
||||||
|
realm.schema.get("Message")
|
||||||
|
?.addField("isEmojiReaction", Boolean::class.java, FieldAttribute.REQUIRED)
|
||||||
|
?.transform { msg ->
|
||||||
|
msg.setBoolean("isEmojiReaction", false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: scan for past emoji reaction messages
|
||||||
|
|
||||||
|
version++
|
||||||
|
}
|
||||||
|
|
||||||
check(version >= newVersion) { "Migration missing from v$oldVersion to v$newVersion" }
|
check(version >= newVersion) { "Migration missing from v$oldVersion to v$newVersion" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ import dev.octoshrimpy.quik.receiver.SendSmsReceiver
|
|||||||
import dev.octoshrimpy.quik.receiver.SmsDeliveredReceiver
|
import dev.octoshrimpy.quik.receiver.SmsDeliveredReceiver
|
||||||
import dev.octoshrimpy.quik.receiver.SmsSentReceiver
|
import dev.octoshrimpy.quik.receiver.SmsSentReceiver
|
||||||
import dev.octoshrimpy.quik.util.ImageUtils
|
import dev.octoshrimpy.quik.util.ImageUtils
|
||||||
|
import dev.octoshrimpy.quik.util.EmojiReactionUtils
|
||||||
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
||||||
import dev.octoshrimpy.quik.util.Preferences
|
import dev.octoshrimpy.quik.util.Preferences
|
||||||
import dev.octoshrimpy.quik.util.tryOrNull
|
import dev.octoshrimpy.quik.util.tryOrNull
|
||||||
@@ -88,6 +89,7 @@ open class MessageRepositoryImpl @Inject constructor(
|
|||||||
Realm.getDefaultInstance()
|
Realm.getDefaultInstance()
|
||||||
.where(Message::class.java)
|
.where(Message::class.java)
|
||||||
.equalTo("threadId", threadId)
|
.equalTo("threadId", threadId)
|
||||||
|
.equalTo("isEmojiReaction", false)
|
||||||
.let {
|
.let {
|
||||||
when (query.isEmpty()) {
|
when (query.isEmpty()) {
|
||||||
true -> it
|
true -> it
|
||||||
@@ -760,6 +762,26 @@ open class MessageRepositoryImpl @Inject constructor(
|
|||||||
// Update contentId after the message has been inserted to the content provider
|
// Update contentId after the message has been inserted to the content provider
|
||||||
realm.executeTransaction { managedMessage?.contentId = id }
|
realm.executeTransaction { managedMessage?.contentId = id }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
managedMessage?.let { savedMessage ->
|
||||||
|
val parsedReaction = EmojiReactionUtils.parseEmojiReaction(body)
|
||||||
|
if (parsedReaction != null) {
|
||||||
|
val targetMessage = EmojiReactionUtils.findTargetMessage(
|
||||||
|
savedMessage.threadId,
|
||||||
|
parsedReaction.originalMessage,
|
||||||
|
realm
|
||||||
|
)
|
||||||
|
realm.executeTransaction {
|
||||||
|
EmojiReactionUtils.saveEmojiReaction(
|
||||||
|
savedMessage,
|
||||||
|
parsedReaction,
|
||||||
|
targetMessage,
|
||||||
|
messageIds,
|
||||||
|
realm,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import dev.octoshrimpy.quik.model.MmsPart
|
|||||||
import dev.octoshrimpy.quik.model.PhoneNumber
|
import dev.octoshrimpy.quik.model.PhoneNumber
|
||||||
import dev.octoshrimpy.quik.model.Recipient
|
import dev.octoshrimpy.quik.model.Recipient
|
||||||
import dev.octoshrimpy.quik.model.SyncLog
|
import dev.octoshrimpy.quik.model.SyncLog
|
||||||
|
import dev.octoshrimpy.quik.util.EmojiReactionUtils
|
||||||
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
||||||
import dev.octoshrimpy.quik.util.tryOrNull
|
import dev.octoshrimpy.quik.util.tryOrNull
|
||||||
import io.reactivex.subjects.BehaviorSubject
|
import io.reactivex.subjects.BehaviorSubject
|
||||||
@@ -104,6 +105,7 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
realm.delete(Message::class.java)
|
realm.delete(Message::class.java)
|
||||||
realm.delete(MmsPart::class.java)
|
realm.delete(MmsPart::class.java)
|
||||||
realm.delete(Recipient::class.java)
|
realm.delete(Recipient::class.java)
|
||||||
|
realm.delete(dev.octoshrimpy.quik.model.EmojiReaction::class.java)
|
||||||
|
|
||||||
keys.reset()
|
keys.reset()
|
||||||
|
|
||||||
@@ -202,6 +204,39 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(0, 0, true))
|
syncProgress.onNext(SyncRepository.SyncProgress.Running(0, 0, true))
|
||||||
|
|
||||||
|
// Now that we have all the messages, we can scan for emoji reactions
|
||||||
|
val allMessages = realm.where(Message::class.java)
|
||||||
|
.beginGroup()
|
||||||
|
.beginGroup()
|
||||||
|
.equalTo("type", "sms")
|
||||||
|
.isNotEmpty("body")
|
||||||
|
.endGroup()
|
||||||
|
.or()
|
||||||
|
.beginGroup()
|
||||||
|
.equalTo("type", "mms")
|
||||||
|
.isNotEmpty("parts.text")
|
||||||
|
.endGroup()
|
||||||
|
.endGroup()
|
||||||
|
.findAll()
|
||||||
|
|
||||||
|
allMessages.forEach { message ->
|
||||||
|
val text = message.getText(false)
|
||||||
|
val parsedReaction = EmojiReactionUtils.parseEmojiReaction(text)
|
||||||
|
if (parsedReaction != null) {
|
||||||
|
val targetMessage = EmojiReactionUtils.findTargetMessage(
|
||||||
|
message.threadId,
|
||||||
|
parsedReaction.originalMessage,
|
||||||
|
realm
|
||||||
|
)
|
||||||
|
EmojiReactionUtils.saveEmojiReaction(
|
||||||
|
message,
|
||||||
|
parsedReaction,
|
||||||
|
targetMessage,
|
||||||
|
keys,
|
||||||
|
realm,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
realm.insert(SyncLog())
|
realm.insert(SyncLog())
|
||||||
realm.commitTransaction()
|
realm.commitTransaction()
|
||||||
@@ -259,6 +294,27 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
conversationRepo.getOrCreateConversation(threadId)
|
conversationRepo.getOrCreateConversation(threadId)
|
||||||
insertOrUpdate()
|
insertOrUpdate()
|
||||||
|
|
||||||
|
val text = getText(false)
|
||||||
|
val parsedReaction = EmojiReactionUtils.parseEmojiReaction(text)
|
||||||
|
if (parsedReaction != null) {
|
||||||
|
Realm.getDefaultInstance().use { realm ->
|
||||||
|
val targetMessage = EmojiReactionUtils.findTargetMessage(
|
||||||
|
threadId,
|
||||||
|
parsedReaction.originalMessage,
|
||||||
|
realm
|
||||||
|
)
|
||||||
|
realm.executeTransaction {
|
||||||
|
EmojiReactionUtils.saveEmojiReaction(
|
||||||
|
this,
|
||||||
|
parsedReaction,
|
||||||
|
targetMessage,
|
||||||
|
keys,
|
||||||
|
realm,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025
|
||||||
|
*
|
||||||
|
* This file is part of QUIK.
|
||||||
|
*
|
||||||
|
* QUIK is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QUIK is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QUIK. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package dev.octoshrimpy.quik.util
|
||||||
|
|
||||||
|
import dev.octoshrimpy.quik.manager.KeyManager
|
||||||
|
import dev.octoshrimpy.quik.model.EmojiReaction
|
||||||
|
import dev.octoshrimpy.quik.model.Message
|
||||||
|
import io.realm.Realm
|
||||||
|
import io.realm.Sort
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
data class ParsedEmojiReaction(val emoji: String, val originalMessage: String, val patternType: String)
|
||||||
|
|
||||||
|
object EmojiReactionUtils {
|
||||||
|
|
||||||
|
fun parseEmojiReaction(body: String): ParsedEmojiReaction? {
|
||||||
|
// Log the raw message with unicode escapes for debugging
|
||||||
|
val escapedBody = body.map { char ->
|
||||||
|
when (char.code) {
|
||||||
|
in 0x20..0x7E -> char.toString() // printable ASCII
|
||||||
|
else -> "\\u${char.code.toString(16).padStart(4, '0')}"
|
||||||
|
}
|
||||||
|
}.joinToString("")
|
||||||
|
Timber.v("Parsing body: \"$escapedBody\"") // TODO: are we okay logging SMS content?
|
||||||
|
|
||||||
|
val iosPattern = Regex("^Reacted (.+?) to \u201C(.+?)\u201D$")
|
||||||
|
val iosMatch = iosPattern.find(body)
|
||||||
|
if (iosMatch != null) {
|
||||||
|
val emoji = iosMatch.groupValues[1]
|
||||||
|
val originalMessage = iosMatch.groupValues[2]
|
||||||
|
|
||||||
|
if (emoji == "with a sticker") {
|
||||||
|
Timber.d("Skipping sticker reaction: '$originalMessage'")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
Timber.d("iOS pattern detected - emoji: '$emoji', original: '$originalMessage'")
|
||||||
|
return ParsedEmojiReaction(emoji, originalMessage, "ios")
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/octoshrimpy/quik/issues/152#issuecomment-2330183516
|
||||||
|
val googleMessagesPattern = Regex("^\u200A\u200B(.+?)\u200B to \u201C\u200A(.+?)\u200A\u201D\u200A$")
|
||||||
|
val googleMatch = googleMessagesPattern.find(body)
|
||||||
|
if (googleMatch != null) {
|
||||||
|
val emoji = googleMatch.groupValues[1]
|
||||||
|
val originalMessage = googleMatch.groupValues[2]
|
||||||
|
Timber.d("Google Messages pattern detected - emoji: '$emoji', original: '$originalMessage'")
|
||||||
|
return ParsedEmojiReaction(emoji, originalMessage, "google")
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for messages in the same thread with matching text content
|
||||||
|
* We'll search recent messages first (within reasonable time window)
|
||||||
|
*/
|
||||||
|
fun findTargetMessage(threadId: Long, originalMessageText: String, realm: Realm): Message? {
|
||||||
|
val messages = realm.where(Message::class.java)
|
||||||
|
.equalTo("threadId", threadId)
|
||||||
|
.sort("date", Sort.DESCENDING)
|
||||||
|
.limit(50) // TODO: should we keep this limit?
|
||||||
|
.findAll()
|
||||||
|
|
||||||
|
val exactMatch = messages.find { message ->
|
||||||
|
message.getText(false).trim() == originalMessageText.trim()
|
||||||
|
}
|
||||||
|
if (exactMatch != null) {
|
||||||
|
Timber.d("Found exact match for reaction target: message ID ${exactMatch.id}")
|
||||||
|
return exactMatch
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try partial match (in case of truncation)
|
||||||
|
val partialMatch = messages.find { message ->
|
||||||
|
val text = message.getText(false).trim()
|
||||||
|
text.isNotEmpty() && (
|
||||||
|
text.contains(originalMessageText.trim(), ignoreCase = true) ||
|
||||||
|
originalMessageText.trim().contains(text, ignoreCase = true)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (partialMatch != null) {
|
||||||
|
Timber.d("Found partial match for reaction target: message ID ${partialMatch.id}")
|
||||||
|
return partialMatch
|
||||||
|
}
|
||||||
|
|
||||||
|
Timber.w("No target message found for reaction text: '$originalMessageText'")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveEmojiReaction(
|
||||||
|
reactionMessage: Message,
|
||||||
|
parsedReaction: ParsedEmojiReaction,
|
||||||
|
targetMessage: Message?,
|
||||||
|
keyManager: KeyManager,
|
||||||
|
realm: Realm,
|
||||||
|
) {
|
||||||
|
val reaction = EmojiReaction().apply {
|
||||||
|
id = keyManager.newId()
|
||||||
|
reactionMessageId = reactionMessage.id
|
||||||
|
targetMessageId = targetMessage?.id ?: 0
|
||||||
|
senderAddress = reactionMessage.address
|
||||||
|
emoji = parsedReaction.emoji
|
||||||
|
originalMessageText = parsedReaction.originalMessage
|
||||||
|
threadId = reactionMessage.threadId
|
||||||
|
patternType = parsedReaction.patternType
|
||||||
|
}
|
||||||
|
|
||||||
|
realm.insertOrUpdate(reaction)
|
||||||
|
reactionMessage.isEmojiReaction = true
|
||||||
|
realm.insertOrUpdate(reactionMessage)
|
||||||
|
|
||||||
|
if (targetMessage != null) {
|
||||||
|
Timber.i("Saved emoji reaction: ${reaction.emoji} from ${reaction.senderAddress} to message ${targetMessage.id}")
|
||||||
|
} else {
|
||||||
|
Timber.w("Saved emoji reaction without target message: ${reaction.emoji} from ${reaction.senderAddress}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025
|
||||||
|
*
|
||||||
|
* This file is part of QUIK.
|
||||||
|
*
|
||||||
|
* QKSMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QKSMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package dev.octoshrimpy.quik.model
|
||||||
|
|
||||||
|
import io.realm.RealmObject
|
||||||
|
import io.realm.annotations.Index
|
||||||
|
import io.realm.annotations.PrimaryKey
|
||||||
|
|
||||||
|
open class EmojiReaction : RealmObject() {
|
||||||
|
@PrimaryKey var id: Long = 0
|
||||||
|
|
||||||
|
/** The message this is a reaction to */
|
||||||
|
@Index var targetMessageId: Long = 0
|
||||||
|
|
||||||
|
/** The reaction message ID itself */
|
||||||
|
@Index var reactionMessageId: Long = 0
|
||||||
|
|
||||||
|
/** The sender's address (phone number) */
|
||||||
|
var senderAddress: String = ""
|
||||||
|
|
||||||
|
/** The emoji used in the reaction */
|
||||||
|
var emoji: String = ""
|
||||||
|
|
||||||
|
/** The original message text that was reacted to */
|
||||||
|
var originalMessageText: String = ""
|
||||||
|
|
||||||
|
/** Thread ID for easier querying */
|
||||||
|
@Index var threadId: Long = 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pattern type that was matched (for debugging)
|
||||||
|
*
|
||||||
|
* for example, "ios" or "google"
|
||||||
|
*/
|
||||||
|
var patternType: String = ""
|
||||||
|
}
|
||||||
@@ -74,6 +74,7 @@ open class Message : RealmObject() {
|
|||||||
var subject: String = ""
|
var subject: String = ""
|
||||||
var textContentType: String = ""
|
var textContentType: String = ""
|
||||||
var parts: RealmList<MmsPart> = RealmList()
|
var parts: RealmList<MmsPart> = RealmList()
|
||||||
|
var isEmojiReaction: Boolean = false
|
||||||
|
|
||||||
fun getUri(): Uri {
|
fun getUri(): Uri {
|
||||||
val baseUri = if (isMms()) Mms.CONTENT_URI else Sms.CONTENT_URI
|
val baseUri = if (isMms()) Mms.CONTENT_URI else Sms.CONTENT_URI
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ object BubbleUtils {
|
|||||||
|
|
||||||
const val TIMESTAMP_THRESHOLD = 10
|
const val TIMESTAMP_THRESHOLD = 10
|
||||||
|
|
||||||
|
// TODO: update to consider emoji reactions
|
||||||
fun canGroup(message: Message, other: Message?): Boolean {
|
fun canGroup(message: Message, other: Message?): Boolean {
|
||||||
if (other == null) return false
|
if (other == null) return false
|
||||||
val diff = TimeUnit.MILLISECONDS.toMinutes(Math.abs(message.date - other.date))
|
val diff = TimeUnit.MILLISECONDS.toMinutes(Math.abs(message.date - other.date))
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ import dev.octoshrimpy.quik.feature.compose.BubbleUtils.getBubble
|
|||||||
import dev.octoshrimpy.quik.feature.compose.part.PartsAdapter
|
import dev.octoshrimpy.quik.feature.compose.part.PartsAdapter
|
||||||
import dev.octoshrimpy.quik.feature.extensions.isEmojiOnly
|
import dev.octoshrimpy.quik.feature.extensions.isEmojiOnly
|
||||||
import dev.octoshrimpy.quik.model.Conversation
|
import dev.octoshrimpy.quik.model.Conversation
|
||||||
|
import dev.octoshrimpy.quik.model.EmojiReaction
|
||||||
import dev.octoshrimpy.quik.model.Message
|
import dev.octoshrimpy.quik.model.Message
|
||||||
import dev.octoshrimpy.quik.model.Recipient
|
import dev.octoshrimpy.quik.model.Recipient
|
||||||
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
import dev.octoshrimpy.quik.util.PhoneNumberUtils
|
||||||
@@ -71,10 +72,13 @@ import dev.octoshrimpy.quik.util.Preferences
|
|||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
import io.reactivex.subjects.Subject
|
import io.reactivex.subjects.Subject
|
||||||
|
import io.realm.Realm
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
import kotlinx.android.synthetic.main.message_list_item_in.*
|
import kotlinx.android.synthetic.main.message_list_item_in.*
|
||||||
import kotlinx.android.synthetic.main.message_list_item_in.body
|
import kotlinx.android.synthetic.main.message_list_item_in.body
|
||||||
|
import kotlinx.android.synthetic.main.message_list_item_in.reactionText
|
||||||
import kotlinx.android.synthetic.main.message_list_item_in.parts
|
import kotlinx.android.synthetic.main.message_list_item_in.parts
|
||||||
|
import kotlinx.android.synthetic.main.message_list_item_in.reactions
|
||||||
import kotlinx.android.synthetic.main.message_list_item_in.sim
|
import kotlinx.android.synthetic.main.message_list_item_in.sim
|
||||||
import kotlinx.android.synthetic.main.message_list_item_in.simIndex
|
import kotlinx.android.synthetic.main.message_list_item_in.simIndex
|
||||||
import kotlinx.android.synthetic.main.message_list_item_in.status
|
import kotlinx.android.synthetic.main.message_list_item_in.status
|
||||||
@@ -389,6 +393,59 @@ class MessagesAdapter @Inject constructor(
|
|||||||
contextMenuValue = message.id
|
contextMenuValue = message.id
|
||||||
clicks.subscribe(partClicks) // part clicks gets passed back to compose view model
|
clicks.subscribe(partClicks) // part clicks gets passed back to compose view model
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bindEmojiReactions(holder, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindEmojiReactions(holder: QkViewHolder, message: Message) {
|
||||||
|
holder.reactions?.let { reactionsContainer ->
|
||||||
|
val reactions = getReactionsForMessage(message.id)
|
||||||
|
val hasReactions = reactions.isNotEmpty()
|
||||||
|
|
||||||
|
if (hasReactions) {
|
||||||
|
val reactionCounts = reactions.groupBy { it.emoji }
|
||||||
|
.mapValues { it.value.size }
|
||||||
|
.toList()
|
||||||
|
.sortedByDescending { it.second } // Sort by count, most reactions first
|
||||||
|
|
||||||
|
// For now, show just the first (most popular) reaction
|
||||||
|
val topReaction = reactionCounts.first()
|
||||||
|
val reactionText = if (topReaction.second == 1) {
|
||||||
|
topReaction.first
|
||||||
|
} else {
|
||||||
|
"${topReaction.first} ${topReaction.second}"
|
||||||
|
}
|
||||||
|
|
||||||
|
holder.reactionText?.text = reactionText
|
||||||
|
reactionsContainer.setVisible(true)
|
||||||
|
makeRoomForEmojis(holder)
|
||||||
|
} else {
|
||||||
|
reactionsContainer.setVisible(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun makeRoomForEmojis(holder: QkViewHolder) {
|
||||||
|
val paddingBottom = 21.dpToPx(context)
|
||||||
|
|
||||||
|
// Adjust the container padding
|
||||||
|
(holder.reactions?.parent as? ViewGroup)?.let { parent ->
|
||||||
|
parent.setPadding(
|
||||||
|
parent.paddingLeft,
|
||||||
|
parent.paddingTop,
|
||||||
|
parent.paddingRight,
|
||||||
|
paddingBottom
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getReactionsForMessage(messageId: Long): List<EmojiReaction> {
|
||||||
|
return Realm.getDefaultInstance().use { realm ->
|
||||||
|
realm.where(EmojiReaction::class.java)
|
||||||
|
.equalTo("targetMessageId", messageId)
|
||||||
|
.findAll()
|
||||||
|
.let { realm.copyFromRealm(it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bindStatus(
|
private fun bindStatus(
|
||||||
|
|||||||
@@ -89,16 +89,19 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="@id/body"
|
app:layout_constraintBottom_toBottomOf="@id/body"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
<LinearLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="12dp"
|
android:layout_marginStart="12dp"
|
||||||
android:orientation="vertical">
|
android:paddingBottom="20dp"
|
||||||
|
android:clipToPadding="false">
|
||||||
|
|
||||||
<dev.octoshrimpy.quik.common.widget.QkContextMenuRecyclerViewLongMmsPart
|
<dev.octoshrimpy.quik.common.widget.QkContextMenuRecyclerViewLongMmsPart
|
||||||
android:id="@+id/parts"
|
android:id="@+id/parts"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
android:nestedScrollingEnabled="false"
|
android:nestedScrollingEnabled="false"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
@@ -110,6 +113,8 @@
|
|||||||
style="@style/TextPrimary"
|
style="@style/TextPrimary"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_below="@id/parts"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:autoLink="email|phone|web"
|
android:autoLink="email|phone|web"
|
||||||
android:background="@drawable/message_only"
|
android:background="@drawable/message_only"
|
||||||
@@ -118,7 +123,37 @@
|
|||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
tools:backgroundTint="@color/tools_theme"
|
tools:backgroundTint="@color/tools_theme"
|
||||||
tools:text="@tools:sample/lorem/random" />
|
tools:text="@tools:sample/lorem/random" />
|
||||||
</LinearLayout>
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/reactions"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@id/body"
|
||||||
|
android:layout_alignEnd="@id/body"
|
||||||
|
android:layout_marginEnd="-12dp"
|
||||||
|
android:layout_marginBottom="-20dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/reactionText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/message_only"
|
||||||
|
android:backgroundTint="?android:attr/colorBackground"
|
||||||
|
android:elevation="2dp"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingTop="4dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:paddingBottom="4dp"
|
||||||
|
android:text="😂 2"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,8 @@
|
|||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:clipToPadding="false">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/cancelFrame"
|
android:id="@+id/cancelFrame"
|
||||||
@@ -145,17 +146,54 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<dev.octoshrimpy.quik.common.widget.TightTextView
|
<FrameLayout
|
||||||
android:id="@+id/body"
|
|
||||||
style="@style/TextPrimary"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:autoLink="email|phone|web"
|
android:paddingStart="18dp"
|
||||||
android:background="@drawable/message_only"
|
android:paddingBottom="21dp"
|
||||||
android:backgroundTint="?attr/bubbleColor"
|
android:clipToPadding="false">
|
||||||
android:gravity="start|center_vertical"
|
|
||||||
android:minHeight="36dp"
|
<dev.octoshrimpy.quik.common.widget.TightTextView
|
||||||
android:textIsSelectable="true" />
|
android:id="@+id/body"
|
||||||
|
style="@style/TextPrimary"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:autoLink="email|phone|web"
|
||||||
|
android:background="@drawable/message_only"
|
||||||
|
android:backgroundTint="?attr/bubbleColor"
|
||||||
|
android:gravity="start|center_vertical"
|
||||||
|
android:minHeight="36dp"
|
||||||
|
android:textIsSelectable="true" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/reactions"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|start"
|
||||||
|
android:layout_marginStart="-16dp"
|
||||||
|
android:layout_marginBottom="-20dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/reactionText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/message_only"
|
||||||
|
android:backgroundTint="?android:attr/colorBackground"
|
||||||
|
android:elevation="2dp"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingTop="4dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:paddingBottom="4dp"
|
||||||
|
android:text="👍 1"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
|||||||
Reference in New Issue
Block a user