diff --git a/src/lib/nostr/social.ts b/src/lib/nostr/social.ts index 11f12f6..589bb5a 100644 --- a/src/lib/nostr/social.ts +++ b/src/lib/nostr/social.ts @@ -74,10 +74,11 @@ export async function fetchFollowSuggestions(myFollows: string[]): Promise<{ pub export async function fetchMentions(pubkey: string, since: number, limit = 50): Promise { const instance = getNDK(); + // Use a longer timeout for #p queries — some relays are slow to index tag lookups const events = await fetchWithTimeout( instance, { kinds: [NDKKind.Text], "#p": [pubkey], since, limit }, - FEED_TIMEOUT, + 12000, ); return Array.from(events).sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0)); } diff --git a/src/stores/notifications.ts b/src/stores/notifications.ts index 2f9b3a4..1fca5b2 100644 --- a/src/stores/notifications.ts +++ b/src/stores/notifications.ts @@ -100,10 +100,18 @@ export const useNotificationsStore = create((set, get) => ({ set({ loading: true }); try { const since = Math.floor(Date.now() / 1000) - 7 * 86400; - const events = await fetchMentions(pubkey, since, MAX_NOTIFICATIONS); - const others = events.filter((e) => e.pubkey !== pubkey); + let events = await fetchMentions(pubkey, since, MAX_NOTIFICATIONS); + let others = events.filter((e) => e.pubkey !== pubkey); debug.log("notif:fetch", events.length, "raw →", others.length, "others"); + // Retry once if empty — relays may need more time for #p tag queries + if (others.length === 0) { + await new Promise((r) => setTimeout(r, 3000)); + events = await fetchMentions(pubkey, since, MAX_NOTIFICATIONS); + others = events.filter((e) => e.pubkey !== pubkey); + debug.log("notif:fetch retry →", others.length, "others"); + } + // Don't overwrite existing notifications with empty results (relay timeout/disconnect) const { readIds, notifications: existing } = get(); if (others.length === 0 && existing.length > 0) {