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>2023-11-16 18:26:22 -0800
committerGitHub <noreply@github.com>2023-11-16 18:26:22 -0800
commit357c752a213dbcf77e5333fa180cfef20a33842d (patch)
treee955e57cc1252b5fe759cde29185d62bb71bc339 /src/state/queries/notifications/unread.tsx
parent3043b324681f1702ca53831701fb5cecd14c0efb (diff)
downloadvoidsky-357c752a213dbcf77e5333fa180cfef20a33842d.tar.zst
Move the current agent to a global and reset RQ queries on agent change (#1946)
Diffstat (limited to 'src/state/queries/notifications/unread.tsx')
-rw-r--r--src/state/queries/notifications/unread.tsx12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/state/queries/notifications/unread.tsx b/src/state/queries/notifications/unread.tsx
index 91aa6f3c2..80b12112e 100644
--- a/src/state/queries/notifications/unread.tsx
+++ b/src/state/queries/notifications/unread.tsx
@@ -1,7 +1,7 @@
 import React from 'react'
 import * as Notifications from 'expo-notifications'
 import BroadcastChannel from '#/lib/broadcast'
-import {useSession} from '#/state/session'
+import {useSession, getAgent} from '#/state/session'
 import {useModerationOpts} from '../preferences'
 import {shouldFilterNotif} from './util'
 import {isNative} from '#/platform/detection'
@@ -25,7 +25,7 @@ const apiContext = React.createContext<ApiContext>({
 })
 
 export function Provider({children}: React.PropsWithChildren<{}>) {
-  const {hasSession, agent} = useSession()
+  const {hasSession} = useSession()
   const moderationOpts = useModerationOpts()
 
   const [numUnread, setNumUnread] = React.useState('')
@@ -60,7 +60,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
     return {
       async markAllRead() {
         // update server
-        await agent.updateSeenNotifications(lastSyncRef.current.toISOString())
+        await getAgent().updateSeenNotifications(
+          lastSyncRef.current.toISOString(),
+        )
 
         // update & broadcast
         setNumUnread('')
@@ -69,7 +71,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
 
       async checkUnread() {
         // count
-        const res = await agent.listNotifications({limit: 40})
+        const res = await getAgent().listNotifications({limit: 40})
         const filtered = res.data.notifications.filter(
           notif => !notif.isRead && !shouldFilterNotif(notif, moderationOpts),
         )
@@ -94,7 +96,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
         broadcast.postMessage({event: num})
       },
     }
-  }, [setNumUnread, agent, moderationOpts])
+  }, [setNumUnread, moderationOpts])
   checkUnreadRef.current = api.checkUnread
 
   return (