feat(reactions): send emoji reactions via quik-encoded SMS/MMS

Long-press a message to open an emoji reaction picker. Reactions are
sent as a plain SMS/MMS body using a quik-specific zero-width encoding
that carries the original sender's address and the message's timestamp,
so a receiving quik instance can attach the reaction to the exact
message via address + date lookup (fast path), falling back to the
existing text matching for non-quik senders.

The quik pattern is registered first so it wins over the generic Google
Messages pattern; iOS/Google parsing is unchanged. New ParsedEmojiReaction
fields are in-memory only, so no Realm migration is needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
octoshrimpy
2026-06-14 10:53:05 -04:00
parent a88d5c62e0
commit d0d3501a83
9 changed files with 193 additions and 8 deletions
@@ -42,8 +42,14 @@ import android.view.DragEvent.ACTION_DRAG_EXITED
import android.view.DragEvent.ACTION_DROP
import android.view.Menu
import android.view.MenuItem
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.PopupWindow
import android.widget.SeekBar
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.constraintlayout.widget.ConstraintSet
@@ -141,6 +147,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
override val clearCurrentMessageIntent: Subject<Boolean> = PublishSubject.create()
override val messageLinkAskIntent: Subject<Uri> by lazy { messageAdapter.messageLinkClicks }
override val reactionClickIntent: Subject<Long> by lazy { messageAdapter.reactionClicks }
override val reactionPickerIntent: Observable<Long> by lazy { messageAdapter.reactionPickerIntent }
override val sendReactionIntent: Subject<Pair<Long, String>> = PublishSubject.create()
override val speechRecogniserIntent by lazy { binding.speechToTextIcon.clicks() }
override val shadeIntent by lazy { binding.shadeBackground.clicks() }
override val recordAudioStartStopRecording: Subject<Boolean> = PublishSubject.create()
@@ -716,6 +724,64 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
.show()
}
override fun showReactionPicker(messageId: Long) {
val defaultEmojis = listOf("❤️", "👍", "👎", "😂", "😮", "😢")
val pad = 12.dpToPx(this)
val row = LinearLayout(this).apply {
orientation = LinearLayout.HORIZONTAL
setPadding(pad, pad, pad, pad)
}
val popup = PopupWindow(
row,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
true
).apply {
elevation = 8.dpToPx(this@ComposeActivity).toFloat()
setBackgroundDrawable(ContextCompat.getDrawable(this@ComposeActivity, R.drawable.rounded_rectangle_4dp))
}
fun emojiView(label: String, onClick: () -> Unit) = TextView(this).apply {
text = label
textSize = 24f
gravity = Gravity.CENTER
setPadding(pad, pad / 2, pad, pad / 2)
setOnClickListener {
onClick()
popup.dismiss()
}
}
defaultEmojis.forEach { emoji ->
row.addView(emojiView(emoji) { sendReactionIntent.onNext(Pair(messageId, emoji)) })
}
// "+" opens a simple input so the user can type or paste any emoji
row.addView(emojiView("+") {
val input = EditText(this).apply { hint = getString(R.string.compose_reaction_custom_hint) }
AlertDialog.Builder(this)
.setTitle(R.string.compose_reaction_custom_title)
.setView(input)
.setPositiveButton(R.string.button_send) { _, _ ->
val emoji = input.text.toString().trim()
if (emoji.isNotEmpty()) sendReactionIntent.onNext(Pair(messageId, emoji))
}
.setNegativeButton(R.string.button_cancel, null)
.show()
})
// Anchor near the long-pressed message if its view is on screen, else the message list
val position = messageAdapter.data?.second?.indexOfLast { it.id == messageId } ?: -1
val anchor = position
.takeIf { it != -1 }
?.let { binding.messageList.layoutManager?.findViewByPosition(it) }
?: binding.messageList
popup.showAtLocation(anchor, Gravity.CENTER, 0, 0)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.compose, menu)
return super.onCreateOptionsMenu(menu)
@@ -78,6 +78,8 @@ interface ComposeView : QkView<ComposeState> {
val clearCurrentMessageIntent: Subject<Boolean>
val messageLinkAskIntent: Observable<Uri>
val reactionClickIntent: Subject<Long>
val reactionPickerIntent: Observable<Long> // message ID to react to
val sendReactionIntent: Subject<Pair<Long, String>> // (messageId, emoji)
val speechRecogniserIntent: Observable<*>
val shadeIntent: Observable<Unit>
val recordAudioStartStopRecording: Subject<Boolean>
@@ -113,6 +115,7 @@ interface ComposeView : QkView<ComposeState> {
fun showDeleteDialog( messages: List<Long>)
fun showClearCurrentMessageDialog()
fun showReactionsDialog(reactions: List<String>)
fun showReactionPicker(messageId: Long)
fun startSpeechRecognition()
fun focusMessage()
}
@@ -71,6 +71,7 @@ import dev.octoshrimpy.quik.model.Recipient
import dev.octoshrimpy.quik.model.getText
import dev.octoshrimpy.quik.repository.ContactRepository
import dev.octoshrimpy.quik.repository.ConversationRepository
import dev.octoshrimpy.quik.repository.EmojiReactionRepository
import dev.octoshrimpy.quik.repository.MessageRepository
import dev.octoshrimpy.quik.repository.ScheduledMessageRepository
import dev.octoshrimpy.quik.util.ActiveSubscriptionObservable
@@ -115,6 +116,7 @@ class ComposeViewModel @Inject constructor(
private val actionDelayedMessage: ActionDelayedMessage,
private val conversationRepo: ConversationRepository,
private val deleteMessages: DeleteMessages,
private val reactions: EmojiReactionRepository,
private val markRead: MarkRead,
private val messageDetailsFormatter: MessageDetailsFormatter,
private val messageRepo: MessageRepository,
@@ -776,6 +778,42 @@ class ComposeViewModel @Inject constructor(
.autoDisposable(view.scope())
.subscribe { reactions -> view.showReactionsDialog(reactions) }
// Long-press on a message opens the emoji reaction picker
view.reactionPickerIntent
.autoDisposable(view.scope())
.subscribe { messageId -> view.showReactionPicker(messageId) }
// Send a reaction: build a quik-encoded body and send it as a normal message. The sent
// message comes back to this device and is parsed as a reaction (isEmojiReaction = true),
// so it is hidden from the conversation automatically.
view.sendReactionIntent
.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
val body = reactions.buildReactionBody(emoji, targetMessage)
messageRepo.sendNewMessages(subId, addresses, body, emptyList(), sendAsGroup)
}
// Set the current conversation
Observables
.combineLatest(
@@ -111,6 +111,7 @@ class MessagesAdapter @Inject constructor(
val resendClicks: Subject<Long> = PublishSubject.create()
val partContextMenuRegistrar: Subject<View> = PublishSubject.create()
val reactionClicks: Subject<Long> = PublishSubject.create()
val reactionPickerIntent: Subject<Long> = PublishSubject.create()
var data: Pair<Conversation, RealmResults<Message>>? = null
set(value) {
@@ -182,8 +183,14 @@ class MessagesAdapter @Inject constructor(
}
view.setOnLongClickListener {
getItem(adapterPosition)?.let {
toggleSelection(it.id)
view.isActivated = isSelected(it.id)
// If a selection is already active, keep extending it (multi-select).
// Otherwise, long-press opens the emoji reaction picker for this message.
// Selection mode remains reachable via the toolbar (select all) once active.
if (toggleSelection(it.id, false)) {
view.isActivated = isSelected(it.id)
} else {
reactionPickerIntent.onNext(it.id)
}
}
true
}