MCPcopy Create free account
hub / github.com/CommE2E/comm / useWatchThread

Function useWatchThread

lib/shared/watch-thread-utils.js:12–37  ·  view source on GitHub ↗
(threadInfo: ?ThreadInfo)

Source from the content-addressed store, hash-verified

10import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
11
12function useWatchThread(threadInfo: ?ThreadInfo) {
13 const dispatchActionPromise = useDispatchActionPromise();
14 const callFetchMostRecentMessages = useFetchMostRecentMessages();
15
16 const threadID = threadInfo?.id;
17 const threadIsInChatList = useIsThreadInChatList(threadInfo);
18 React.useEffect(() => {
19 if (threadID && !threadIsInChatList) {
20 threadWatcher.watchID(threadID);
21 void dispatchActionPromise(
22 fetchMostRecentMessagesActionTypes,
23 callFetchMostRecentMessages({ threadID }),
24 );
25 }
26 return () => {
27 if (threadID && !threadIsInChatList) {
28 threadWatcher.removeID(threadID);
29 }
30 };
31 }, [
32 callFetchMostRecentMessages,
33 dispatchActionPromise,
34 threadIsInChatList,
35 threadID,
36 ]);
37}
38
39export { useWatchThread };

Calls 6

useDispatchActionPromiseFunction · 0.90
useIsThreadInChatListFunction · 0.90
dispatchActionPromiseFunction · 0.85
watchIDMethod · 0.80
removeIDMethod · 0.80

Tested by

no test coverage detected