Multiple notifications fixes (#2154)

* Dont reset notifications feed on push notification event

* Dont separate notifications by read state to avoid jank

* On notifications screen focus, check latest and only rerender if not scrolled down

* Reuse the cached notifs page when its not stale

* Bump ios build number

* Improve comments

* Change the 'mark all read' condition to avoid firing too early
This commit is contained in:
Paul Frazee 2023-12-09 15:09:31 -08:00 committed by GitHub
parent d854e88218
commit 6b3eb401b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 162 additions and 146 deletions

View file

@ -37,7 +37,7 @@ const apiContext = React.createContext<ApiContext>({
})
export function Provider({children}: React.PropsWithChildren<{}>) {
const {hasSession, currentAccount} = useSession()
const {hasSession} = useSession()
const queryClient = useQueryClient()
const moderationOpts = useModerationOpts()
const threadMutes = useMutedThreads()
@ -46,7 +46,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
const checkUnreadRef = React.useRef<ApiContext['checkUnread'] | null>(null)
const cacheRef = React.useRef<CachedFeedPage>({
sessDid: currentAccount?.did || '',
usableInFeed: false,
syncedAt: new Date(),
data: undefined,
})
@ -65,7 +65,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
React.useEffect(() => {
const listener = ({data}: MessageEvent) => {
cacheRef.current = {
sessDid: currentAccount?.did || '',
usableInFeed: false,
syncedAt: new Date(),
data: undefined,
}
@ -75,7 +75,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
return () => {
broadcast.removeEventListener('message', listener)
}
}, [setNumUnread, currentAccount])
}, [setNumUnread])
// create API
const api = React.useMemo<ApiContext>(() => {
@ -119,7 +119,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
const lastIndexed =
page.items[0] && new Date(page.items[0].notification.indexedAt)
cacheRef.current = {
sessDid: currentAccount?.did || '',
usableInFeed: !!invalidate, // will be used immediately
data: page,
syncedAt: !lastIndexed || now > lastIndexed ? now : lastIndexed,
}
@ -136,14 +136,13 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
},
getCachedUnreadPage() {
// return cached page if was for the current user
// (protects against session changes serving data from the past session)
if (cacheRef.current.sessDid === currentAccount?.did) {
// return cached page if it's marked as fresh enough
if (cacheRef.current.usableInFeed) {
return cacheRef.current.data
}
},
}
}, [setNumUnread, queryClient, moderationOpts, threadMutes, currentAccount])
}, [setNumUnread, queryClient, moderationOpts, threadMutes])
checkUnreadRef.current = api.checkUnread
return (