mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix stale Notifications after push (#3507)

authored by danabra.mov and committed by

GitHub 835f2e65 14208eef

+31 -7
+4
src/lib/notifications/notifications.ts
··· 4 4 5 5 import {logger} from '#/logger' 6 6 import {RQKEY as RQKEY_NOTIFS} from '#/state/queries/notifications/feed' 7 + import {invalidateCachedUnreadPage} from '#/state/queries/notifications/unread' 7 8 import {truncateAndInvalidate} from '#/state/queries/util' 8 9 import {getAgent, SessionAccount} from '#/state/session' 9 10 import {track} from 'lib/analytics/analytics' ··· 87 88 // handle notifications that are received, both in the foreground or background 88 89 // NOTE: currently just here for debug logging 89 90 const sub1 = Notifications.addNotificationReceivedListener(event => { 91 + invalidateCachedUnreadPage() 90 92 logger.debug( 91 93 'Notifications: received', 92 94 {event}, ··· 131 133 ) 132 134 track('Notificatons:OpenApp') 133 135 logEvent('notifications:openApp', {}) 136 + invalidateCachedUnreadPage() 134 137 truncateAndInvalidate(queryClient, RQKEY_NOTIFS()) 135 138 resetToTab('NotificationsTab') // open notifications tab 136 139 } 137 140 }, 138 141 ) 142 + 139 143 return () => { 140 144 sub1.remove() 141 145 sub2.remove()
+27 -7
src/state/queries/notifications/unread.tsx
··· 3 3 */ 4 4 5 5 import React from 'react' 6 + import {AppState} from 'react-native' 6 7 import * as Notifications from 'expo-notifications' 7 8 import {useQueryClient} from '@tanstack/react-query' 9 + import EventEmitter from 'eventemitter3' 10 + 8 11 import BroadcastChannel from '#/lib/broadcast' 9 - import {useSession, getAgent} from '#/state/session' 10 - import {useModerationOpts} from '../preferences' 11 - import {fetchPage} from './util' 12 - import {CachedFeedPage, FeedPage} from './types' 12 + import {logger} from '#/logger' 13 13 import {isNative} from '#/platform/detection' 14 14 import {useMutedThreads} from '#/state/muted-threads' 15 - import {RQKEY as RQKEY_NOTIFS} from './feed' 16 - import {logger} from '#/logger' 15 + import {getAgent, useSession} from '#/state/session' 16 + import {useModerationOpts} from '../preferences' 17 17 import {truncateAndInvalidate} from '../util' 18 - import {AppState} from 'react-native' 18 + import {RQKEY as RQKEY_NOTIFS} from './feed' 19 + import {CachedFeedPage, FeedPage} from './types' 20 + import {fetchPage} from './util' 19 21 20 22 const UPDATE_INTERVAL = 30 * 1e3 // 30sec 21 23 22 24 const broadcast = new BroadcastChannel('NOTIFS_BROADCAST_CHANNEL') 25 + 26 + const emitter = new EventEmitter() 23 27 24 28 type StateContext = string 25 29 ··· 55 59 data: undefined, 56 60 unreadCount: 0, 57 61 }) 62 + 63 + React.useEffect(() => { 64 + function markAsUnusable() { 65 + if (cacheRef.current) { 66 + cacheRef.current.usableInFeed = false 67 + } 68 + } 69 + emitter.addListener('invalidate', markAsUnusable) 70 + return () => { 71 + emitter.removeListener('invalidate', markAsUnusable) 72 + } 73 + }, []) 58 74 59 75 // periodic sync 60 76 React.useEffect(() => { ··· 214 230 } 215 231 return num 216 232 } 233 + 234 + export function invalidateCachedUnreadPage() { 235 + emitter.emit('invalidate') 236 + }