From 74ed52e261a0dbe0fe475b9fb034ff1617d70ec8 Mon Sep 17 00:00:00 2001 From: Nora Trapp Date: Tue, 25 Feb 2020 11:23:55 -0800 Subject: [PATCH] Auto-accept group requests from trusted contacts --- SignalServiceKit/src/Util/GroupManager.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/SignalServiceKit/src/Util/GroupManager.swift b/SignalServiceKit/src/Util/GroupManager.swift index 7ef56679c9..15dfd472ff 100644 --- a/SignalServiceKit/src/Util/GroupManager.swift +++ b/SignalServiceKit/src/Util/GroupManager.swift @@ -543,14 +543,22 @@ public class GroupManager: NSObject { } else { // This thread didn't previously exist, so if we're a member we // have to assume we were just added. + var wasAddedToGroup = false if let localAddress = tsAccountManager.localAddress, groupModel.groupMembers.contains(localAddress) { groupModel.addedByAddress = groupUpdateSourceAddress + wasAddedToGroup = true } // GroupsV2 TODO: Can we use upsertGroupThread(...) here and above? let thread = TSGroupThread(groupModelPrivate: groupModel) thread.anyInsert(transaction: transaction) + // Auto-accept the message request for this group if we were added by someone we trust. + if wasAddedToGroup, let addedByAddress = groupUpdateSourceAddress, + profileManager.isUser(inProfileWhitelist: addedByAddress, transaction: transaction) { + profileManager.addGroupId(toProfileWhitelist: groupModel.groupId, wasLocallyInitiated: true, transaction: transaction) + } + if createInfoMessageForNewGroups { var userInfo: [InfoMessageUserInfoKey: Any] = [ .newGroupModel: groupModel @@ -610,6 +618,12 @@ public class GroupManager: NSObject { // triggered this update added us to the group. if !oldGroupModel.groupMembers.contains(localAddress), newGroupModel.groupMembers.contains(localAddress) { newGroupModel.addedByAddress = groupUpdateSourceAddress + + // Auto-accept the message request for this group if we were added by someone we trust. + if let addedByAddress = groupUpdateSourceAddress, + profileManager.isUser(inProfileWhitelist: addedByAddress, transaction: transaction) { + profileManager.addGroupId(toProfileWhitelist: newGroupModel.groupId, wasLocallyInitiated: true, transaction: transaction) + } } var userInfo: [InfoMessageUserInfoKey: Any] = [