From d0b83a59e74450eebb7d240d981c385c73d00a27 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 15 Apr 2020 14:20:02 +1000 Subject: [PATCH] Add comment & clean --- .../src/Contacts/Threads/TSGroupThread.h | 2 +- .../src/Contacts/Threads/TSGroupThread.m | 2 +- .../src/Messages/OWSMessageManager.m | 21 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h index 89ce72249..7c55b4370 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.h @@ -45,7 +45,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId; + (NSArray *)groupThreadsWithRecipientId:(NSString *)recipientId transaction:(YapDatabaseReadWriteTransaction *)transaction; -- (void)updateGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction; +- (void)setGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)leaveGroupWithSneakyTransaction; - (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; diff --git a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m index 4d65917f9..db4bede17 100644 --- a/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m +++ b/SignalServiceKit/src/Contacts/Threads/TSGroupThread.m @@ -232,7 +232,7 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific return NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @""); } -- (void)updateGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction +- (void)setGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction { self.groupModel = newGroupModel; [self saveWithTransaction:transaction]; diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index e12e9ac87..7cc98d993 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -589,12 +589,10 @@ NS_ASSUME_NONNULL_BEGIN [TSGroupThread threadWithGroupId:dataMessage.group.id transaction:transaction]; if (groupThread) { - BOOL isClosedGroup = groupThread.groupModel.groupType == closedGroup; + BOOL isClosedGroup = (groupThread.groupModel.groupType == closedGroup); if (isClosedGroup && dataMessage.group.type == SSKProtoGroupContextTypeDeliver) { - // Only allow messages from members of the group - if (![groupThread isUserInGroup:envelope.source transaction:transaction]) { - return; - } + // Only allow messages from group members + if (![groupThread isUserInGroup:envelope.source transaction:transaction]) { return; } } if (dataMessage.group.type != SSKProtoGroupContextTypeUpdate) { @@ -1499,10 +1497,10 @@ NS_ASSUME_NONNULL_BEGIN NSString *updateGroupInfo = [newGroupThread.groupModel getInfoStringAboutUpdateTo:newGroupModel contactsManager:self.contactsManager]; - [newGroupThread updateGroupModel:newGroupModel withTransaction:transaction]; + [newGroupThread setGroupModel:newGroupModel withTransaction:transaction]; - BOOL removedFromGroup = [removedMemberIds containsObject:ourHexEncodedPublicKey]; - if (!removedFromGroup) { + BOOL wasCurrentUserRemovedFromGroup = [removedMemberIds containsObject:ourHexEncodedPublicKey]; + if (!wasCurrentUserRemovedFromGroup) { // Loki: Try to establish sessions with all members when a group is created or updated [self establishSessionsWithMembersIfNeeded: newMemberIds.allObjects forThread:newGroupThread transaction:transaction]; } @@ -1521,7 +1519,7 @@ NS_ASSUME_NONNULL_BEGIN [infoMessage saveWithTransaction:transaction]; // If we were the one that was removed then we need to leave the group - if (removedFromGroup) { + if (wasCurrentUserRemovedFromGroup) { [newGroupThread leaveGroupWithTransaction:transaction]; } @@ -1529,7 +1527,7 @@ NS_ASSUME_NONNULL_BEGIN } case SSKProtoGroupContextTypeQuit: { if (!oldGroupThread) { - OWSLogWarn(@"ignoring quit group message from unknown group."); + OWSLogWarn(@"Ignoring quit group message from unknown group."); return nil; } newMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds]; @@ -1547,7 +1545,8 @@ NS_ASSUME_NONNULL_BEGIN messageType:TSInfoMessageTypeGroupUpdate customMessage:updateGroupInfo] saveWithTransaction:transaction]; - // If we were the one that quit then we need to leave the group + // If we were the one that quit then we need to leave the group (only relevant for slave + // devices in a multi device context) if ([newMemberIds containsObject:ourHexEncodedPublicKey]) { [oldGroupThread leaveGroupWithTransaction:transaction]; }