diff options
author | Eric Bailey <git@esb.lol> | 2024-11-15 11:34:31 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-15 11:34:31 -0600 |
commit | db39f3e98abf6abc157685ca39eba6fb38f42705 (patch) | |
tree | f829278f4dcdcefb1010d608df1c38e9c2c56255 /src/state/queries/messages/conversation.ts | |
parent | 18aaa19b97dfb6af72fcd669de325b6df118c6c0 (diff) | |
download | voidsky-db39f3e98abf6abc157685ca39eba6fb38f42705.tar.zst |
Reduce `listConvos` requests (#6378)
* Reduce page size for request * Remove refetch interval entirely * Add comment * Optimistically mark as read * Drop default active poll interval to 60s from 5min * Only optimistically update unread count if success
Diffstat (limited to 'src/state/queries/messages/conversation.ts')
-rw-r--r-- | src/state/queries/messages/conversation.ts | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/state/queries/messages/conversation.ts b/src/state/queries/messages/conversation.ts index fa8a883d0..db96d21a9 100644 --- a/src/state/queries/messages/conversation.ts +++ b/src/state/queries/messages/conversation.ts @@ -5,7 +5,11 @@ import {STALE} from '#/state/queries' import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const' import {useOnMarkAsRead} from '#/state/queries/messages/list-converations' import {useAgent} from '#/state/session' -import {RQKEY as LIST_CONVOS_KEY} from './list-converations' +import { + ConvoListQueryData, + getConvoFromQueryData, + RQKEY as LIST_CONVOS_KEY, +} from './list-converations' const RQKEY_ROOT = 'convo' export const RQKEY = (convoId: string) => [RQKEY_ROOT, convoId] @@ -57,8 +61,37 @@ export function useMarkAsReadMutation() { if (!convoId) throw new Error('No convoId provided') optimisticUpdate(convoId) }, - onSettled() { - queryClient.invalidateQueries({queryKey: LIST_CONVOS_KEY}) + onSuccess(_, {convoId}) { + if (!convoId) return + + queryClient.setQueryData(LIST_CONVOS_KEY, (old: ConvoListQueryData) => { + if (!old) return old + + const existingConvo = getConvoFromQueryData(convoId, old) + + if (existingConvo) { + return { + ...old, + pages: old.pages.map(page => { + return { + ...page, + convos: page.convos.map(convo => { + if (convo.id === convoId) { + return { + ...convo, + unreadCount: 0, + } + } + return convo + }), + } + }), + } + } else { + // If we somehow marked a convo as read that doesn't exist in the + // list, then we don't need to do anything. + } + }) }, }) } |