Skip to content

Commit

Permalink
fix: Message sent triggering thread subscriptions multiple times (#29546
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ggazzo authored Jun 15, 2023
1 parent c43b745 commit 6bce20a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-tomatoes-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

fix: Message sent triggering thread subscriptions multiple times
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ export const useThreadMainMessageQuery = (
useEffect(() => {
return () => {
unsubscribeRef.current?.();
unsubscribeRef.current = undefined;
};
}, []);
}, [tmid]);

return useQuery(
['rooms', room._id, 'threads', tmid, 'main-message'] as const,
Expand All @@ -96,17 +97,17 @@ export const useThreadMainMessageQuery = (
throw new Error('Invalid main message');
}

unsubscribeRef.current?.();

unsubscribeRef.current = subscribeToMessage(mainMessage, {
onMutate: () => {
queryClient.invalidateQueries(queryKey, { exact: true });
},
onDelete: () => {
onDelete?.();
queryClient.invalidateQueries(queryKey, { exact: true });
},
});
unsubscribeRef.current =
unsubscribeRef.current ||
subscribeToMessage(mainMessage, {
onMutate: () => {
queryClient.invalidateQueries(queryKey, { exact: true });
},
onDelete: () => {
onDelete?.();
queryClient.invalidateQueries(queryKey, { exact: true });
},
});

return mainMessage;
},
Expand Down

0 comments on commit 6bce20a

Please sign in to comment.