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:
@@ -772,14 +772,18 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
.show()
|
||||
})
|
||||
|
||||
// Anchor near the long-pressed message if its view is on screen, else the message list
|
||||
// Anchor above the long-pressed message if its view is on screen; else center on the list
|
||||
val position = messageAdapter.data?.second?.indexOfLast { it.id == messageId } ?: -1
|
||||
val anchor = position
|
||||
val messageView = position
|
||||
.takeIf { it != -1 }
|
||||
?.let { binding.messageList.layoutManager?.findViewByPosition(it) }
|
||||
?: binding.messageList
|
||||
|
||||
popup.showAtLocation(anchor, Gravity.CENTER, 0, 0)
|
||||
if (messageView != null) {
|
||||
row.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
|
||||
popup.showAsDropDown(messageView, 0, -(messageView.height + row.measuredHeight))
|
||||
} else {
|
||||
popup.showAtLocation(binding.messageList, Gravity.CENTER, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
|
||||
@@ -766,12 +766,17 @@ class ComposeViewModel @Inject constructor(
|
||||
.mapNotNull { messageId -> messageRepo.getMessage(messageId) }
|
||||
.withLatestFrom(conversation) { message, conv ->
|
||||
message.emojiReactions.map { reaction ->
|
||||
val contactName = conv.recipients
|
||||
.firstOrNull { recipient ->
|
||||
phoneNumberUtils.compare(recipient.address, reaction.senderAddress)
|
||||
}
|
||||
?.getDisplayName()
|
||||
?: reaction.senderAddress
|
||||
val contactName = when {
|
||||
// our own reactions are stored against our own number, so show "Me"
|
||||
messageRepo.getMessage(reaction.reactionMessageId)?.isMe() == true ->
|
||||
context.getString(R.string.compose_reaction_me)
|
||||
else -> conv.recipients
|
||||
.firstOrNull { recipient ->
|
||||
phoneNumberUtils.compare(recipient.address, reaction.senderAddress)
|
||||
}
|
||||
?.getDisplayName()
|
||||
?: reaction.senderAddress
|
||||
}
|
||||
"${reaction.emoji} $contactName"
|
||||
}
|
||||
}
|
||||
@@ -787,28 +792,30 @@ class ComposeViewModel @Inject constructor(
|
||||
// message comes back to this device and is parsed as a reaction (isEmojiReaction = true),
|
||||
// so it is hidden from the conversation automatically.
|
||||
view.sendReactionIntent
|
||||
// permission checks touch the UI, so keep them on the main thread
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.filter {
|
||||
when {
|
||||
!permissionManager.isDefaultSms() -> { view.requestDefaultSms(); false }
|
||||
!permissionManager.hasSendSms() -> { view.requestSmsPermission(); false }
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
// sending and realm access happen off the main thread
|
||||
.observeOn(Schedulers.io())
|
||||
.withLatestFrom(state, conversation) { pair, state, conversation ->
|
||||
Triple(pair, state, conversation)
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { (pair, state, conversation) ->
|
||||
if (!permissionManager.isDefaultSms()) {
|
||||
view.requestDefaultSms()
|
||||
return@subscribe
|
||||
}
|
||||
if (!permissionManager.hasSendSms()) {
|
||||
view.requestSmsPermission()
|
||||
return@subscribe
|
||||
}
|
||||
|
||||
val (messageId, emoji) = pair
|
||||
val targetMessage = messageRepo.getMessage(messageId) ?: return@subscribe
|
||||
val addresses = conversation.recipients.map { it.address }
|
||||
if (addresses.isEmpty()) return@subscribe
|
||||
|
||||
val subId = state.subscription?.subscriptionId ?: -1
|
||||
val sendAsGroup = (addresses.size > 1) && state.sendAsGroup
|
||||
// always send a group reaction in a group thread so it reaches everyone
|
||||
val sendAsGroup = addresses.size > 1
|
||||
val body = reactions.buildReactionBody(emoji, targetMessage)
|
||||
|
||||
messageRepo.sendNewMessages(subId, addresses, body, emptyList(), sendAsGroup)
|
||||
|
||||
Reference in New Issue
Block a user