mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
Swift
34 lines
1.1 KiB
Swift
|
|
@objc(SNContactsMigration)
|
|
public class ContactsMigration : OWSDatabaseMigration {
|
|
|
|
@objc
|
|
class func migrationId() -> String {
|
|
return "001"
|
|
}
|
|
|
|
override public func runUp(completion: @escaping OWSDatabaseMigrationCompletion) {
|
|
self.doMigrationAsync(completion: completion)
|
|
}
|
|
|
|
private func doMigrationAsync(completion: @escaping OWSDatabaseMigrationCompletion) {
|
|
var contacts: [Contact] = []
|
|
TSContactThread.enumerateCollectionObjects { object, _ in
|
|
guard let thread = object as? TSContactThread else { return }
|
|
let sessionID = thread.contactSessionID()
|
|
if let contact = Storage.shared.getContact(with: sessionID) {
|
|
contact.isTrusted = true
|
|
contacts.append(contact)
|
|
}
|
|
}
|
|
Storage.write(with: { transaction in
|
|
contacts.forEach { contact in
|
|
Storage.shared.setContact(contact, using: transaction)
|
|
}
|
|
self.save(with: transaction) // Intentionally capture self
|
|
}, completion: {
|
|
completion()
|
|
})
|
|
}
|
|
}
|