From 2e4602e973e9a64e84c5f9912730027c252799be Mon Sep 17 00:00:00 2001 From: codytseng Date: Wed, 21 May 2025 21:53:42 +0800 Subject: [PATCH] fix: attempt to resolve notification indicator issue --- src/providers/NostrProvider/index.tsx | 10 +++++++--- src/providers/NotificationProvider.tsx | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/providers/NostrProvider/index.tsx b/src/providers/NostrProvider/index.tsx index dd04b181..43bfe65d 100644 --- a/src/providers/NostrProvider/index.tsx +++ b/src/providers/NostrProvider/index.tsx @@ -130,6 +130,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) { setProfileEvent(null) setNsec(null) setFavoriteRelaysEvent(null) + setNotificationsSeenAt(-1) if (!account) { return } @@ -147,6 +148,12 @@ export function NostrProvider({ children }: { children: React.ReactNode }) { } else { setNcryptsec(null) } + + const storedNotificationsSeenAt = storage.getLastReadNotificationTime(account.pubkey) + if (storedNotificationsSeenAt) { + setNotificationsSeenAt(storedNotificationsSeenAt) + } + const [ storedRelayListEvent, storedProfileEvent, @@ -251,15 +258,12 @@ export function NostrProvider({ children }: { children: React.ReactNode }) { await indexedDb.putReplaceableEvent(favoriteRelaysEvent) } - const storedNotificationsSeenAt = storage.getLastReadNotificationTime(account.pubkey) if ( notificationsSeenAtEvent && notificationsSeenAtEvent.created_at > storedNotificationsSeenAt ) { setNotificationsSeenAt(notificationsSeenAtEvent.created_at) storage.setLastReadNotificationTime(account.pubkey, notificationsSeenAtEvent.created_at) - } else { - setNotificationsSeenAt(storedNotificationsSeenAt) } client.initUserIndexFromFollowings(account.pubkey, controller.signal) diff --git a/src/providers/NotificationProvider.tsx b/src/providers/NotificationProvider.tsx index 6c776917..ce6f9bba 100644 --- a/src/providers/NotificationProvider.tsx +++ b/src/providers/NotificationProvider.tsx @@ -135,6 +135,11 @@ export function NotificationProvider({ children }: { children: React.ReactNode } const clearNewNotifications = async () => { if (!pubkey) return + if (subCloserRef.current) { + subCloserRef.current.close() + subCloserRef.current = null + } + setNewNotificationIds(new Set()) await updateNotificationsSeenAt() }