Made a couple of changes to how the ConfigurationMessage is generated and handled

Stopped configuration messages from automatically creating threads for sync'ed contacts (now they will only be created if there are messages)
Updated the ConfigurationMessage to stop truncating the list of contacts but filter the full set (also update the logic to include previously approved contacts)
pull/571/head
Morgan Pretty 4 years ago
parent decb946bf3
commit af543b980b

@ -675,7 +675,7 @@
C3A7219A2558C1660043A11F /* AnyPromise+Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A721992558C1660043A11F /* AnyPromise+Conversion.swift */; }; C3A7219A2558C1660043A11F /* AnyPromise+Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A721992558C1660043A11F /* AnyPromise+Conversion.swift */; };
C3A7225E2558C38D0043A11F /* Promise+Retaining.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A7225D2558C38D0043A11F /* Promise+Retaining.swift */; }; C3A7225E2558C38D0043A11F /* Promise+Retaining.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A7225D2558C38D0043A11F /* Promise+Retaining.swift */; };
C3A76A8D25DB83F90074CB90 /* PermissionMissingModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A76A8C25DB83F90074CB90 /* PermissionMissingModal.swift */; }; C3A76A8D25DB83F90074CB90 /* PermissionMissingModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A76A8C25DB83F90074CB90 /* PermissionMissingModal.swift */; };
C3AABDDF2553ECF00042FF4C /* Array+Description.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D12553860800C340D1 /* Array+Description.swift */; }; C3AABDDF2553ECF00042FF4C /* Array+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D12553860800C340D1 /* Array+Utilities.swift */; };
C3AAFFF225AE99710089E6DD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3AAFFF125AE99710089E6DD /* AppDelegate.swift */; }; C3AAFFF225AE99710089E6DD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3AAFFF125AE99710089E6DD /* AppDelegate.swift */; };
C3ADC66126426688005F1414 /* ShareVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3ADC66026426688005F1414 /* ShareVC.swift */; }; C3ADC66126426688005F1414 /* ShareVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3ADC66026426688005F1414 /* ShareVC.swift */; };
C3BBE0762554CDA60050F1E3 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3BBE0752554CDA60050F1E3 /* Configuration.swift */; }; C3BBE0762554CDA60050F1E3 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3BBE0752554CDA60050F1E3 /* Configuration.swift */; };
@ -1749,7 +1749,7 @@
C3C2A5CE2553860700C340D1 /* Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; }; C3C2A5CE2553860700C340D1 /* Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; };
C3C2A5CF2553860700C340D1 /* Promise+Hashing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Hashing.swift"; sourceTree = "<group>"; }; C3C2A5CF2553860700C340D1 /* Promise+Hashing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Hashing.swift"; sourceTree = "<group>"; };
C3C2A5D02553860800C340D1 /* Promise+Threading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Threading.swift"; sourceTree = "<group>"; }; C3C2A5D02553860800C340D1 /* Promise+Threading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Threading.swift"; sourceTree = "<group>"; };
C3C2A5D12553860800C340D1 /* Array+Description.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Description.swift"; sourceTree = "<group>"; }; C3C2A5D12553860800C340D1 /* Array+Utilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Utilities.swift"; sourceTree = "<group>"; };
C3C2A5D22553860900C340D1 /* String+Trimming.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Trimming.swift"; sourceTree = "<group>"; }; C3C2A5D22553860900C340D1 /* String+Trimming.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Trimming.swift"; sourceTree = "<group>"; };
C3C2A5D32553860900C340D1 /* Promise+Delaying.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Delaying.swift"; sourceTree = "<group>"; }; C3C2A5D32553860900C340D1 /* Promise+Delaying.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Delaying.swift"; sourceTree = "<group>"; };
C3C2A5D42553860A00C340D1 /* Threading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Threading.swift; sourceTree = "<group>"; }; C3C2A5D42553860A00C340D1 /* Threading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Threading.swift; sourceTree = "<group>"; };
@ -2349,7 +2349,7 @@
children = ( children = (
C33FDB8A255A581200E217F9 /* AppContext.h */, C33FDB8A255A581200E217F9 /* AppContext.h */,
C33FDB85255A581100E217F9 /* AppContext.m */, C33FDB85255A581100E217F9 /* AppContext.m */,
C3C2A5D12553860800C340D1 /* Array+Description.swift */, C3C2A5D12553860800C340D1 /* Array+Utilities.swift */,
C33FDAA8255A57FF00E217F9 /* BuildConfiguration.swift */, C33FDAA8255A57FF00E217F9 /* BuildConfiguration.swift */,
B8F5F58225EC94A6003BF8D4 /* Collection+Subscripting.swift */, B8F5F58225EC94A6003BF8D4 /* Collection+Subscripting.swift */,
B8AE75A325A6C6A6001A84D2 /* Data+Trimming.swift */, B8AE75A325A6C6A6001A84D2 /* Data+Trimming.swift */,
@ -4655,7 +4655,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
C3AABDDF2553ECF00042FF4C /* Array+Description.swift in Sources */, C3AABDDF2553ECF00042FF4C /* Array+Utilities.swift in Sources */,
C32C5A47256DB8F0003C73A2 /* ECKeyPair+Hexadecimal.swift in Sources */, C32C5A47256DB8F0003C73A2 /* ECKeyPair+Hexadecimal.swift in Sources */,
C3D9E41525676C320040E4F3 /* Storage.swift in Sources */, C3D9E41525676C320040E4F3 /* Storage.swift in Sources */,
C32C5D83256DD5B6003C73A2 /* SSKKeychainStorage.swift in Sources */, C32C5D83256DD5B6003C73A2 /* SSKKeychainStorage.swift in Sources */,

