| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -41,7 +41,7 @@ public final class SyncMessagesProtocol : NSObject {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        TSContactThread.enumerateCollectionObjects { object, _ in
 | 
					 | 
					 | 
					 | 
					        TSContactThread.enumerateCollectionObjects { object, _ in
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            guard let thread = object as? TSContactThread else { return }
 | 
					 | 
					 | 
					 | 
					            guard let thread = object as? TSContactThread else { return }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            let hexEncodedPublicKey = thread.contactIdentifier()
 | 
					 | 
					 | 
					 | 
					            let hexEncodedPublicKey = thread.contactIdentifier()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            guard thread.isContactFriend && thread.shouldThreadBeVisible && !thread.isForceHidden else { return }
 | 
					 | 
					 | 
					 | 
					            guard thread.isContactFriend && thread.shouldThreadBeVisible && !thread.isSlaveThread else { return }
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            friends.append(SignalAccount(recipientId: hexEncodedPublicKey))
 | 
					 | 
					 | 
					 | 
					            friends.append(SignalAccount(recipientId: hexEncodedPublicKey))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        friends.append(SignalAccount(recipientId: getUserHexEncodedPublicKey())) // TODO: Are we sure about this?
 | 
					 | 
					 | 
					 | 
					        friends.append(SignalAccount(recipientId: getUserHexEncodedPublicKey())) // TODO: Are we sure about this?
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -61,7 +61,7 @@ public final class SyncMessagesProtocol : NSObject {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        var groups: [TSGroupThread] = []
 | 
					 | 
					 | 
					 | 
					        var groups: [TSGroupThread] = []
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        TSGroupThread.enumerateCollectionObjects { object, _ in
 | 
					 | 
					 | 
					 | 
					        TSGroupThread.enumerateCollectionObjects { object, _ in
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            guard let group = object as? TSGroupThread, group.groupModel.groupType == .closedGroup,
 | 
					 | 
					 | 
					 | 
					            guard let group = object as? TSGroupThread, group.groupModel.groupType == .closedGroup,
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                group.shouldThreadBeVisible, !group.isForceHidden else { return }
 | 
					 | 
					 | 
					 | 
					                group.shouldThreadBeVisible else { return }
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            groups.append(group)
 | 
					 | 
					 | 
					 | 
					            groups.append(group)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        let syncManager = SSKEnvironment.shared.syncManager
 | 
					 | 
					 | 
					 | 
					        let syncManager = SSKEnvironment.shared.syncManager
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -168,30 +168,23 @@ public final class SyncMessagesProtocol : NSObject {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // Try to establish sessions
 | 
					 | 
					 | 
					 | 
					        // Try to establish sessions
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        for hexEncodedPublicKey in hexEncodedPublicKeys {
 | 
					 | 
					 | 
					 | 
					        for hexEncodedPublicKey in hexEncodedPublicKeys {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            // We don't update the friend request status; that's done in OWSMessageSender.sendMessage(_:)
 | 
					 | 
					 | 
					 | 
					            // We don't update the friend request status; that's done in OWSMessageSender.sendMessage(_:)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction)
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            let friendRequestStatus = storage.getFriendRequestStatus(for: hexEncodedPublicKey, transaction: transaction)
 | 
					 | 
					 | 
					 | 
					            let friendRequestStatus = storage.getFriendRequestStatus(for: hexEncodedPublicKey, transaction: transaction)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            switch friendRequestStatus {
 | 
					 | 
					 | 
					 | 
					            switch friendRequestStatus {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            case .none, .requestExpired:
 | 
					 | 
					 | 
					 | 
					            case .none, .requestExpired:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                let messageSender = SSKEnvironment.shared.messageSender
 | 
					 | 
					 | 
					 | 
					                let messageSender = SSKEnvironment.shared.messageSender
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                // We need to send the FR message to all of the user's devices as the contact sync message excludes slave devices
 | 
					 | 
					 | 
					 | 
					                // We need to send the FR message to all of the user's devices as the contact sync message excludes slave devices
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                let autoGeneratedFRMessage = MultiDeviceProtocol.getAutoGeneratedMultiDeviceFRMessage(for: hexEncodedPublicKey, in: transaction)
 | 
					 | 
					 | 
					 | 
					                let autoGeneratedFRMessage = MultiDeviceProtocol.getAutoGeneratedMultiDeviceFRMessage(for: hexEncodedPublicKey, in: transaction)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                thread.isForceHidden = true
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                thread.save(with: transaction)
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                // This takes into account multi device
 | 
					 | 
					 | 
					 | 
					                // This takes into account multi device
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                messageSender.send(autoGeneratedFRMessage, success: {
 | 
					 | 
					 | 
					 | 
					                messageSender.send(autoGeneratedFRMessage, success: {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    DispatchQueue.main.async {
 | 
					 | 
					 | 
					 | 
					                    DispatchQueue.main.async {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        storage.dbReadWriteConnection.readWrite { transaction in
 | 
					 | 
					 | 
					 | 
					                        storage.dbReadWriteConnection.readWrite { transaction in
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            autoGeneratedFRMessage.remove(with: transaction)
 | 
					 | 
					 | 
					 | 
					                            autoGeneratedFRMessage.remove(with: transaction)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            thread.isForceHidden = false
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            thread.save(with: transaction)
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        }
 | 
					 | 
					 | 
					 | 
					                        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    }
 | 
					 | 
					 | 
					 | 
					                    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                }, failure: { error in
 | 
					 | 
					 | 
					 | 
					                }, failure: { error in
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    DispatchQueue.main.async {
 | 
					 | 
					 | 
					 | 
					                    DispatchQueue.main.async {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        storage.dbReadWriteConnection.readWrite { transaction in
 | 
					 | 
					 | 
					 | 
					                        storage.dbReadWriteConnection.readWrite { transaction in
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            autoGeneratedFRMessage.remove(with: transaction)
 | 
					 | 
					 | 
					 | 
					                            autoGeneratedFRMessage.remove(with: transaction)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            thread.isForceHidden = false
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            thread.save(with: transaction)
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        }
 | 
					 | 
					 | 
					 | 
					                        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    }
 | 
					 | 
					 | 
					 | 
					                    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                })
 | 
					 | 
					 | 
					 | 
					                })
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
 
 |