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)