feat(desktop): wire NIP-17 emoji reactions in DM chat
Replace TODO stub with sendWrappedReaction using NIP17Factory. createReactionWithinGroup creates gift-wrapped reactions for group privacy. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+36
-10
@@ -85,6 +85,8 @@ import com.vitorpamplona.amethyst.commons.ui.feeds.FeedState
|
|||||||
import com.vitorpamplona.amethyst.commons.util.toTimeAgo
|
import com.vitorpamplona.amethyst.commons.util.toTimeAgo
|
||||||
import com.vitorpamplona.amethyst.commons.viewmodels.ChatNewMessageState
|
import com.vitorpamplona.amethyst.commons.viewmodels.ChatNewMessageState
|
||||||
import com.vitorpamplona.amethyst.commons.viewmodels.ChatroomFeedViewModel
|
import com.vitorpamplona.amethyst.commons.viewmodels.ChatroomFeedViewModel
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle
|
||||||
|
import com.vitorpamplona.quartz.nip17Dm.NIP17Factory
|
||||||
import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKey
|
import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKey
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@@ -185,6 +187,11 @@ fun ChatPane(
|
|||||||
account = account,
|
account = account,
|
||||||
cacheProvider = cacheProvider,
|
cacheProvider = cacheProvider,
|
||||||
onAuthorClick = onNavigateToProfile,
|
onAuthorClick = onNavigateToProfile,
|
||||||
|
onReaction = { note, emoji ->
|
||||||
|
scope.launch {
|
||||||
|
sendWrappedReaction(note, emoji, roomKey, account)
|
||||||
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,6 +362,34 @@ private fun MessageWithReactions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a NIP-17 gift-wrapped reaction to a note within a group DM.
|
||||||
|
*/
|
||||||
|
private suspend fun sendWrappedReaction(
|
||||||
|
note: Note,
|
||||||
|
emoji: String,
|
||||||
|
roomKey: ChatroomKey,
|
||||||
|
account: IAccount,
|
||||||
|
) {
|
||||||
|
val event = note.event ?: return
|
||||||
|
val eventBundle = EventHintBundle(event)
|
||||||
|
val recipients = roomKey.users.toList()
|
||||||
|
|
||||||
|
val result =
|
||||||
|
NIP17Factory().createReactionWithinGroup(
|
||||||
|
content = emoji,
|
||||||
|
originalNote = eventBundle,
|
||||||
|
to = recipients,
|
||||||
|
signer = account.signer,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send each gift wrap as a NIP-17 message
|
||||||
|
result.wraps.forEach { wrap ->
|
||||||
|
// Broadcast through the account's NIP-17 send path
|
||||||
|
// The wraps are already gift-wrapped, so we broadcast directly
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Floating row of quick emoji reaction buttons.
|
* Floating row of quick emoji reaction buttons.
|
||||||
*/
|
*/
|
||||||
@@ -372,16 +407,7 @@ private fun ReactionBar(onReaction: (String) -> Unit) {
|
|||||||
) {
|
) {
|
||||||
QUICK_REACTIONS.forEach { emoji ->
|
QUICK_REACTIONS.forEach { emoji ->
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = { onReaction(emoji) },
|
||||||
// TODO: Wire up NIP17Factory.createReactionWithinGroup to send
|
|
||||||
// the reaction via gift-wrapped NIP-17. Requires:
|
|
||||||
// 1. Get the note's event as EventHintBundle
|
|
||||||
// 2. Get the room participants as List<HexKey>
|
|
||||||
// 3. Get the NostrSigner from the account
|
|
||||||
// 4. Call NIP17Factory().createReactionWithinGroup(emoji, eventBundle, participants, signer)
|
|
||||||
// 5. Broadcast the resulting wraps via relay manager
|
|
||||||
onReaction(emoji)
|
|
||||||
},
|
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
contentPadding =
|
contentPadding =
|
||||||
androidx.compose.foundation.layout
|
androidx.compose.foundation.layout
|
||||||
|
|||||||
Reference in New Issue
Block a user