diff --git a/SignalMessaging/groups/GroupsV2Changes.swift b/SignalMessaging/groups/GroupsV2Changes.swift index d9e553f44e..1da113ce46 100644 --- a/SignalMessaging/groups/GroupsV2Changes.swift +++ b/SignalMessaging/groups/GroupsV2Changes.swift @@ -107,18 +107,14 @@ public class GroupsV2Changes { groupMembershipBuilder.remove(address) groupMembershipBuilder.addNonPendingMember(address, role: role) - do { - guard let profileKeyCiphertextData = member.profileKey else { - throw OWSAssertionError("Missing profileKeyCiphertext.") - } - let profileKeyCiphertext = try ProfileKeyCiphertext(contents: [UInt8](profileKeyCiphertextData)) - let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext, - uuid: uuid) - - profileKeys[uuid] = profileKey - } catch { - owsFailDebug("Error parsing profile key: \(error)") + guard let profileKeyCiphertextData = member.profileKey else { + throw OWSAssertionError("Missing profileKeyCiphertext.") } + let profileKeyCiphertext = try ProfileKeyCiphertext(contents: [UInt8](profileKeyCiphertextData)) + let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext, + uuid: uuid) + + profileKeys[uuid] = profileKey } for action in changeActionsProto.deleteMembers { @@ -168,14 +164,10 @@ public class GroupsV2Changes { throw OWSAssertionError("Invalid membership.") } - do { - let profileKeyCiphertext = try presentation.getProfileKeyCiphertext() - let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext, - uuid: uuid) - profileKeys[uuid] = profileKey - } catch { - owsFailDebug("Error parsing profile key: \(error)") - } + let profileKeyCiphertext = try presentation.getProfileKeyCiphertext() + let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext, + uuid: uuid) + profileKeys[uuid] = profileKey } for action in changeActionsProto.addPendingMembers { @@ -194,13 +186,19 @@ public class GroupsV2Changes { guard let role = TSGroupMemberRole.role(for: protoRole) else { throw OWSAssertionError("Invalid role: \(protoRole.rawValue)") } - let uuid = try groupV2Params.uuid(forUserId: userId) - let address = SignalServiceAddress(uuid: uuid) guard let addedByUserID = pendingMember.addedByUserID else { throw OWSAssertionError("Group pending member missing addedByUserID.") } - let addedByUuid = try groupV2Params.uuid(forUserId: addedByUserID) - + let uuid: UUID + let addedByUuid: UUID + do { + uuid = try groupV2Params.uuid(forUserId: userId) + addedByUuid = try groupV2Params.uuid(forUserId: addedByUserID) + } catch { + owsFailDebug("Error parsing uuid: \(error)") + continue + } + let address = SignalServiceAddress(uuid: uuid) guard !oldGroupMembership.allUsers.contains(address) else { throw OWSAssertionError("Invalid membership.") } @@ -242,14 +240,10 @@ public class GroupsV2Changes { groupMembershipBuilder.remove(address) groupMembershipBuilder.addNonPendingMember(address, role: role) - do { - let profileKeyCiphertext = try presentation.getProfileKeyCiphertext() - let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext, - uuid: uuid) - profileKeys[uuid] = profileKey - } catch { - owsFailDebug("Error parsing profile key: \(error)") - } + let profileKeyCiphertext = try presentation.getProfileKeyCiphertext() + let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext, + uuid: uuid) + profileKeys[uuid] = profileKey } if let action = changeActionsProto.modifyTitle { diff --git a/SignalMessaging/groups/GroupsV2Protos.swift b/SignalMessaging/groups/GroupsV2Protos.swift index 762688930b..46d1fcaae9 100644 --- a/SignalMessaging/groups/GroupsV2Protos.swift +++ b/SignalMessaging/groups/GroupsV2Protos.swift @@ -242,18 +242,13 @@ public class GroupsV2Protos { role: role) members.append(member) - do { - let uuid = try groupV2Params.uuid(forUserId: userID) - guard let profileKeyCiphertextData = memberProto.profileKey else { - throw OWSAssertionError("Group member missing profileKeyCiphertextData.") - } - let profileKeyCiphertext = try ProfileKeyCiphertext(contents: [UInt8](profileKeyCiphertextData)) - let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext, - uuid: uuid) - profileKeys[uuid] = profileKey - } catch { - owsFailDebug("Error parsing profile key: \(error)") + guard let profileKeyCiphertextData = memberProto.profileKey else { + throw OWSAssertionError("Group member missing profileKeyCiphertextData.") } + let profileKeyCiphertext = try ProfileKeyCiphertext(contents: [UInt8](profileKeyCiphertextData)) + let profileKey = try groupV2Params.profileKey(forProfileKeyCiphertext: profileKeyCiphertext, + uuid: uuid) + profileKeys[uuid] = profileKey } var pendingMembers = [GroupV2SnapshotImpl.PendingMember]() @@ -271,13 +266,19 @@ public class GroupsV2Protos { throw OWSAssertionError("Group pending member missing addedByUserID.") } let timestamp = pendingMemberProto.timestamp - - let uuid = try groupV2Params.uuid(forUserId: userId) - let addedByUuid = try groupV2Params.uuid(forUserId: addedByUserId) - guard memberProto.hasRole, let role = memberProto.role else { throw OWSAssertionError("Group member missing role.") } + + let uuid: UUID + let addedByUuid: UUID + do { + uuid = try groupV2Params.uuid(forUserId: userId) + addedByUuid = try groupV2Params.uuid(forUserId: addedByUserId) + } catch { + owsFailDebug("Error parsing uuid: \(error)") + continue + } let pendingMember = GroupV2SnapshotImpl.PendingMember(userID: userId, uuid: uuid, timestamp: timestamp,