fix: Message sent triggering thread subscriptions multiple times (#29546)

pull/29544/head
Guilherme Gazzo 3 years ago committed by GitHub
parent c43b745fec
commit 6bce20a39f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      .changeset/tricky-tomatoes-sit.md
  2. 25
      apps/meteor/client/views/room/contextualBar/Threads/hooks/useThreadMainMessageQuery.ts

@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---
fix: Message sent triggering thread subscriptions multiple times

@ -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,
@ -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;
},

Loading…
Cancel
Save