about summary refs log tree commit diff
path: root/src/state/queries/notifications/unread.tsx
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2024-01-04 17:36:27 -0800
committerGitHub <noreply@github.com>2024-01-04 17:36:27 -0800
commitdb62f272412df2c34e1a57200291b53fa1cd07aa (patch)
treea3944eed82535671bd41d6e2234dbc78ef4aa4c7 /src/state/queries/notifications/unread.tsx
parent8a4a8af61c47ba315bcf39d6170825e316bfd241 (diff)
downloadvoidsky-db62f272412df2c34e1a57200291b53fa1cd07aa.tar.zst
Reduce web requests (#2420)
* Stop auto-refetching app passwords and invites on an interval

* Don't poll for posts or notifs if the app/tab isnt focused
Diffstat (limited to 'src/state/queries/notifications/unread.tsx')
-rw-r--r--src/state/queries/notifications/unread.tsx4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/state/queries/notifications/unread.tsx b/src/state/queries/notifications/unread.tsx
index abaabbf0e..d604e8fe0 100644
--- a/src/state/queries/notifications/unread.tsx
+++ b/src/state/queries/notifications/unread.tsx
@@ -15,6 +15,7 @@ import {useMutedThreads} from '#/state/muted-threads'
 import {RQKEY as RQKEY_NOTIFS} from './feed'
 import {logger} from '#/logger'
 import {truncateAndInvalidate} from '../util'
+import {AppState} from 'react-native'
 
 const UPDATE_INTERVAL = 30 * 1e3 // 30sec
 
@@ -97,6 +98,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
       async checkUnread({invalidate}: {invalidate?: boolean} = {}) {
         try {
           if (!getAgent().session) return
+          if (AppState.currentState !== 'active') {
+            return
+          }
 
           // count
           const page = await fetchPage({