From 636ceacdad447ce15b7d51025671837c86afeec9 Mon Sep 17 00:00:00 2001 From: codytseng Date: Thu, 24 Jul 2025 22:57:49 +0800 Subject: [PATCH] fix: prevent frequent requests for signing seen notifications events --- src/providers/NostrProvider/index.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/providers/NostrProvider/index.tsx b/src/providers/NostrProvider/index.tsx index 1b4a49f3..85383779 100644 --- a/src/providers/NostrProvider/index.tsx +++ b/src/providers/NostrProvider/index.tsx @@ -67,6 +67,8 @@ type TNostrContext = { const NostrContext = createContext(undefined) +let lastPublishedSeenNotificationsAtEventAt = -1 + export const useNostr = () => { const context = useContext(NostrContext) if (!context) { @@ -682,7 +684,15 @@ export function NostrProvider({ children }: { children: React.ReactNode }) { setTimeout(() => { setNotificationsSeenAt(now) }, 5_000) - await publish(createSeenNotificationsAtDraftEvent()) + + // Prevent too frequent requests for signing seen notifications events + if ( + lastPublishedSeenNotificationsAtEventAt < 0 || + now - lastPublishedSeenNotificationsAtEventAt > 10 * 60 // 10 minutes + ) { + await publish(createSeenNotificationsAtDraftEvent()) + lastPublishedSeenNotificationsAtEventAt = now + } } return (