From 661727c2906309f45c26899c46295ef032b8bb1e Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 5 Jan 2024 14:47:29 -0800 Subject: [PATCH] Group creation/update: Don't allow self-selection via phone number --- ts/components/LeftPane.stories.tsx | 3 +++ .../AddGroupMembersModal.stories.tsx | 1 + .../AddGroupMembersModal/ChooseGroupMembersModal.tsx | 8 +++++--- .../ConversationDetails.stories.tsx | 1 + .../leftPane/LeftPaneChooseGroupMembersHelper.tsx | 11 +++++++---- ts/state/smart/ChooseGroupMembersModal.tsx | 1 + ts/state/smart/LeftPane.tsx | 1 + .../leftPane/LeftPaneChooseGroupMembersHelper_test.ts | 1 + 8 files changed, 20 insertions(+), 7 deletions(-) diff --git a/ts/components/LeftPane.stories.tsx b/ts/components/LeftPane.stories.tsx index f2cabb62797..439f5bac0aa 100644 --- a/ts/components/LeftPane.stories.tsx +++ b/ts/components/LeftPane.stories.tsx @@ -938,6 +938,7 @@ export function ChooseGroupMembersPartialPhoneNumber(): JSX.Element { isShowingRecommendedGroupSizeModal: false, isShowingMaximumGroupSizeModal: false, isUsernamesEnabled: true, + ourE164: undefined, ourUsername: undefined, searchTerm: '+1(212) 555', regionCode: 'US', @@ -961,6 +962,7 @@ export function ChooseGroupMembersValidPhoneNumber(): JSX.Element { isShowingRecommendedGroupSizeModal: false, isShowingMaximumGroupSizeModal: false, isUsernamesEnabled: true, + ourE164: undefined, ourUsername: undefined, searchTerm: '+1(212) 555 5454', regionCode: 'US', @@ -984,6 +986,7 @@ export function ChooseGroupMembersUsername(): JSX.Element { isShowingRecommendedGroupSizeModal: false, isShowingMaximumGroupSizeModal: false, isUsernamesEnabled: true, + ourE164: undefined, ourUsername: undefined, searchTerm: '@signal', regionCode: 'US', diff --git a/ts/components/conversation/conversation-details/AddGroupMembersModal.stories.tsx b/ts/components/conversation/conversation-details/AddGroupMembersModal.stories.tsx index dc9f1f568d7..55ae5f9ff8e 100644 --- a/ts/components/conversation/conversation-details/AddGroupMembersModal.stories.tsx +++ b/ts/components/conversation/conversation-details/AddGroupMembersModal.stories.tsx @@ -64,6 +64,7 @@ const createProps = ( )} regionCode="US" getPreferredBadge={() => undefined} + ourE164={undefined} ourUsername={undefined} theme={ThemeType.light} i18n={i18n} diff --git a/ts/components/conversation/conversation-details/AddGroupMembersModal/ChooseGroupMembersModal.tsx b/ts/components/conversation/conversation-details/AddGroupMembersModal/ChooseGroupMembersModal.tsx index 4db439cce7e..f36a9e1d176 100644 --- a/ts/components/conversation/conversation-details/AddGroupMembersModal/ChooseGroupMembersModal.tsx +++ b/ts/components/conversation/conversation-details/AddGroupMembersModal/ChooseGroupMembersModal.tsx @@ -55,6 +55,7 @@ export type StatePropsType = { i18n: LocalizerType; theme: ThemeType; maxGroupSize: number; + ourE164: string | undefined; ourUsername: string | undefined; searchTerm: string; selectedContacts: ReadonlyArray; @@ -86,6 +87,7 @@ export function ChooseGroupMembersModal({ i18n, maxGroupSize, onClose, + ourE164, ourUsername, removeSelectedContact, searchTerm, @@ -129,9 +131,9 @@ export function ChooseGroupMembersModal({ phoneNumber.isValid && selectedContacts.some(contact => contact.e164 === e164); - isPhoneNumberVisible = candidateContacts.every( - contact => contact.e164 !== e164 - ); + isPhoneNumberVisible = + e164 !== ourE164 && + candidateContacts.every(contact => contact.e164 !== e164); } const inputRef = useRef(null); diff --git a/ts/components/conversation/conversation-details/ConversationDetails.stories.tsx b/ts/components/conversation/conversation-details/ConversationDetails.stories.tsx index 9597b531ed8..002454fdb2e 100644 --- a/ts/components/conversation/conversation-details/ConversationDetails.stories.tsx +++ b/ts/components/conversation/conversation-details/ConversationDetails.stories.tsx @@ -122,6 +122,7 @@ const createProps = ( theme={ThemeType.light} i18n={i18n} lookupConversationWithoutServiceId={makeFakeLookupConversationWithoutServiceId()} + ourE164={undefined} ourUsername={undefined} showUserNotFoundModal={action('showUserNotFoundModal')} isUsernamesEnabled diff --git a/ts/components/leftPane/LeftPaneChooseGroupMembersHelper.tsx b/ts/components/leftPane/LeftPaneChooseGroupMembersHelper.tsx index f539f499249..27fa2cc2b09 100644 --- a/ts/components/leftPane/LeftPaneChooseGroupMembersHelper.tsx +++ b/ts/components/leftPane/LeftPaneChooseGroupMembersHelper.tsx @@ -35,6 +35,7 @@ export type LeftPaneChooseGroupMembersPropsType = { isShowingRecommendedGroupSizeModal: boolean; isShowingMaximumGroupSizeModal: boolean; isUsernamesEnabled: boolean; + ourE164: string | undefined; ourUsername: string | undefined; searchTerm: string; regionCode: string | undefined; @@ -75,6 +76,7 @@ export class LeftPaneChooseGroupMembersHelper extends LeftPaneHelper contact.e164 === phoneNumber.e164); + selectedContacts.some(contact => contact.e164 === e164); - const isVisible = this.candidateContacts.every( - contact => contact.e164 !== phoneNumber.e164 - ); + const isVisible = + e164 !== ourE164 && + this.candidateContacts.every(contact => contact.e164 !== e164); if (isVisible) { this.phoneNumber = phoneNumber; } diff --git a/ts/state/smart/ChooseGroupMembersModal.tsx b/ts/state/smart/ChooseGroupMembersModal.tsx index 70515422d1a..19e879500af 100644 --- a/ts/state/smart/ChooseGroupMembersModal.tsx +++ b/ts/state/smart/ChooseGroupMembersModal.tsx @@ -55,6 +55,7 @@ const mapStateToProps = ( getPreferredBadge: getPreferredBadgeSelector(state), i18n: getIntl(state), theme: getTheme(state), + ourE164: getMe(state).e164, ourUsername: getMe(state).username, selectedContacts, lookupConversationWithoutServiceId, diff --git a/ts/state/smart/LeftPane.tsx b/ts/state/smart/LeftPane.tsx index 96db059bf4f..e312955bc78 100644 --- a/ts/state/smart/LeftPane.tsx +++ b/ts/state/smart/LeftPane.tsx @@ -180,6 +180,7 @@ const getModeSpecificProps = ( OneTimeModalState.Showing, isShowingMaximumGroupSizeModal: getMaximumGroupSizeModalState(state) === OneTimeModalState.Showing, + ourE164: getMe(state).e164, ourUsername: getMe(state).username, regionCode: getRegionCode(state), searchTerm: getComposerConversationSearchTerm(state), diff --git a/ts/test-node/components/leftPane/LeftPaneChooseGroupMembersHelper_test.ts b/ts/test-node/components/leftPane/LeftPaneChooseGroupMembersHelper_test.ts index d3eda804d18..f059c64226a 100644 --- a/ts/test-node/components/leftPane/LeftPaneChooseGroupMembersHelper_test.ts +++ b/ts/test-node/components/leftPane/LeftPaneChooseGroupMembersHelper_test.ts @@ -17,6 +17,7 @@ describe('LeftPaneChooseGroupMembersHelper', () => { isShowingRecommendedGroupSizeModal: false, isShowingMaximumGroupSizeModal: false, isUsernamesEnabled: true, + ourE164: undefined, ourUsername: undefined, groupSizeRecommendedLimit: 22, groupSizeHardLimit: 33,