Fix notification mark-read behaviors (#2696)
* Mark read on first notifs page fetch always; this is less optimal but it fixes a case where when the first full page's unreads are all filtered out * Use the pre-filter indexedAt for updateSeenzio/stable
parent
a175922ccf
commit
45291f17a0
|
@ -67,7 +67,8 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||||
page = unreads.getCachedUnreadPage()
|
page = unreads.getCachedUnreadPage()
|
||||||
}
|
}
|
||||||
if (!page) {
|
if (!page) {
|
||||||
page = await fetchPage({
|
page = (
|
||||||
|
await fetchPage({
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
queryClient,
|
queryClient,
|
||||||
|
@ -75,10 +76,11 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||||
threadMutes,
|
threadMutes,
|
||||||
fetchAdditionalData: true,
|
fetchAdditionalData: true,
|
||||||
})
|
})
|
||||||
|
).page
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the first page has an unread, mark all read
|
// if the first page has an unread, mark all read
|
||||||
if (!pageParam && page.items[0] && !page.items[0].notification.isRead) {
|
if (!pageParam) {
|
||||||
unreads.markAllRead()
|
unreads.markAllRead()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// count
|
// count
|
||||||
const page = await fetchPage({
|
const {page, indexedAt: lastIndexed} = await fetchPage({
|
||||||
cursor: undefined,
|
cursor: undefined,
|
||||||
limit: 40,
|
limit: 40,
|
||||||
queryClient,
|
queryClient,
|
||||||
|
@ -151,12 +151,14 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
|
|
||||||
// track last sync
|
// track last sync
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const lastIndexed =
|
const lastIndexedDate = lastIndexed
|
||||||
page.items[0] && new Date(page.items[0].notification.indexedAt)
|
? new Date(lastIndexed)
|
||||||
|
: undefined
|
||||||
cacheRef.current = {
|
cacheRef.current = {
|
||||||
usableInFeed: !!invalidate, // will be used immediately
|
usableInFeed: !!invalidate, // will be used immediately
|
||||||
data: page,
|
data: page,
|
||||||
syncedAt: !lastIndexed || now > lastIndexed ? now : lastIndexed,
|
syncedAt:
|
||||||
|
!lastIndexedDate || now > lastIndexedDate ? now : lastIndexedDate,
|
||||||
unreadCount,
|
unreadCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,11 +36,12 @@ export async function fetchPage({
|
||||||
moderationOpts: ModerationOpts | undefined
|
moderationOpts: ModerationOpts | undefined
|
||||||
threadMutes: string[]
|
threadMutes: string[]
|
||||||
fetchAdditionalData: boolean
|
fetchAdditionalData: boolean
|
||||||
}): Promise<FeedPage> {
|
}): Promise<{page: FeedPage; indexedAt: string | undefined}> {
|
||||||
const res = await getAgent().listNotifications({
|
const res = await getAgent().listNotifications({
|
||||||
limit,
|
limit,
|
||||||
cursor,
|
cursor,
|
||||||
})
|
})
|
||||||
|
const indexedAt = res.data.notifications[0]?.indexedAt
|
||||||
|
|
||||||
// filter out notifs by mod rules
|
// filter out notifs by mod rules
|
||||||
const notifs = res.data.notifications.filter(
|
const notifs = res.data.notifications.filter(
|
||||||
|
@ -75,9 +76,12 @@ export async function fetchPage({
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
page: {
|
||||||
cursor: res.data.cursor,
|
cursor: res.data.cursor,
|
||||||
seenAt,
|
seenAt,
|
||||||
items: notifsGrouped,
|
items: notifsGrouped,
|
||||||
|
},
|
||||||
|
indexedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue