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 @@ -1177,7 +1177,7 @@ +searching: boolean, +userInfoInputArray: $ReadOnlyArray, }; -type ExistingThreadInfoFinder = ( +export type ExistingThreadInfoFinder = ( params: ExistingThreadInfoFinderParams, ) => ?ThreadInfo; function useExistingThreadInfoFinder( 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 @@ -229,6 +229,9 @@ ); }, [ + existingThreadInfoFinderForCreatingThread, inputState, isChatCreation, otherUserInfos, diff --git a/web/chat/chat-thread-composer.react.js b/web/chat/chat-thread-composer.react.js --- a/web/chat/chat-thread-composer.react.js +++ b/web/chat/chat-thread-composer.react.js @@ -4,6 +4,7 @@ import { useDispatch } from 'react-redux'; import { searchUsers } from 'lib/actions/user-actions.js'; +import { useModalContext } from 'lib/components/modal-provider.react.js'; import SWMansionIcon from 'lib/components/SWMansionIcon.react.js'; import { useENSNames } from 'lib/hooks/ens-cache.js'; import { @@ -11,8 +12,12 @@ userSearchIndexForPotentialMembers, searchIndexFromUserInfos, } from 'lib/selectors/user-selectors.js'; -import { getPotentialMemberItems } from 'lib/shared/search-utils.js'; +import { + getPotentialMemberItems, + notFriendNotice, +} from 'lib/shared/search-utils.js'; import { threadIsPending } from 'lib/shared/thread-utils.js'; +import type { ExistingThreadInfoFinder } from 'lib/shared/thread-utils.js'; import type { SetState } from 'lib/types/hook-types.js'; import type { AccountUserInfo, @@ -26,12 +31,14 @@ import Label from '../components/label.react.js'; import Search from '../components/search.react.js'; import type { InputState } from '../input/input-state.js'; +import Alert from '../modals/alert.react.js'; import { updateNavInfoActionType } from '../redux/action-types.js'; import { useSelector } from '../redux/redux-utils.js'; type Props = { +userInfoInputArray: $ReadOnlyArray, +setUserInfoInputArray: SetState<$ReadOnlyArray>, + +existingThreadInfoFinderForCreatingThread: ExistingThreadInfoFinder, +otherUserInfos: { [id: string]: AccountUserInfo }, +threadID: string, +inputState: InputState, @@ -45,6 +52,7 @@ const { userInfoInputArray, setUserInfoInputArray, + existingThreadInfoFinderForCreatingThread, otherUserInfos, threadID, inputState, @@ -116,15 +124,49 @@ ); const userListItemsWithENSNames = useENSNames(userListItems); + const dispatch = useDispatch(); + const { pushModal } = useModalContext(); const onSelectUserFromSearch = React.useCallback( - (id: string, username: string) => { - setUserInfoInputArray(previousUserInfoInputArray => [ - ...previousUserInfoInputArray, - { id, username }, - ]); + (userItem: UserListItem) => { setUsernameInputText(''); + if (!userItem.alert) { + setUserInfoInputArray(previousUserInfoInputArray => [ + ...previousUserInfoInputArray, + { id: userItem.id, username: userItem.username }, + ]); + } else if ( + userItem.notice === notFriendNotice && + userInfoInputArray.length === 0 + ) { + const newUserInfoInputArray = [ + { id: userItem.id, username: userItem.username }, + ]; + setUserInfoInputArray(newUserInfoInputArray); + const threadInfo = existingThreadInfoFinderForCreatingThread({ + searching: true, + userInfoInputArray: newUserInfoInputArray, + }); + dispatch({ + type: updateNavInfoActionType, + payload: { + chatMode: 'view', + activeChatThreadID: threadInfo?.id, + pendingThread: threadInfo, + }, + }); + } else { + pushModal( + {userItem.alert.text}, + ); + } }, - [setUserInfoInputArray], + [ + dispatch, + existingThreadInfoFinderForCreatingThread, + pushModal, + setUserInfoInputArray, + userInfoInputArray.length, + ], ); const onRemoveUserFromSelected = React.useCallback( @@ -150,18 +192,11 @@
  • ))} @@ -174,7 +209,6 @@ usernameInputText, ]); - const dispatch = useDispatch(); const hideSearch = React.useCallback( (threadBehavior: ActiveThreadBehavior = 'keep-active-thread') => { dispatch({