From 2a1d68401d61f58011b772ad884f26bac2b10368 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 15 Feb 2021 17:16:16 +1100 Subject: [PATCH] Allow allow one group creation at a time --- ts/components/MainViewController.tsx | 20 +++++++++---------- .../session/LeftPaneMessageSection.tsx | 16 +++++++++++++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ts/components/MainViewController.tsx b/ts/components/MainViewController.tsx index 055f7120a..1beac675d 100644 --- a/ts/components/MainViewController.tsx +++ b/ts/components/MainViewController.tsx @@ -32,11 +32,13 @@ export class MessageView extends React.Component { // //////////// Management ///////////// // ///////////////////////////////////// +/** + * Returns true if the group was indead created + */ async function createClosedGroup( groupName: string, - groupMembers: Array, - onSuccess: any -) { + groupMembers: Array +): Promise { // Validate groupName and groupMembers length if (groupName.length === 0) { ToastUtils.pushToastError( @@ -44,13 +46,13 @@ async function createClosedGroup( window.i18n('invalidGroupNameTooShort') ); - return; + return false; } else if (groupName.length > window.CONSTANTS.MAX_GROUP_NAME_LENGTH) { ToastUtils.pushToastError( 'invalidGroupName', window.i18n('invalidGroupNameTooLong') ); - return; + return false; } // >= because we add ourself as a member AFTER this. so a 10 group is already invalid as it will be 11 with ourself @@ -61,23 +63,19 @@ async function createClosedGroup( 'pickClosedGroupMember', window.i18n('pickClosedGroupMember') ); - return; + return false; } else if (groupMembers.length >= window.CONSTANTS.CLOSED_GROUP_SIZE_LIMIT) { ToastUtils.pushToastError( 'closedGroupMaxSize', window.i18n('closedGroupMaxSize') ); - return; + return false; } const groupMemberIds = groupMembers.map(m => m.id); await createClosedGroupV2(groupName, groupMemberIds); - if (onSuccess) { - onSuccess(); - } - return true; } diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index 5e890e314..e8e3b856d 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -469,8 +469,20 @@ export class LeftPaneMessageSection extends React.Component { groupName: string, groupMembers: Array ) { - await MainViewController.createClosedGroup(groupName, groupMembers, () => { - this.handleToggleOverlay(undefined); + if (this.state.loading) { + window.log.warn('Closed group creation already in progress'); + return; + } + this.setState({ loading: true }, async () => { + const groupCreated = await MainViewController.createClosedGroup( + groupName, + groupMembers + ); + + if (groupCreated) { + this.handleToggleOverlay(undefined); + } + this.setState({ loading: false }); }); }