forked from upstream-mirrors/quik
fix(reactions): correct thread safety, self-receipt, anchoring, and attribution
Address review findings on the send-reaction feature: - Run permission checks on the main thread and only switch to IO for the actual send, instead of touching the UI from a background thread. - Parse outgoing reactions on the sender's own device. Sent messages don't arrive back as incoming, so they would otherwise never be attached or hidden until a full reparse. - Anchor the reaction picker above the long-pressed message instead of centering it on the screen, falling back to the list when off-screen. - Always send reactions as group MMS in a group thread. - Attribute our own reactions to our own number (via isMe + getMyPhoneNumber) rather than the recipient's address, and show "Me" for them in the reactions dialog. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
package dev.octoshrimpy.quik.repository
|
||||
|
||||
import android.content.Context
|
||||
import com.klinker.android.send_message.Utils
|
||||
import com.squareup.moshi.Moshi
|
||||
import dev.octoshrimpy.quik.manager.KeyManager
|
||||
import dev.octoshrimpy.quik.model.EmojiReaction
|
||||
@@ -251,6 +252,17 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* The address to attribute a reaction to. For incoming reactions this is the message sender;
|
||||
* for our own outgoing reactions [Message.address] is the recipient, so use our own number
|
||||
* instead so the reaction shows as coming from us.
|
||||
*/
|
||||
private fun reactionSenderAddress(reactionMessage: Message): String =
|
||||
if (reactionMessage.isMe())
|
||||
Utils.getMyPhoneNumber(context).takeUnless { it.isNullOrEmpty() } ?: reactionMessage.address
|
||||
else
|
||||
reactionMessage.address
|
||||
|
||||
private fun removeEmojiReaction(
|
||||
reactionMessage: Message,
|
||||
reaction: ParsedEmojiReaction,
|
||||
@@ -262,8 +274,9 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
||||
return
|
||||
}
|
||||
|
||||
val senderAddress = reactionSenderAddress(reactionMessage)
|
||||
val existingReaction = targetMessage.emojiReactions.find { candidate ->
|
||||
candidate.senderAddress == reactionMessage.address && candidate.emoji == reaction.emoji
|
||||
candidate.senderAddress == senderAddress && candidate.emoji == reaction.emoji
|
||||
}
|
||||
|
||||
if (existingReaction != null) {
|
||||
@@ -291,7 +304,7 @@ class EmojiReactionRepositoryImpl @Inject constructor(
|
||||
val reaction = EmojiReaction().apply {
|
||||
id = keyManager.newId()
|
||||
reactionMessageId = reactionMessage.id
|
||||
senderAddress = reactionMessage.address
|
||||
senderAddress = reactionSenderAddress(reactionMessage)
|
||||
emoji = parsedReaction.emoji
|
||||
originalMessageText = parsedReaction.originalMessage
|
||||
threadId = reactionMessage.threadId
|
||||
|
||||
@@ -614,6 +614,29 @@ open class MessageRepositoryImpl @Inject constructor(
|
||||
|
||||
Timber.v("created message id ${message.id} from uri $messageUri")
|
||||
|
||||
// Parse outgoing reactions on the sender's own device. Sent messages don't arrive back as
|
||||
// incoming, so without this they'd never be parsed (only on a full reparse). This attaches
|
||||
// the reaction to its target locally and marks the reaction message as hidden.
|
||||
reactions.parseEmojiReaction(body)?.let { parsedReaction ->
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
realm.where(Message::class.java)
|
||||
.equalTo("id", message.id)
|
||||
.findFirst()
|
||||
?.let { savedMessage ->
|
||||
val targetMessage = reactions.findTargetMessage(
|
||||
savedMessage.threadId,
|
||||
parsedReaction.originalMessage,
|
||||
realm,
|
||||
parsedReaction.quikSenderAddress,
|
||||
parsedReaction.quikTimestamp,
|
||||
)
|
||||
realm.executeTransaction {
|
||||
reactions.saveEmojiReaction(savedMessage, parsedReaction, targetMessage, realm)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (delayMs > 0) { // if delaying
|
||||
val sendTime = (now() + delayMs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user