diff options
Diffstat (limited to 'src/state/queries/messages/conversation.ts')
-rw-r--r-- | src/state/queries/messages/conversation.ts | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/src/state/queries/messages/conversation.ts b/src/state/queries/messages/conversation.ts index 260524524..de5a90571 100644 --- a/src/state/queries/messages/conversation.ts +++ b/src/state/queries/messages/conversation.ts @@ -13,7 +13,7 @@ import {useAgent} from '#/state/session' import { ConvoListQueryData, getConvoFromQueryData, - RQKEY as LIST_CONVOS_KEY, + RQKEY_ROOT as LIST_CONVOS_KEY, } from './list-conversations' const RQKEY_ROOT = 'convo' @@ -76,34 +76,37 @@ export function useMarkAsReadMutation() { onSuccess(_, {convoId}) { if (!convoId) return - queryClient.setQueryData(LIST_CONVOS_KEY, (old: ConvoListQueryData) => { - if (!old) return old + queryClient.setQueriesData( + {queryKey: [LIST_CONVOS_KEY]}, + (old?: ConvoListQueryData) => { + if (!old) return old - const existingConvo = getConvoFromQueryData(convoId, 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, + 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 - }), - } - }), + 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. } - } else { - // If we somehow marked a convo as read that doesn't exist in the - // list, then we don't need to do anything. - } - }) + }, + ) }, }) } |