From 26b90cc86b081acd844017551362ea0ccff3f828 Mon Sep 17 00:00:00 2001 From: Warrick Corfe-Tan Date: Tue, 15 Jun 2021 07:10:16 +1000 Subject: [PATCH] checkpoint before refactoring update group members dialog --- .../conversation/UpdateGroupMembersDialog.tsx | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/ts/components/conversation/UpdateGroupMembersDialog.tsx b/ts/components/conversation/UpdateGroupMembersDialog.tsx index 53c79e434..26efbe3d2 100644 --- a/ts/components/conversation/UpdateGroupMembersDialog.tsx +++ b/ts/components/conversation/UpdateGroupMembersDialog.tsx @@ -230,6 +230,57 @@ export class UpdateGroupMembersDialog extends React.Component { } } + private async onSubmit(newMembers) { + const _ = window.Lodash; + const ourPK = window.libsession.Utils.UserUtils.getOurPubKeyStrFromCache(); + + const allMembersAfterUpdate = window.Lodash.concat(newMembers, [ourPK]); + + if (!this.isAdmin) { + window.log.warn('Skipping update of members, we are not the admin'); + return; + } + // new members won't include the zombies. We are the admin and we want to remove them not matter what + + // We need to NOT trigger an group update if the list of member is the same. + // we need to merge all members, including zombies for this call. + + // we consider that the admin ALWAYS wants to remove zombies (actually they should be removed + // automatically by him when the LEFT message is received) + const allExistingMembersWithZombies = _.uniq( + this.existingMembers.concat(this.existingZombies) + ); + + const notPresentInOld = allMembersAfterUpdate.filter( + m => !allExistingMembersWithZombies.includes(m) + ); + + // be sure to include zombies in here + const membersToRemove = allExistingMembersWithZombies.filter( + m => !allMembersAfterUpdate.includes(m) + ); + + const xor = _.xor(membersToRemove, notPresentInOld); + if (xor.length === 0) { + window.log.info('skipping group update: no detected changes in group member list'); + + return; + } + + // If any extra devices of removed exist in newMembers, ensure that you filter them + // Note: I think this is useless + const filteredMembers = allMembersAfterUpdate.filter( + member => !_.includes(membersToRemove, member) + ); + + window.libsession.ClosedGroup.initiateGroupUpdate( + this.groupId, + this.groupName, + filteredMembers, + this.avatarPath + ); + } + // Return members that would comprise the group given the // current state in `users` private getWouldBeMembers(users: Array) {