diff options
Diffstat (limited to 'src/state/queries/notifications')
-rw-r--r-- | src/state/queries/notifications/feed.ts | 4 | ||||
-rw-r--r-- | src/state/queries/notifications/unread.tsx | 10 | ||||
-rw-r--r-- | src/state/queries/notifications/util.ts | 14 |
3 files changed, 13 insertions, 15 deletions
diff --git a/src/state/queries/notifications/feed.ts b/src/state/queries/notifications/feed.ts index 80e5a4c47..523af2824 100644 --- a/src/state/queries/notifications/feed.ts +++ b/src/state/queries/notifications/feed.ts @@ -47,7 +47,7 @@ export function RQKEY() { } export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { - const {getAgent} = useAgent() + const agent = useAgent() const queryClient = useQueryClient() const moderationOpts = useModerationOpts() const threadMutes = useMutedThreads() @@ -73,7 +73,7 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { if (!page) { page = ( await fetchPage({ - getAgent, + agent, limit: PAGE_SIZE, cursor: pageParam, queryClient, diff --git a/src/state/queries/notifications/unread.tsx b/src/state/queries/notifications/unread.tsx index acc68c360..5f33cdf74 100644 --- a/src/state/queries/notifications/unread.tsx +++ b/src/state/queries/notifications/unread.tsx @@ -45,7 +45,7 @@ const apiContext = React.createContext<ApiContext>({ export function Provider({children}: React.PropsWithChildren<{}>) { const {hasSession} = useSession() - const {getAgent} = useAgent() + const agent = useAgent() const queryClient = useQueryClient() const moderationOpts = useModerationOpts() const threadMutes = useMutedThreads() @@ -112,7 +112,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { return { async markAllRead() { // update server - await getAgent().updateSeenNotifications( + await agent.updateSeenNotifications( cacheRef.current.syncedAt.toISOString(), ) @@ -127,7 +127,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { isPoll, }: {invalidate?: boolean; isPoll?: boolean} = {}) { try { - if (!getAgent().session) return + if (!agent.session) return if (AppState.currentState !== 'active') { return } @@ -142,7 +142,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { // count const {page, indexedAt: lastIndexed} = await fetchPage({ - getAgent, + agent, cursor: undefined, limit: 40, queryClient, @@ -192,7 +192,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { } }, } - }, [setNumUnread, queryClient, moderationOpts, threadMutes, getAgent]) + }, [setNumUnread, queryClient, moderationOpts, threadMutes, agent]) checkUnreadRef.current = api.checkUnread return ( diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts index 5029a33cc..ebcdff686 100644 --- a/src/state/queries/notifications/util.ts +++ b/src/state/queries/notifications/util.ts @@ -23,7 +23,7 @@ const MS_2DAY = MS_1HR * 48 // = export async function fetchPage({ - getAgent, + agent, cursor, limit, queryClient, @@ -31,7 +31,7 @@ export async function fetchPage({ threadMutes, fetchAdditionalData, }: { - getAgent: () => BskyAgent + agent: BskyAgent cursor: string | undefined limit: number queryClient: QueryClient @@ -39,7 +39,7 @@ export async function fetchPage({ threadMutes: string[] fetchAdditionalData: boolean }): Promise<{page: FeedPage; indexedAt: string | undefined}> { - const res = await getAgent().listNotifications({ + const res = await agent.listNotifications({ limit, cursor, }) @@ -56,7 +56,7 @@ export async function fetchPage({ // we fetch subjects of notifications (usually posts) now instead of lazily // in the UI to avoid relayouts if (fetchAdditionalData) { - const subjects = await fetchSubjects(getAgent, notifsGrouped) + const subjects = await fetchSubjects(agent, notifsGrouped) for (const notif of notifsGrouped) { if (notif.subjectUri) { notif.subject = subjects.get(notif.subjectUri) @@ -140,7 +140,7 @@ export function groupNotifications( } async function fetchSubjects( - getAgent: () => BskyAgent, + agent: BskyAgent, groupedNotifs: FeedNotification[], ): Promise<Map<string, AppBskyFeedDefs.PostView>> { const uris = new Set<string>() @@ -152,9 +152,7 @@ async function fetchSubjects( const uriChunks = chunk(Array.from(uris), 25) const postsChunks = await Promise.all( uriChunks.map(uris => - getAgent() - .app.bsky.feed.getPosts({uris}) - .then(res => res.data.posts), + agent.app.bsky.feed.getPosts({uris}).then(res => res.data.posts), ), ) const map = new Map<string, AppBskyFeedDefs.PostView>() |