diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -14,11 +14,6 @@ import { getMessageTitle, isInvalidSidebarSource } from './message-utils.js'; import { relationshipBlockedInEitherDirection } from './relationship-utils.js'; import { useForwardLookupSearchText, useSearchUsers } from './search-utils.js'; -import threadWatcher from './thread-watcher.js'; -import { - fetchMostRecentMessagesActionTypes, - useFetchMostRecentMessages, -} from '../actions/message-actions.js'; import type { RemoveUsersFromThreadInput } from '../actions/thread-actions'; import { newThreadActionTypes, @@ -126,10 +121,7 @@ } from '../utils/entity-text.js'; import type { GetFCNames } from '../utils/farcaster-helpers.js'; import { entries, values } from '../utils/objects.js'; -import { - useDispatchActionPromise, - type DispatchActionPromise, -} from '../utils/redux-promise-utils.js'; +import type { DispatchActionPromise } from '../utils/redux-promise-utils.js'; import { useSelector } from '../utils/redux-utils.js'; import { usingCommServicesAccessToken } from '../utils/services-utils.js'; import { firstLine } from '../utils/string-utils.js'; @@ -1289,33 +1281,6 @@ } } -function useWatchThread(threadInfo: ?ThreadInfo) { - const dispatchActionPromise = useDispatchActionPromise(); - const callFetchMostRecentMessages = useFetchMostRecentMessages(); - - const threadID = threadInfo?.id; - const threadIsInChatList = useIsThreadInChatList(threadInfo); - React.useEffect(() => { - if (threadID && !threadIsInChatList) { - threadWatcher.watchID(threadID); - void dispatchActionPromise( - fetchMostRecentMessagesActionTypes, - callFetchMostRecentMessages({ threadID }), - ); - } - return () => { - if (threadID && !threadIsInChatList) { - threadWatcher.removeID(threadID); - } - }; - }, [ - callFetchMostRecentMessages, - dispatchActionPromise, - threadIsInChatList, - threadID, - ]); -} - type ExistingThreadInfoFinderParams = { +searching: boolean, +userInfoInputArray: $ReadOnlyArray, @@ -1991,7 +1956,6 @@ emptyItemText, threadNoun, threadLabel, - useWatchThread, useExistingThreadInfoFinder, getThreadTypeParentRequirement, threadMemberHasPermission, diff --git a/lib/shared/watch-thread-utils.js b/lib/shared/watch-thread-utils.js new file mode 100644 --- /dev/null +++ b/lib/shared/watch-thread-utils.js @@ -0,0 +1,41 @@ +// @flow + +import * as React from 'react'; + +import { useIsThreadInChatList } from './thread-utils.js'; +import threadWatcher from './thread-watcher.js'; +import { + fetchMostRecentMessagesActionTypes, + useFetchMostRecentMessages, +} from '../actions/message-actions.js'; +import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; +import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; + +function useWatchThread(threadInfo: ?ThreadInfo) { + const dispatchActionPromise = useDispatchActionPromise(); + const callFetchMostRecentMessages = useFetchMostRecentMessages(); + + const threadID = threadInfo?.id; + const threadIsInChatList = useIsThreadInChatList(threadInfo); + React.useEffect(() => { + if (threadID && !threadIsInChatList) { + threadWatcher.watchID(threadID); + void dispatchActionPromise( + fetchMostRecentMessagesActionTypes, + callFetchMostRecentMessages({ threadID }), + ); + } + return () => { + if (threadID && !threadIsInChatList) { + threadWatcher.removeID(threadID); + } + }; + }, [ + callFetchMostRecentMessages, + dispatchActionPromise, + threadIsInChatList, + threadID, + ]); +} + +export { useWatchThread }; diff --git a/native/chat/message-list.react.js b/native/chat/message-list.react.js --- a/native/chat/message-list.react.js +++ b/native/chat/message-list.react.js @@ -17,7 +17,7 @@ import { useOldestMessageServerID } from 'lib/hooks/message-hooks.js'; import { registerFetchKey } from 'lib/reducers/loading-reducer.js'; import { messageKey } from 'lib/shared/message-utils.js'; -import { useWatchThread } from 'lib/shared/thread-utils.js'; +import { useWatchThread } from 'lib/shared/watch-thread-utils.js'; import type { FetchMessageInfosPayload } from 'lib/types/message-types.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import { threadTypes } from 'lib/types/thread-types-enum.js'; diff --git a/web/chat/chat-message-list-container.react.js b/web/chat/chat-message-list-container.react.js --- a/web/chat/chat-message-list-container.react.js +++ b/web/chat/chat-message-list-container.react.js @@ -6,7 +6,8 @@ import { useDrop } from 'react-dnd'; import { NativeTypes } from 'react-dnd-html5-backend'; -import { useWatchThread, threadIsPending } from 'lib/shared/thread-utils.js'; +import { threadIsPending } from 'lib/shared/thread-utils.js'; +import { useWatchThread } from 'lib/shared/watch-thread-utils.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; import ChatInputBar from './chat-input-bar.react.js';