mirror of
https://github.com/hoornet/vega.git
synced 2026-05-06 12:19:11 -07:00
Fix notification badges disappearing on relay timeout
Don't overwrite existing notifications with empty results when relay times out or disconnects. Also fetch notification counts immediately on startup instead of waiting for the first poll cycle.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -74,11 +74,18 @@ export const useNotificationsStore = create<NotificationsState>((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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user