diff options
author | Paul Frazee <pfrazee@gmail.com> | 2024-01-30 17:46:35 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-30 17:46:35 -0800 |
commit | 45291f17a08acb8b62d0ff86f2ce40ad4fa9f1f6 (patch) | |
tree | ddd4a3e093fe4bb5e1bb3e9596f95693588a3f76 | |
parent | a175922ccf806b529ee9c18b62d602f6c91d0f54 (diff) | |
download | voidsky-45291f17a08acb8b62d0ff86f2ce40ad4fa9f1f6.tar.zst |
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 updateSeen
-rw-r--r-- | src/state/queries/notifications/feed.ts | 20 | ||||
-rw-r--r-- | src/state/queries/notifications/unread.tsx | 10 | ||||
-rw-r--r-- | src/state/queries/notifications/util.ts | 12 |
3 files changed, 25 insertions, 17 deletions
diff --git a/src/state/queries/notifications/feed.ts b/src/state/queries/notifications/feed.ts index d652f493d..b91db9237 100644 --- a/src/state/queries/notifications/feed.ts +++ b/src/state/queries/notifications/feed.ts @@ -67,18 +67,20 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) { page = unreads.getCachedUnreadPage() } if (!page) { - page = await fetchPage({ - limit: PAGE_SIZE, - cursor: pageParam, - queryClient, - moderationOpts, - threadMutes, - fetchAdditionalData: true, - }) + page = ( + await fetchPage({ + limit: PAGE_SIZE, + cursor: pageParam, + queryClient, + moderationOpts, + threadMutes, + fetchAdditionalData: true, + }) + ).page } // if the first page has an unread, mark all read - if (!pageParam && page.items[0] && !page.items[0].notification.isRead) { + if (!pageParam) { unreads.markAllRead() } diff --git a/src/state/queries/notifications/unread.tsx b/src/state/queries/notifications/unread.tsx index a96b56225..e7a0631ec 100644 --- a/src/state/queries/notifications/unread.tsx +++ b/src/state/queries/notifications/unread.tsx @@ -127,7 +127,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { } // count - const page = await fetchPage({ + const {page, indexedAt: lastIndexed} = await fetchPage({ cursor: undefined, limit: 40, queryClient, @@ -151,12 +151,14 @@ export function Provider({children}: React.PropsWithChildren<{}>) { // track last sync const now = new Date() - const lastIndexed = - page.items[0] && new Date(page.items[0].notification.indexedAt) + const lastIndexedDate = lastIndexed + ? new Date(lastIndexed) + : undefined cacheRef.current = { usableInFeed: !!invalidate, // will be used immediately data: page, - syncedAt: !lastIndexed || now > lastIndexed ? now : lastIndexed, + syncedAt: + !lastIndexedDate || now > lastIndexedDate ? now : lastIndexedDate, unreadCount, } diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts index e53a07258..1c85d2b6d 100644 --- a/src/state/queries/notifications/util.ts +++ b/src/state/queries/notifications/util.ts @@ -36,11 +36,12 @@ export async function fetchPage({ moderationOpts: ModerationOpts | undefined threadMutes: string[] fetchAdditionalData: boolean -}): Promise<FeedPage> { +}): Promise<{page: FeedPage; indexedAt: string | undefined}> { const res = await getAgent().listNotifications({ limit, cursor, }) + const indexedAt = res.data.notifications[0]?.indexedAt // filter out notifs by mod rules const notifs = res.data.notifications.filter( @@ -75,9 +76,12 @@ export async function fetchPage({ } return { - cursor: res.data.cursor, - seenAt, - items: notifsGrouped, + page: { + cursor: res.data.cursor, + seenAt, + items: notifsGrouped, + }, + indexedAt, } } |