fix(dm): convert @npub mentions to nostr: URIs in NIP-17 messages

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019JSYZ3DdZJXvv4vh4vw4G9
This commit is contained in:
Claude
2026-10-02 13:24:31 +00:00
parent 6524130fbf
commit 5b3c0dcd45
2 changed files with 18 additions and 1 deletions
@@ -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)
}
}
@@ -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)