mirror of
https://github.com/bitwarden/mobile
synced 2025-01-29 17:59:23 +01:00
EC-842 Delete items that are not included in the sync to the watch (#2242)
This commit is contained in:
parent
f6895a0733
commit
a19b5c4e05
@ -42,7 +42,9 @@ extension CipherService: CipherServiceProtocol {
|
||||
}
|
||||
|
||||
func saveCiphers(_ ciphers: [Cipher], completionHandler: @escaping () -> Void) {
|
||||
dbHelper.insertBatch("CipherEntity", items: ciphers) { item, context in
|
||||
let cipherIds = ciphers.map { $0.id }
|
||||
deleteAll(ciphers[0].userId, notIn: cipherIds) {
|
||||
self.dbHelper.insertBatch("CipherEntity", items: ciphers) { item, context in
|
||||
guard let cipher = item as! Cipher? else { return [:] }
|
||||
let c = cipher.toCipherEntity(moContext: context)
|
||||
guard let data = try? JSONEncoder().encode(c) else
|
||||
@ -62,9 +64,20 @@ extension CipherService: CipherServiceProtocol {
|
||||
completionHandler()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func deleteAll(_ withUserId: String? = nil, completionHandler: @escaping () -> Void) {
|
||||
let predicate = withUserId == nil ? nil : NSPredicate(format: "userId = %@", withUserId!)
|
||||
dbHelper.deleteAll("CipherEntity", predicate: predicate, completionHandler: completionHandler)
|
||||
}
|
||||
|
||||
func deleteAll(_ withUserId: String? = nil, notIn: [String], completionHandler: @escaping () -> Void) {
|
||||
var predicateList : [NSPredicate] = []
|
||||
if let userId = withUserId {
|
||||
predicateList.append(NSPredicate(format: "userId = %@", userId))
|
||||
}
|
||||
predicateList.append(NSPredicate(format: "NOT (id in %@)", notIn))
|
||||
let predicate = NSCompoundPredicate(type: .and, subpredicates: predicateList)
|
||||
dbHelper.deleteAll("CipherEntity", predicate: predicate, completionHandler: completionHandler)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user