From 5b3c0dcd450e6f340aa982b49b333cf446ec5191 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 13:24:31 +0000 Subject: [PATCH] fix(dm): convert @npub mentions to nostr: URIs in NIP-17 messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NIP-17 DM composer sent the typed text verbatim, so an `@npub1…` mention went out as plain text instead of a `nostr:nprofile1…` reference. Run the message through NewMessageTagger like every other composer, but use only the rewritten content: its pTags are not added to the event, because a NIP-17 room is defined by its p-tags and tagging a mentioned user would move the message into a different conversation. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019JSYZ3DdZJXvv4vh4vw4G9 --- .../model/composer/NewMessageTaggerKeyParseTest.kt | 11 +++++++++++ .../chats/privateDM/send/ChatNewMessageViewModel.kt | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/composer/NewMessageTaggerKeyParseTest.kt b/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/composer/NewMessageTaggerKeyParseTest.kt index 582c55e918..d5c6bea949 100644 --- a/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/composer/NewMessageTaggerKeyParseTest.kt +++ b/commons/src/jvmTest/kotlin/com/vitorpamplona/amethyst/commons/model/composer/NewMessageTaggerKeyParseTest.kt @@ -209,4 +209,15 @@ class NewMessageTaggerKeyParseTest { assertTrue(tagger.message.startsWith("hi nostr:nprofile1")) } + + @Test + fun possessiveAtMentionBecomesNostrUri() = + runBlocking { + val npub = "npub19ma2w9dmk3kat0nt0k5dwuqzvmg3va9ezwup0zkakhpwv0vcwvcsg8axkl" + val tagger = NewMessageTagger(message = "@$npub's ERP screens look good", dao = dao) + tagger.run() + + val nprofile = tagger.pTags!!.single().toNProfile() + assertEquals("nostr:$nprofile's ERP screens look good", tagger.message) + } } diff --git a/commonsUI/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt b/commonsUI/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt index b99fa90af4..aad92f05f9 100644 --- a/commonsUI/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt +++ b/commonsUI/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt @@ -603,7 +603,13 @@ class ChatNewMessageViewModel : ) { val room = room.value ?: return - val messageText = message.text.toString() + // Rewrites typed `@npub…`/`note1…` references into `nostr:` URIs. Only the rewritten text is + // used: the tagger's pTags must NOT reach the event, since a NIP-17 room is defined by its + // p-tags — adding a mentioned user would send the message to a different conversation. + val tagger = NewMessageTagger(message.text.toString(), null, null, accountViewModel) + tagger.run() + + val messageText = tagger.message val urls = findURLs(messageText) val usedAttachments = iMetaAttachments.filterIsIn(urls.toSet()) val emojis = accountViewModel.account.emoji.findEmojiTags(messageText)