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 @@ -1027,7 +1027,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 @@ -226,6 +226,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 @@ -5,12 +5,17 @@ import { useDispatch } from 'react-redux'; import { searchUsers } from 'lib/actions/user-actions'; +import { useModalContext } from 'lib/components/modal-provider.react'; import { filterPotentialMembers, userSearchIndexForPotentialMembers, } from 'lib/selectors/user-selectors'; -import { getPotentialMemberItems } from 'lib/shared/search-utils'; +import { + getPotentialMemberItems, + notFriendNotice, +} from 'lib/shared/search-utils'; import { threadIsPending } from 'lib/shared/thread-utils'; +import type { ExistingThreadInfoFinder } from 'lib/shared/thread-utils'; import type { SetState } from 'lib/types/hook-types'; import type { AccountUserInfo, @@ -23,6 +28,7 @@ import Label from '../components/label.react'; import Search from '../components/search.react'; import type { InputState } from '../input/input-state'; +import Alert from '../modals/alert.react'; import { updateNavInfoActionType } from '../redux/action-types'; import { useSelector } from '../redux/redux-utils'; import SWMansionIcon from '../SWMansionIcon.react'; @@ -31,6 +37,7 @@ type Props = { +userInfoInputArray: $ReadOnlyArray, +setUserInfoInputArray: SetState<$ReadOnlyArray>, + +existingThreadInfoFinderForCreatingThread: ExistingThreadInfoFinder, +otherUserInfos: { [id: string]: AccountUserInfo }, +threadID: string, +inputState: InputState, @@ -44,6 +51,7 @@ const { userInfoInputArray, setUserInfoInputArray, + existingThreadInfoFinderForCreatingThread, otherUserInfos, threadID, inputState, @@ -116,15 +124,49 @@ ], ); + 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({