dm: focus the selected recipient instead of the top conversation

Clicking "Message" on a profile (or selecting anyone you'd never DMed) set the
recipient, but buildDmConversationData discarded it: a recipient with no
existing thread wasn't in conversationMap, so it fell back to conversations[0]
(the top conversation). The inbox silently jumped to the top thread, and any
message sent then went to the wrong person ("says sent but I don't see it").

Fixes:
- setDirectMessageRecipient now focuses the selected recipient's conversation
  so a stale activeDmConversationId can't win.
- buildDmConversationData synthesizes an empty conversation for a
  selected-but-threadless recipient and treats it as active, including an
  activeRemotePubkey fallback so the composer targets the right person.
- The legacy renderProfileMessages list no longer clobbers a non-null
  recipient with threadsToRender[0].

Regression: tests/ui/dm-conversation-focus.test.mjs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
thePR0M3TH3ANandClaude Opus 4.8 committed 2026-06-23 20:37:30 -04:00
1 parent 4f7baa3e99
commit d29287a580
5 files changed
+193 -11

No files matched your search

@@ -635,13 +635,49 @@ export class ProfileDirectMessageHelper {
storedRecipient && actor
? this.buildDmConversationId(actor, storedRecipient)
: "";
// If a recipient is explicitly selected but has no existing thread yet
// (e.g. the "Message" button on the profile of someone you've never DMed),
// synthesize an empty conversation so the UI focuses THEM. Without this the
// selected recipient falls through to fallbackConversationId and the inbox
// silently jumps to the top conversation — and any message you send goes to
// the wrong person.
if (
storedRecipient &&
storedConversationId &&
!conversationMap.has(storedConversationId) &&
!isRemoteBlocked(storedRecipient)
) {
const summary = this.resolveProfileSummaryForPubkey(storedRecipient);
const recipientContext = this.buildDmRecipientContext(storedRecipient);
conversations.unshift({
id: storedConversationId,
name: summary.displayName,
preview: "No messages yet",
timestamp: "",
unreadCount: 0,
avatarSrc: summary.avatarSrc,
status: summary.status,
pubkey: storedRecipient,
lightningAddress: summary.lightningAddress,
relayHints: Array.isArray(recipientContext?.relayHints)
? recipientContext.relayHints
: [],
});
}
const preferredConversationId =
this.controller.activeDmConversationId || storedConversationId;
const fallbackConversationId = conversations[0]?.id || "";
const activeConversationId =
preferredConversationId && conversationMap.has(preferredConversationId)
? preferredConversationId
: fallbackConversationId;
// A selected recipient with no messages yet won't be in conversationMap, but
// it IS a valid focus target (storedConversationId / the synthetic entry).
const preferredIsSelectable =
preferredConversationId &&
(conversationMap.has(preferredConversationId) ||
preferredConversationId === storedConversationId);
const activeConversationId = preferredIsSelectable
? preferredConversationId
: fallbackConversationId;
const activeThread = activeConversationId
? conversationMap.get(activeConversationId)
: null;
@@ -649,7 +685,11 @@ export class ProfileDirectMessageHelper {
activeThread?.remoteHex ||
(activeConversationId
? this.resolveRemoteForConversationId(activeConversationId, actor)
: storedRecipient) ||
: null) ||
// A freshly-selected recipient has no messages, so it can't be resolved
// from the cache above — fall back to the stored recipient for the
// synthetic conversation so the composer targets the right person.
(activeConversationId === storedConversationId ? storedRecipient : null) ||
null;
if (activeConversationId && this.controller.activeDmConversationId !== activeConversationId) {