mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-12 16:37:06 +02:00
fix: Actively fetch own inbox relays for self-chat in NIP-17
Previously, self-chat relied on giftWrapService.inboxRelays$.value being populated, but if empty, self-chat would show 0 relays and fail to send messages. This fix actively fetches own inbox relays using fetchInboxRelays(activePubkey) for self-chat, ensuring inbox relays are always populated and self-chat works correctly. Changes: - Detect self-chat and actively fetch own inbox relays - For non-self-chat, use cached value first (optimization) - Store fetched relays in userInboxRelays variable for metadata - Add logging for self-chat relay fetch status Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -459,11 +459,28 @@ export class Nip17Adapter extends ChatProtocolAdapter {
|
||||
|
||||
// Fetch inbox relays for all participants
|
||||
const participantInboxRelays: Record<string, string[]> = {};
|
||||
let userInboxRelays: string[] = [];
|
||||
|
||||
// Current user's relays (already loaded)
|
||||
const userRelays = giftWrapService.inboxRelays$.value;
|
||||
if (userRelays.length > 0) {
|
||||
participantInboxRelays[activePubkey] = userRelays;
|
||||
// For self-chat, actively fetch own inbox relays to ensure they're populated
|
||||
// For other chats, try cached value first (optimization)
|
||||
if (isSelfChat) {
|
||||
const ownRelays = await fetchInboxRelays(activePubkey);
|
||||
if (ownRelays.length > 0) {
|
||||
participantInboxRelays[activePubkey] = ownRelays;
|
||||
userInboxRelays = ownRelays;
|
||||
console.log(
|
||||
`[NIP-17] ✅ Fetched own inbox relays for self-chat: ${ownRelays.length} relays`,
|
||||
);
|
||||
} else {
|
||||
console.warn(`[NIP-17] ⚠️ Could not find inbox relays for self-chat`);
|
||||
}
|
||||
} else {
|
||||
// For non-self-chat, try cached value first
|
||||
const userRelays = giftWrapService.inboxRelays$.value;
|
||||
if (userRelays.length > 0) {
|
||||
participantInboxRelays[activePubkey] = userRelays;
|
||||
userInboxRelays = userRelays;
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch for other participants in parallel
|
||||
@@ -498,7 +515,7 @@ export class Nip17Adapter extends ChatProtocolAdapter {
|
||||
metadata: {
|
||||
encrypted: true,
|
||||
giftWrapped: true,
|
||||
inboxRelays: userRelays,
|
||||
inboxRelays: userInboxRelays,
|
||||
participantInboxRelays,
|
||||
// Flag if some participants have no inbox relays (can't send to them)
|
||||
unreachableParticipants:
|
||||
|
||||
Reference in New Issue
Block a user