feat: show DM relays in NIP-17 chat RelaysDropdown

- Added dmRelays field to ConversationMetadata type
- NIP-17 adapter now includes combined relays from both participants
- RelaysDropdown checks for dmRelays in addition to liveActivity/relayUrl
This commit is contained in:
Claude
2026-01-12 22:02:23 +00:00
parent 35623cfbf3
commit db2df8014d
3 changed files with 13 additions and 4 deletions

View File

@@ -22,13 +22,17 @@ export function RelaysDropdown({ conversation }: RelaysDropdownProps) {
const { relays: relayStates } = useRelayState();
// Get relays for this conversation (immutable pattern)
// Priority: liveActivity relays > dmRelays > single relayUrl
const liveActivityRelays = conversation.metadata?.liveActivity?.relays;
const dmRelays = conversation.metadata?.dmRelays;
const relays: string[] =
Array.isArray(liveActivityRelays) && liveActivityRelays.length > 0
? liveActivityRelays
: conversation.metadata?.relayUrl
? [conversation.metadata.relayUrl]
: [];
: Array.isArray(dmRelays) && dmRelays.length > 0
? dmRelays
: conversation.metadata?.relayUrl
? [conversation.metadata.relayUrl]
: [];
// Pre-compute normalized URLs and state lookups in a single pass (O(n))
const relayData = relays.map((url) => {

View File

@@ -163,11 +163,14 @@ export class Nip17Adapter extends ChatProtocolAdapter {
// Fetch DM relays for both parties in parallel
// (for self-chat, this fetches the same relays twice but that's fine)
await Promise.all([
const [ownRelays, partnerRelays] = await Promise.all([
this.fetchDmRelays(activePubkey),
this.fetchDmRelays(partnerPubkey),
]);
// Combine and deduplicate relays from both parties
const allRelays = [...new Set([...ownRelays, ...partnerRelays])];
// Get display name for partner (the person we're chatting with)
const metadataEvent = await this.getMetadata(partnerPubkey);
const metadata = metadataEvent
@@ -187,6 +190,7 @@ export class Nip17Adapter extends ChatProtocolAdapter {
metadata: {
encrypted: true,
giftWrapped: true,
dmRelays: allRelays,
},
unreadCount: 0,
};

View File

@@ -64,6 +64,7 @@ export interface ConversationMetadata {
// NIP-17 DM
encrypted?: boolean;
giftWrapped?: boolean;
dmRelays?: string[]; // DM inbox relays for the conversation
}
/**