diff --git a/lib/hooks/user-identities-hooks.js b/lib/hooks/user-identities-hooks.js --- a/lib/hooks/user-identities-hooks.js +++ b/lib/hooks/user-identities-hooks.js @@ -6,6 +6,7 @@ import { useFindUserIdentities } from '../actions/find-user-identities-actions.js'; import { IdentityClientContext } from '../shared/identity-client-context.js'; import type { FarcasterUser } from '../types/identity-service-types.js'; +import type { AccountUserInfo } from '../types/user-types.js'; import { useSelector } from '../utils/redux-utils.js'; function useUsersSupportThickThreads(): ( @@ -88,6 +89,51 @@ ); } +function useUsersSupportingProtocols(users: $ReadOnlyArray): { + +allUsersSupportThickThreads: boolean, + +allUsersSupportFarcasterThreads: boolean, +} { + const checkUsersThickThreadSupport = useUsersSupportThickThreads(); + const [allUsersSupportThickThreads, setAllUsersSupportThickThreads] = + React.useState(false); + React.useEffect(() => { + void (async () => { + if (users.length === 0) { + return; + } + const usersSupportingThickThreads = await checkUsersThickThreadSupport( + users.map(user => user.id), + ); + setAllUsersSupportThickThreads( + users.every(userInfo => usersSupportingThickThreads.get(userInfo.id)), + ); + })(); + }, [checkUsersThickThreadSupport, users]); + + const checkUsersFarcasterDCsSupport = useUsersSupportFarcasterDCs(); + const [allUsersSupportFarcasterThreads, setAllUsersSupportFarcasterThreads] = + React.useState(false); + + React.useEffect(() => { + void (async () => { + if (users.length === 0) { + return; + } + const usersSupportingThickThreads = await checkUsersFarcasterDCsSupport( + users.map(user => user.id), + ); + setAllUsersSupportFarcasterThreads( + users.every(userInfo => usersSupportingThickThreads.get(userInfo.id)), + ); + })(); + }, [checkUsersFarcasterDCsSupport, checkUsersThickThreadSupport, users]); + + return React.useMemo( + () => ({ allUsersSupportThickThreads, allUsersSupportFarcasterThreads }), + [allUsersSupportFarcasterThreads, allUsersSupportThickThreads], + ); +} + export type FCUserInfos = $ReadOnlyMap; export type GetCommFCUsersForFIDs = ( farcasterIDs: $ReadOnlyArray, @@ -142,4 +188,5 @@ useUsersSupportThickThreads, useUsersSupportFarcasterDCs, useGetCommFCUsersForFIDs, + useUsersSupportingProtocols, }; diff --git a/native/chat/message-list-container.react.js b/native/chat/message-list-container.react.js --- a/native/chat/message-list-container.react.js +++ b/native/chat/message-list-container.react.js @@ -7,7 +7,10 @@ import { Text, View } from 'react-native'; import genesis from 'lib/facts/genesis.js'; -import { useUsersSupportThickThreads } from 'lib/hooks/user-identities-hooks.js'; +import { + useUsersSupportingProtocols, + useUsersSupportThickThreads, +} from 'lib/hooks/user-identities-hooks.js'; import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; import { userInfoSelectorForPotentialMembers } from 'lib/selectors/user-selectors.js'; import { useRefreshFarcasterConversation } from 'lib/shared/farcaster/farcaster-hooks.js'; @@ -284,20 +287,8 @@ useExistingThreadInfoFinder(baseThreadInfo); const checkUsersThickThreadSupport = useUsersSupportThickThreads(); - const [allUsersSupportThickThreads, setAllUsersSupportThickThreads] = - React.useState(false); - React.useEffect(() => { - void (async () => { - const usersSupportingThickThreads = await checkUsersThickThreadSupport( - userInfoInputArray.map(user => user.id), - ); - setAllUsersSupportThickThreads( - userInfoInputArray.every(userInfo => - usersSupportingThickThreads.get(userInfo.id), - ), - ); - })(); - }, [checkUsersThickThreadSupport, userInfoInputArray]); + const { allUsersSupportThickThreads } = + useUsersSupportingProtocols(userInfoInputArray); const isSearching = !!props.route.params.searching; const threadInfo = React.useMemo( diff --git a/web/utils/thread-utils.js b/web/utils/thread-utils.js --- a/web/utils/thread-utils.js +++ b/web/utils/thread-utils.js @@ -4,7 +4,7 @@ import * as React from 'react'; import { useLoggedInUserInfo } from 'lib/hooks/account-hooks.js'; -import { useUsersSupportThickThreads } from 'lib/hooks/user-identities-hooks.js'; +import { useUsersSupportingProtocols } from 'lib/hooks/user-identities-hooks.js'; import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; import { createPendingThread, @@ -77,22 +77,9 @@ return state.navInfo.pendingThread; }); const existingThreadInfoFinder = useExistingThreadInfoFinder(baseThreadInfo); - const checkUsersThickThreadSupport = useUsersSupportThickThreads(); - - const [allUsersSupportThickThreads, setAllUsersSupportThickThreads] = - React.useState(false); - React.useEffect(() => { - void (async () => { - const usersSupportingThickThreads = await checkUsersThickThreadSupport( - selectedUserInfos.map(user => user.id), - ); - setAllUsersSupportThickThreads( - selectedUserInfos.every(userInfo => - usersSupportingThickThreads.get(userInfo.id), - ), - ); - })(); - }, [checkUsersThickThreadSupport, selectedUserInfos]); + + const { allUsersSupportThickThreads } = + useUsersSupportingProtocols(selectedUserInfos); const threadInfo = React.useMemo(() => { if (isChatCreation) {