| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -120,27 +120,26 @@ public final class LokiAPI : NSObject {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }.map { Set($0) }.retryingIfNeeded(maxRetryCount: maxRetryCount)
 | 
					 | 
					 | 
					 | 
					        }.map { Set($0) }.retryingIfNeeded(maxRetryCount: maxRetryCount)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    
 | 
					 | 
					 | 
					 | 
					    
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public static func getDestinations(for hexEncodedPublicKey: String) -> Promise<Set<Destination>> {
 | 
					 | 
					 | 
					 | 
					    public static func getDestinations(for hexEncodedPublicKey: String) -> Promise<[Destination]> {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        var result: Promise<Set<Destination>>!
 | 
					 | 
					 | 
					 | 
					        var result: Promise<[Destination]>!
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        storage.dbReadWriteConnection.readWrite { transaction in
 | 
					 | 
					 | 
					 | 
					        storage.dbReadWriteConnection.readWrite { transaction in
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            result = getDestinations(for: hexEncodedPublicKey, in: transaction)
 | 
					 | 
					 | 
					 | 
					            result = getDestinations(for: hexEncodedPublicKey, in: transaction)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return result
 | 
					 | 
					 | 
					 | 
					        return result
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    
 | 
					 | 
					 | 
					 | 
					    
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    public static func getDestinations(for hexEncodedPublicKey: String, in transaction: YapDatabaseReadWriteTransaction) -> Promise<Set<Destination>> {
 | 
					 | 
					 | 
					 | 
					    public static func getDestinations(for hexEncodedPublicKey: String, in transaction: YapDatabaseReadWriteTransaction) -> Promise<[Destination]> {
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        // All of this has to happen on DispatchQueue.global() due to the way OWSMessageManager works
 | 
					 | 
					 | 
					 | 
					        // All of this has to happen on DispatchQueue.global() due to the way OWSMessageManager works
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        let (promise, seal) = Promise<Set<Destination>>.pending()
 | 
					 | 
					 | 
					 | 
					        let (promise, seal) = Promise<[Destination]>.pending()
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        func getDestinations(in transaction: YapDatabaseReadTransaction? = nil) {
 | 
					 | 
					 | 
					 | 
					        func getDestinations(in transaction: YapDatabaseReadTransaction? = nil) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            func getDestinationsInternal(in transaction: YapDatabaseReadTransaction) {
 | 
					 | 
					 | 
					 | 
					            func getDestinationsInternal(in transaction: YapDatabaseReadTransaction) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                let query = YapDatabaseQuery(string: "WHERE \(DeviceLinkIndex.slaveHexEncodedPublicKey) = ? OR \(DeviceLinkIndex.masterHexEncodedPublicKey) = ?", parameters: [ hexEncodedPublicKey, hexEncodedPublicKey ])
 | 
					 | 
					 | 
					 | 
					                var destinations: [Destination] = []
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                let deviceLinks = Set(DeviceLinkIndex.getDeviceLinks(for: query, in: transaction))
 | 
					 | 
					 | 
					 | 
					                let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) ?? hexEncodedPublicKey
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                var destinations = Set(deviceLinks.flatMap {
 | 
					 | 
					 | 
					 | 
					                let masterDestination = Destination(hexEncodedPublicKey: masterHexEncodedPublicKey, kind: .master)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    return [ Destination(hexEncodedPublicKey: $0.master.hexEncodedPublicKey, kind: .master), Destination(hexEncodedPublicKey: $0.slave.hexEncodedPublicKey, kind: .slave) ]
 | 
					 | 
					 | 
					 | 
					                destinations.append(masterDestination)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                })
 | 
					 | 
					 | 
					 | 
					                let deviceLinks = storage.getDeviceLinks(for: masterHexEncodedPublicKey, in: transaction)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                if destinations.isEmpty {
 | 
					 | 
					 | 
					 | 
					                let slaveDestinations = deviceLinks.map { Destination(hexEncodedPublicKey: $0.slave.hexEncodedPublicKey, kind: .slave) }
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                    destinations.insert(Destination(hexEncodedPublicKey: hexEncodedPublicKey, kind: .master))
 | 
					 | 
					 | 
					 | 
					                destinations.append(contentsOf: slaveDestinations)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                }
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                seal.fulfill(destinations)
 | 
					 | 
					 | 
					 | 
					                seal.fulfill(destinations)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            }
 | 
					 | 
					 | 
					 | 
					            }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if let transaction = transaction, transaction.connection.pendingTransactionCount != 0 {
 | 
					 | 
					 | 
					 | 
					            if let transaction = transaction, transaction.connection.pendingTransactionCount != 0 {
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
 
 |