mirror of
https://github.com/bitwarden/mobile
synced 2025-01-28 01:09:43 +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
@ -41,25 +41,28 @@ extension CipherService: CipherServiceProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func saveCiphers(_ ciphers: [Cipher], completionHandler: @escaping () -> Void){
|
||||
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
|
||||
{
|
||||
Log.e("Error converting to data")
|
||||
return [:]
|
||||
}
|
||||
|
||||
guard let cipherDict = try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any ] else
|
||||
{
|
||||
Log.e("Error converting json data to dict")
|
||||
return [:]
|
||||
}
|
||||
return cipherDict
|
||||
func saveCiphers(_ ciphers: [Cipher], completionHandler: @escaping () -> Void) {
|
||||
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
|
||||
{
|
||||
Log.e("Error converting to data")
|
||||
return [:]
|
||||
}
|
||||
|
||||
guard let cipherDict = try? JSONSerialization.jsonObject(with: data, options: []) as? [String : Any ] else
|
||||
{
|
||||
Log.e("Error converting json data to dict")
|
||||
return [:]
|
||||
}
|
||||
return cipherDict
|
||||
|
||||
} completionHandler: {
|
||||
completionHandler()
|
||||
} completionHandler: {
|
||||
completionHandler()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,4 +70,14 @@ extension CipherService: CipherServiceProtocol {
|
||||
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