From b3f9824b917a711e1050923010f34e8bc22600c3 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 26 Apr 2021 09:54:06 +1000 Subject: [PATCH] Add documentation --- .../MessageReceiver+Handling.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index 7a73809b2..7bff37fff 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -484,9 +484,17 @@ extension MessageReceiver { let newGroupModel = TSGroupModel(title: group.groupName, memberIds: [String](members), image: nil, groupId: groupID, groupType: .closedGroup, adminIds: group.groupAdminIds) thread.setGroupModel(newGroupModel, with: transaction) // Send the latest encryption key pair to the added members if the current user is the admin of the group - // FIXME: Is this still needed? I believe this was to fix a race condition, where someone might add a - // member to a group when they don't have the latest key pair. The admin would then be able to send the - // added user the latest key pair later. Not sure if that race condition still exists though. + // + // This fixes a race condition where: + // • A member removes another member. + // • A member adds someone to the group and sends them the latest group key pair. + // • The admin is offline during all of this. + // • When the admin comes back online they see the member removed message and generate + distribute a new key pair, + // but they don't know about the added member yet. + // • Now they see the member added message. + // + // Without the code below, the added member(s) would never get the key pair that was generated by the admin when they saw + // the member removed message. let isCurrentUserAdmin = group.groupAdminIds.contains(getUserHexEncodedPublicKey()) if isCurrentUserAdmin { for member in membersAsData.map({ $0.toHexString() }) {