Allow allow one group creation at a time

pull/1507/head
Audric Ackermann 4 years ago
parent 720922cc71
commit 2a1d68401d

@ -32,11 +32,13 @@ export class MessageView extends React.Component {
// //////////// Management ///////////// // //////////// Management /////////////
// ///////////////////////////////////// // /////////////////////////////////////
/**
* Returns true if the group was indead created
*/
async function createClosedGroup( async function createClosedGroup(
groupName: string, groupName: string,
groupMembers: Array<ContactType>, groupMembers: Array<ContactType>
onSuccess: any ): Promise<boolean> {
) {
// Validate groupName and groupMembers length // Validate groupName and groupMembers length
if (groupName.length === 0) { if (groupName.length === 0) {
ToastUtils.pushToastError( ToastUtils.pushToastError(
@ -44,13 +46,13 @@ async function createClosedGroup(
window.i18n('invalidGroupNameTooShort') window.i18n('invalidGroupNameTooShort')
); );
return; return false;
} else if (groupName.length > window.CONSTANTS.MAX_GROUP_NAME_LENGTH) { } else if (groupName.length > window.CONSTANTS.MAX_GROUP_NAME_LENGTH) {
ToastUtils.pushToastError( ToastUtils.pushToastError(
'invalidGroupName', 'invalidGroupName',
window.i18n('invalidGroupNameTooLong') 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 // >= 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', 'pickClosedGroupMember',
window.i18n('pickClosedGroupMember') window.i18n('pickClosedGroupMember')
); );
return; return false;
} else if (groupMembers.length >= window.CONSTANTS.CLOSED_GROUP_SIZE_LIMIT) { } else if (groupMembers.length >= window.CONSTANTS.CLOSED_GROUP_SIZE_LIMIT) {
ToastUtils.pushToastError( ToastUtils.pushToastError(
'closedGroupMaxSize', 'closedGroupMaxSize',
window.i18n('closedGroupMaxSize') window.i18n('closedGroupMaxSize')
); );
return; return false;
} }
const groupMemberIds = groupMembers.map(m => m.id); const groupMemberIds = groupMembers.map(m => m.id);
await createClosedGroupV2(groupName, groupMemberIds); await createClosedGroupV2(groupName, groupMemberIds);
if (onSuccess) {
onSuccess();
}
return true; return true;
} }

@ -469,8 +469,20 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
groupName: string, groupName: string,
groupMembers: Array<ContactType> groupMembers: Array<ContactType>
) { ) {
await MainViewController.createClosedGroup(groupName, groupMembers, () => { 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.handleToggleOverlay(undefined);
}
this.setState({ loading: false });
}); });
} }

Loading…
Cancel
Save