diff options
author | dan <dan.abramov@gmail.com> | 2024-04-12 19:33:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-12 11:33:34 -0700 |
commit | 835f2e6548a9a55fded1f506b17692154a07caab (patch) | |
tree | 9988400824e6e7ae509ce023d0a56b9994a5ac8c /src/state/queries/notifications/unread.tsx | |
parent | 14208eef11b1598af7b9bfc855e608c231850d4d (diff) | |
download | voidsky-835f2e6548a9a55fded1f506b17692154a07caab.tar.zst |
Fix stale Notifications after push (#3507)
Diffstat (limited to 'src/state/queries/notifications/unread.tsx')
-rw-r--r-- | src/state/queries/notifications/unread.tsx | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/state/queries/notifications/unread.tsx b/src/state/queries/notifications/unread.tsx index e7a0631ec..1c01d71a5 100644 --- a/src/state/queries/notifications/unread.tsx +++ b/src/state/queries/notifications/unread.tsx @@ -3,24 +3,28 @@ */ import React from 'react' +import {AppState} from 'react-native' import * as Notifications from 'expo-notifications' import {useQueryClient} from '@tanstack/react-query' +import EventEmitter from 'eventemitter3' + import BroadcastChannel from '#/lib/broadcast' -import {useSession, getAgent} from '#/state/session' -import {useModerationOpts} from '../preferences' -import {fetchPage} from './util' -import {CachedFeedPage, FeedPage} from './types' +import {logger} from '#/logger' import {isNative} from '#/platform/detection' import {useMutedThreads} from '#/state/muted-threads' -import {RQKEY as RQKEY_NOTIFS} from './feed' -import {logger} from '#/logger' +import {getAgent, useSession} from '#/state/session' +import {useModerationOpts} from '../preferences' import {truncateAndInvalidate} from '../util' -import {AppState} from 'react-native' +import {RQKEY as RQKEY_NOTIFS} from './feed' +import {CachedFeedPage, FeedPage} from './types' +import {fetchPage} from './util' const UPDATE_INTERVAL = 30 * 1e3 // 30sec const broadcast = new BroadcastChannel('NOTIFS_BROADCAST_CHANNEL') +const emitter = new EventEmitter() + type StateContext = string interface ApiContext { @@ -56,6 +60,18 @@ export function Provider({children}: React.PropsWithChildren<{}>) { unreadCount: 0, }) + React.useEffect(() => { + function markAsUnusable() { + if (cacheRef.current) { + cacheRef.current.usableInFeed = false + } + } + emitter.addListener('invalidate', markAsUnusable) + return () => { + emitter.removeListener('invalidate', markAsUnusable) + } + }, []) + // periodic sync React.useEffect(() => { if (!hasSession || !checkUnreadRef.current) { @@ -214,3 +230,7 @@ function countUnread(page: FeedPage) { } return num } + +export function invalidateCachedUnreadPage() { + emitter.emit('invalidate') +} |