Skip to content

Commit

Permalink
Recover from a bad message cache state;
Browse files Browse the repository at this point in the history
  • Loading branch information
stef-coenen committed Oct 2, 2024
1 parent 3ed2d4e commit 81f286f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
25 changes: 14 additions & 11 deletions packages/chat-app/src/hooks/chat/useChatMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,20 @@ export const insertNewMessagesForConversation = (
}>
>(['chat-messages', conversationId]);

if (newMessages.length > PAGE_SIZE || !extistingMessages) {
queryClient.setQueryData(
['chat-messages', conversationId],
(data: InfiniteData<unknown, unknown>) => {
return {
pages: data?.pages?.slice(0, 1) ?? [],
pageParams: data?.pageParams?.slice(0, 1) || [undefined],
};
}
);
queryClient.invalidateQueries({ queryKey: ['chat-messages', conversationId] });
if (newMessages.length > PAGE_SIZE || !extistingMessages || !extistingMessages.pages.length) {
if (extistingMessages) {
// Only reset the first page if we have data;
queryClient.setQueryData(
['chat-messages', conversationId],
(data: InfiniteData<unknown, unknown>) => {
return {
pages: data?.pages?.slice(0, 1) ?? [],
pageParams: data?.pageParams?.slice(0, 1) || [undefined],
};
}
);
}
queryClient.refetchQueries({ queryKey: ['chat-messages', conversationId] });
return;
}

Expand Down
1 change: 0 additions & 1 deletion packages/chat-app/src/hooks/chat/useLiveChatProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const useInboxProcessor = (connected?: boolean) => {
);
isDebug && console.debug('[InboxProcessor] new messages', updatedMessages.length);
await processChatMessagesBatch(dotYouClient, queryClient, updatedMessages);

const updatedConversations = await findChangesSinceTimestamp(
dotYouClient,
lastProcessedWithBuffer,
Expand Down
2 changes: 1 addition & 1 deletion packages/chat-app/src/templates/Chat/ChatDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const ChatDetail = ({
if (
!conversation ||
stringGuidsEqual(conversationId, ConversationWithYourselfId) ||
conversation?.fileMetadata.senderOdinId
conversation?.fileMetadata.senderOdinId !== identity
) {
return;
}
Expand Down

0 comments on commit 81f286f

Please sign in to comment.