Preload device links to make message sending quicker

pull/220/head
nielsandriesse 5 years ago
parent 28f066b059
commit 17398f3f9e

@ -154,6 +154,19 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
DispatchQueue.global(qos: .utility).async { DispatchQueue.global(qos: .utility).async {
let _ = IP2Country.shared.populateCacheIfNeeded() let _ = IP2Country.shared.populateCacheIfNeeded()
} }
// Preload device links to make message sending quicker
var publicKeys: Set<String> = []
let storage = OWSPrimaryStorage.shared()
storage.dbReadConnection.read { transaction in
TSContactThread.enumerateCollectionObjects(with: transaction) { object, _ in
guard let thread = object as? TSContactThread, thread.shouldThreadBeVisible && thread.isContactFriend else { return }
let publicKey = thread.contactIdentifier()
guard UserDisplayNameUtilities.getPrivateChatDisplayName(for: publicKey) != nil,
storage.getMasterHexEncodedPublicKey(for: publicKey, in: transaction) == nil else { return }
publicKeys.insert(publicKey)
}
}
let _ = LokiFileServerAPI.getDeviceLinks(associatedWith: publicKeys)
// Do initial update // Do initial update
reload() reload()
} }

@ -11,11 +11,10 @@ final class NewClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelegat
let hexEncodedPublicKey = thread.contactIdentifier() let hexEncodedPublicKey = thread.contactIdentifier()
guard UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) != nil else { return } guard UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) != nil else { return }
// We shouldn't be able to add slave devices to groups // We shouldn't be able to add slave devices to groups
if (storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) == nil) { guard storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) == nil else { return }
result.append(hexEncodedPublicKey) result.append(hexEncodedPublicKey)
} }
} }
}
func getDisplayName(for hexEncodedPublicKey: String) -> String { func getDisplayName(for hexEncodedPublicKey: String) -> String {
return UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact" return UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? "Unknown Contact"
} }

Loading…
Cancel
Save