mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-12 08:27:27 +02:00
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:
@@ -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) => {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -64,6 +64,7 @@ export interface ConversationMetadata {
|
||||
// NIP-17 DM
|
||||
encrypted?: boolean;
|
||||
giftWrapped?: boolean;
|
||||
dmRelays?: string[]; // DM inbox relays for the conversation
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user