diff --git a/src/lib/notificationPoller.ts b/src/lib/notificationPoller.ts index 7af3948..d3d6efc 100644 --- a/src/lib/notificationPoller.ts +++ b/src/lib/notificationPoller.ts @@ -109,7 +109,9 @@ async function pollOnce(pubkey: string) { export function startNotificationPoller(pubkey: string) { stopNotificationPoller(); - // Run first poll after a short delay (let relays connect) + // Fetch notification counts immediately (before full poll) + useNotificationsStore.getState().fetchNotifications(pubkey).catch(() => {}); + // Run first full poll after a short delay (let relays connect) setTimeout(() => pollOnce(pubkey).catch(() => {}), 5000); intervalId = setInterval(() => pollOnce(pubkey).catch(() => {}), POLL_INTERVAL); } diff --git a/src/stores/notifications.ts b/src/stores/notifications.ts index 2e99f88..599aa05 100644 --- a/src/stores/notifications.ts +++ b/src/stores/notifications.ts @@ -74,11 +74,18 @@ export const useNotificationsStore = create((set, get) => ({ // Filter out own events — your replies shouldn't be notifications const others = events.filter((e) => e.pubkey !== pubkey); const sorted = others.sort((a, b) => (b.created_at ?? 0) - (a.created_at ?? 0)).slice(0, MAX_NOTIFICATIONS); - const { readIds } = get(); + + // Don't overwrite existing notifications with empty results (relay timeout/disconnect) + const { readIds, notifications: existing } = get(); + if (sorted.length === 0 && existing.length > 0) { + // Keep existing notifications — relay probably timed out + return; + } + const unreadCount = sorted.filter((e) => !readIds.has(e.id!)).length; set({ notifications: sorted, unreadCount }); } catch { - // Non-critical + // Non-critical — keep existing notifications on error } finally { set({ loading: false }); }