Page MenuHomePhorge

D5518.1765088463.diff
No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None

D5518.1765088463.diff

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<AccountUserInfo>,
};
-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 @@
<ChatThreadComposer
userInfoInputArray={userInfoInputArray}
setUserInfoInputArray={setUserInfoInputArray}
+ existingThreadInfoFinderForCreatingThread={
+ existingThreadInfoFinderForCreatingThread
+ }
otherUserInfos={otherUserInfos}
threadID={threadInfo.id}
inputState={inputState}
@@ -246,6 +249,7 @@
</>
);
}, [
+ 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<AccountUserInfo>,
+setUserInfoInputArray: SetState<$ReadOnlyArray<AccountUserInfo>>,
+ +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(
+ <Alert title={userItem.alert.title}>{userItem.alert.text}</Alert>,
+ );
+ }
},
- [setUserInfoInputArray],
+ [
+ dispatch,
+ existingThreadInfoFinderForCreatingThread,
+ pushModal,
+ setUserInfoInputArray,
+ userInfoInputArray.length,
+ ],
);
const onRemoveUserFromSelected = React.useCallback(
@@ -150,18 +192,11 @@
<li key={userSearchResult.id} className={css.searchResultsItem}>
<Button
variant="text"
- onClick={() =>
- onSelectUserFromSearch(
- userSearchResult.id,
- userSearchResult.username,
- )
- }
+ onClick={() => onSelectUserFromSearch(userSearchResult)}
className={css.searchResultsButton}
>
<div className={css.userName}>{userSearchResult.username}</div>
- <div className={css.userInfo}>
- {userSearchResult.alert?.title}
- </div>
+ <div className={css.userInfo}>{userSearchResult.notice}</div>
</Button>
</li>
))}
@@ -174,7 +209,6 @@
usernameInputText,
]);
- const dispatch = useDispatch();
const hideSearch = React.useCallback(
(threadBehavior: ActiveThreadBehavior = 'keep-active-thread') => {
dispatch({

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 7, 6:21 AM (6 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5842803
Default Alt Text
D5518.1765088463.diff (5 KB)

Event Timeline