2022-04-05 00:38:22 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo, useMemo } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
2022-04-05 00:38:22 +00:00
|
|
|
import { strictAssert } from '../../util/assert';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { lookupConversationWithoutServiceId } from '../../util/lookupConversationWithoutServiceId';
|
2024-02-14 18:18:49 +00:00
|
|
|
import { getUsernameFromSearch } from '../../util/Username';
|
2022-04-05 00:38:22 +00:00
|
|
|
import { ChooseGroupMembersModal } from '../../components/conversation/conversation-details/AddGroupMembersModal/ChooseGroupMembersModal';
|
|
|
|
import { getIntl, getTheme, getRegionCode } from '../selectors/user';
|
|
|
|
import {
|
|
|
|
getCandidateContactsForNewGroup,
|
|
|
|
getConversationByIdSelector,
|
2023-11-07 23:45:33 +00:00
|
|
|
getMe,
|
2022-04-05 00:38:22 +00:00
|
|
|
} from '../selectors/conversations';
|
2024-03-13 20:44:13 +00:00
|
|
|
import { useGlobalModalActions } from '../ducks/globalModals';
|
2022-04-05 00:38:22 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export type SmartChooseGroupMembersModalPropsType = Readonly<{
|
2022-04-05 00:38:22 +00:00
|
|
|
conversationIdsAlreadyInGroup: Set<string>;
|
|
|
|
maxGroupSize: number;
|
|
|
|
confirmAdds: () => void;
|
|
|
|
onClose: () => void;
|
|
|
|
removeSelectedContact: (_: string) => void;
|
|
|
|
searchTerm: string;
|
|
|
|
selectedConversationIds: ReadonlyArray<string>;
|
|
|
|
setSearchTerm: (_: string) => void;
|
|
|
|
toggleSelectedContact: (conversationId: string) => void;
|
2024-03-13 20:44:13 +00:00
|
|
|
}>;
|
2022-04-05 00:38:22 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartChooseGroupMembersModal = memo(
|
|
|
|
function SmartChooseGroupMembersModal({
|
|
|
|
conversationIdsAlreadyInGroup,
|
|
|
|
maxGroupSize,
|
|
|
|
confirmAdds,
|
|
|
|
onClose,
|
|
|
|
removeSelectedContact,
|
|
|
|
searchTerm,
|
|
|
|
selectedConversationIds,
|
|
|
|
setSearchTerm,
|
|
|
|
toggleSelectedContact,
|
|
|
|
}: SmartChooseGroupMembersModalPropsType) {
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const theme = useSelector(getTheme);
|
|
|
|
const regionCode = useSelector(getRegionCode);
|
|
|
|
const me = useSelector(getMe);
|
|
|
|
const conversationSelector = useSelector(getConversationByIdSelector);
|
2022-04-05 00:38:22 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const candidateContacts = useSelector(getCandidateContactsForNewGroup);
|
|
|
|
const selectedContacts = selectedConversationIds.map(conversationId => {
|
|
|
|
const convo = conversationSelector(conversationId);
|
|
|
|
strictAssert(
|
|
|
|
convo,
|
|
|
|
'<SmartChooseGroupMemberModal> selected conversation not found'
|
|
|
|
);
|
|
|
|
return convo;
|
|
|
|
});
|
2024-02-14 18:18:49 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const { showUserNotFoundModal } = useGlobalModalActions();
|
2022-04-05 00:38:22 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
const username = useMemo(() => {
|
|
|
|
return getUsernameFromSearch(searchTerm);
|
|
|
|
}, [searchTerm]);
|
2022-04-05 00:38:22 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
return (
|
|
|
|
<ChooseGroupMembersModal
|
|
|
|
regionCode={regionCode}
|
|
|
|
candidateContacts={candidateContacts}
|
|
|
|
confirmAdds={confirmAdds}
|
|
|
|
conversationIdsAlreadyInGroup={conversationIdsAlreadyInGroup}
|
|
|
|
i18n={i18n}
|
|
|
|
maxGroupSize={maxGroupSize}
|
|
|
|
onClose={onClose}
|
|
|
|
ourE164={me.e164}
|
|
|
|
ourUsername={me.username}
|
|
|
|
removeSelectedContact={removeSelectedContact}
|
|
|
|
searchTerm={searchTerm}
|
|
|
|
selectedContacts={selectedContacts}
|
|
|
|
setSearchTerm={setSearchTerm}
|
|
|
|
theme={theme}
|
|
|
|
toggleSelectedContact={toggleSelectedContact}
|
|
|
|
lookupConversationWithoutServiceId={lookupConversationWithoutServiceId}
|
|
|
|
showUserNotFoundModal={showUserNotFoundModal}
|
|
|
|
username={username}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|