@ -5,6 +5,7 @@ enum ContactUtilities {
// Collect all contacts // Collect all contacts
var result: [String] = [] var result: [String] = []
Storage.read { transaction in Storage.read { transaction in
// FIXME: If a user deletes a contact thread they will no longer appear in this list (ie. won't be an option for closed group conversations)
TSContactThread.enumerateCollectionObjects(with: transaction) { object, _ in TSContactThread.enumerateCollectionObjects(with: transaction) { object, _ in
guard guard
let thread: TSContactThread = object as? TSContactThread, let thread: TSContactThread = object as? TSContactThread,

@ -1,3 +1,4 @@
import SessionUtilitiesKit
extension ConfigurationMessage { extension ConfigurationMessage {
@ -10,8 +11,7 @@ extension ConfigurationMessage {
let profileKey = user.profileEncryptionKey?.keyData let profileKey = user.profileEncryptionKey?.keyData
var closedGroups: Set<ClosedGroup> = [] var closedGroups: Set<ClosedGroup> = []
var openGroups: Set<String> = [] var openGroups: Set<String> = []
var contacts: Set<Contact> = [] var contacts: Set<ConfigurationMessage.Contact> = []
var contactCount = 0
let populateDataClosure: (YapDatabaseReadTransaction) -> () = { transaction in let populateDataClosure: (YapDatabaseReadTransaction) -> () = { transaction in
TSGroupThread.enumerateCollectionObjects(with: transaction) { object, _ in TSGroupThread.enumerateCollectionObjects(with: transaction) { object, _ in
@ -48,33 +48,36 @@ extension ConfigurationMessage {
} }
let currentUserPublicKey: String = getUserHexEncodedPublicKey() let currentUserPublicKey: String = getUserHexEncodedPublicKey()
var truncatedContacts = storage.getAllContacts(with: transaction)
if truncatedContacts.count > 200 { contacts = storage.getAllContacts(with: transaction)
truncatedContacts = Set(Array(truncatedContacts)[0..<200]) .filter { contact -> Bool in
} let threadID = TSContactThread.threadID(fromContactSessionID: contact.sessionID)
return (
// Skip the current user
contact.sessionID != currentUserPublicKey && (
// Include already approved contacts
contact.isApproved ||
contact.didApproveMe ||
truncatedContacts.forEach { contact in // Sync blocked contacts
let publicKey = contact.sessionID SSKEnvironment.shared.blockingManager.isRecipientIdBlocked(contact.sessionID) ||
let threadID = TSContactThread.threadID(fromContactSessionID: publicKey)
// Want to sync contacts for visible threads and blocked contacts between devices // Contacts which have visible threads (sanity check - should be included as already approved)
guard TSContactThread.fetch(uniqueId: threadID, transaction: transaction)?.shouldBeVisible == true
publicKey != currentUserPublicKey && ( )
TSContactThread.fetch(uniqueId: threadID, transaction: transaction)?.shouldBeVisible == true ||
SSKEnvironment.shared.blockingManager.isRecipientIdBlocked(publicKey)
) )
else {
return
} }
.map { contact -> ConfigurationMessage.Contact in
// Can just default the 'hasX' values to true as they will be set to this // Can just default the 'hasX' values to true as they will be set to this
// when converting to proto anyway // when converting to proto anyway
let profilePictureURL = contact.profilePictureURL let profilePictureURL = contact.profilePictureURL
let profileKey = contact.profileEncryptionKey?.keyData let profileKey = contact.profileEncryptionKey?.keyData
let contact = ConfigurationMessage.Contact(
publicKey: publicKey, return ConfigurationMessage.Contact(
displayName: (contact.name ?? publicKey), publicKey: contact.sessionID,
displayName: (contact.name ?? contact.sessionID),
profilePictureURL: profilePictureURL, profilePictureURL: profilePictureURL,
profileKey: profileKey, profileKey: profileKey,
hasIsApproved: true, hasIsApproved: true,
@ -84,10 +87,8 @@ extension ConfigurationMessage {
hasDidApproveMe: true, hasDidApproveMe: true,
didApproveMe: contact.didApproveMe didApproveMe: contact.didApproveMe
) )
contacts.insert(contact)
contactCount += 1
} }
.asSet()
} }
// If we are provided with a transaction then read the data based on the state of the database // If we are provided with a transaction then read the data based on the state of the database

@ -238,12 +238,6 @@ extension MessageReceiver {
thread.remove(with: transaction) thread.remove(with: transaction)
} }
} }
else {
// Otherwise create and save the thread
let thread = TSContactThread.getOrCreateThread(withContactSessionID: sessionID, transaction: transaction)
thread.shouldBeVisible = true
thread.save(with: transaction)
}
} }
// FIXME: 'OWSBlockingManager' manages it's own dbConnection and transactions so we have to dispatch this to prevent deadlocks // FIXME: 'OWSBlockingManager' manages it's own dbConnection and transactions so we have to dispatch this to prevent deadlocks

@ -5,3 +5,9 @@ public extension Array where Element : CustomStringConvertible {
return "[ " + map { $0.description }.joined(separator: ", ") + " ]" return "[ " + map { $0.description }.joined(separator: ", ") + " ]"
} }
} }
public extension Array where Element: Hashable {
func asSet() -> Set<Element> {
return Set(self)
}
}
Loading…
Cancel
Save