(threadInfo: ?ThreadInfo)
| 10 | import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; |
| 11 | |
| 12 | function 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 | |
| 39 | export { useWatchThread }; |
no test coverage detected