Add comment & clean

pull/154/head
nielsandriesse 5 years ago
parent 0b29def940
commit d0b83a59e7

@ -45,7 +45,7 @@ extern NSString *const TSGroupThread_NotificationKey_UniqueId;
+ (NSArray<TSGroupThread *> *)groupThreadsWithRecipientId:(NSString *)recipientId + (NSArray<TSGroupThread *> *)groupThreadsWithRecipientId:(NSString *)recipientId
transaction:(YapDatabaseReadWriteTransaction *)transaction; transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)updateGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)setGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)leaveGroupWithSneakyTransaction; - (void)leaveGroupWithSneakyTransaction;
- (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;

@ -232,7 +232,7 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
return NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @""); return NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @"");
} }
- (void)updateGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction - (void)setGroupModel:(TSGroupModel *)newGroupModel withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
self.groupModel = newGroupModel; self.groupModel = newGroupModel;
[self saveWithTransaction:transaction]; [self saveWithTransaction:transaction];

@ -589,12 +589,10 @@ NS_ASSUME_NONNULL_BEGIN
[TSGroupThread threadWithGroupId:dataMessage.group.id transaction:transaction]; [TSGroupThread threadWithGroupId:dataMessage.group.id transaction:transaction];
if (groupThread) { if (groupThread) {
BOOL isClosedGroup = groupThread.groupModel.groupType == closedGroup; BOOL isClosedGroup = (groupThread.groupModel.groupType == closedGroup);
if (isClosedGroup && dataMessage.group.type == SSKProtoGroupContextTypeDeliver) { if (isClosedGroup && dataMessage.group.type == SSKProtoGroupContextTypeDeliver) {
// Only allow messages from members of the group // Only allow messages from group members
if (![groupThread isUserInGroup:envelope.source transaction:transaction]) { if (![groupThread isUserInGroup:envelope.source transaction:transaction]) { return; }
return;
}
} }
if (dataMessage.group.type != SSKProtoGroupContextTypeUpdate) { if (dataMessage.group.type != SSKProtoGroupContextTypeUpdate) {
@ -1499,10 +1497,10 @@ NS_ASSUME_NONNULL_BEGIN
NSString *updateGroupInfo = [newGroupThread.groupModel getInfoStringAboutUpdateTo:newGroupModel NSString *updateGroupInfo = [newGroupThread.groupModel getInfoStringAboutUpdateTo:newGroupModel
contactsManager:self.contactsManager]; contactsManager:self.contactsManager];
[newGroupThread updateGroupModel:newGroupModel withTransaction:transaction]; [newGroupThread setGroupModel:newGroupModel withTransaction:transaction];
BOOL removedFromGroup = [removedMemberIds containsObject:ourHexEncodedPublicKey]; BOOL wasCurrentUserRemovedFromGroup = [removedMemberIds containsObject:ourHexEncodedPublicKey];
if (!removedFromGroup) { if (!wasCurrentUserRemovedFromGroup) {
// Loki: Try to establish sessions with all members when a group is created or updated // Loki: Try to establish sessions with all members when a group is created or updated
[self establishSessionsWithMembersIfNeeded: newMemberIds.allObjects forThread:newGroupThread transaction:transaction]; [self establishSessionsWithMembersIfNeeded: newMemberIds.allObjects forThread:newGroupThread transaction:transaction];
} }
@ -1521,7 +1519,7 @@ NS_ASSUME_NONNULL_BEGIN
[infoMessage saveWithTransaction:transaction]; [infoMessage saveWithTransaction:transaction];
// If we were the one that was removed then we need to leave the group // If we were the one that was removed then we need to leave the group
if (removedFromGroup) { if (wasCurrentUserRemovedFromGroup) {
[newGroupThread leaveGroupWithTransaction:transaction]; [newGroupThread leaveGroupWithTransaction:transaction];
} }
@ -1529,7 +1527,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
case SSKProtoGroupContextTypeQuit: { case SSKProtoGroupContextTypeQuit: {
if (!oldGroupThread) { if (!oldGroupThread) {
OWSLogWarn(@"ignoring quit group message from unknown group."); OWSLogWarn(@"Ignoring quit group message from unknown group.");
return nil; return nil;
} }
newMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds]; newMemberIds = [NSMutableSet setWithArray:oldGroupThread.groupModel.groupMemberIds];
@ -1547,7 +1545,8 @@ NS_ASSUME_NONNULL_BEGIN
messageType:TSInfoMessageTypeGroupUpdate messageType:TSInfoMessageTypeGroupUpdate
customMessage:updateGroupInfo] saveWithTransaction:transaction]; 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]) { if ([newMemberIds containsObject:ourHexEncodedPublicKey]) {
[oldGroupThread leaveGroupWithTransaction:transaction]; [oldGroupThread leaveGroupWithTransaction:transaction];
} }

Loading…
Cancel
Save