mv-experiment #1
|
@ -6,6 +6,9 @@ import MartinOMEMO
|
|||
final class ClientMartinOMEMO {
|
||||
let credentials: Credentials
|
||||
|
||||
private let queue = DispatchQueue(label: "SignalPreKeyRemovalQueue")
|
||||
private var preKeysMarkedForRemoval: [UInt32] = []
|
||||
|
||||
init(_ credentials: Credentials) {
|
||||
self.credentials = credentials
|
||||
}
|
||||
|
@ -227,48 +230,64 @@ extension ClientMartinOMEMO: SignalPreKeyStoreProtocol {
|
|||
}
|
||||
|
||||
func deletePreKey(withId: UInt32) -> Bool {
|
||||
do {
|
||||
try Database.shared.dbQueue.write { db in
|
||||
try db.execute(
|
||||
sql: "DELETE FROM omemo_pre_keys WHERE account = :account AND id = :id",
|
||||
arguments: ["account": credentials.bareJid, "id": withId]
|
||||
)
|
||||
queue.async {
|
||||
print("queueing prekey with id \(withId) for removal..")
|
||||
self.preKeysMarkedForRemoval.append(withId)
|
||||
}
|
||||
return true
|
||||
} catch {
|
||||
logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check logic of this function carefully!!!
|
||||
func flushDeletedPreKeys() -> Bool {
|
||||
do {
|
||||
try Database.shared.dbQueue.write { db in
|
||||
try db.execute(
|
||||
sql: """
|
||||
DELETE FROM omemo_pre_keys
|
||||
WHERE account = :account
|
||||
AND id IN (
|
||||
SELECT id
|
||||
FROM omemo_pre_keys
|
||||
WHERE account = :account
|
||||
AND id NOT IN (
|
||||
SELECT id
|
||||
FROM omemo_pre_keys
|
||||
WHERE account = :account
|
||||
ORDER BY id DESC
|
||||
LIMIT 100)
|
||||
)
|
||||
""",
|
||||
arguments: ["account": credentials.bareJid]
|
||||
)
|
||||
}
|
||||
return true
|
||||
} catch {
|
||||
logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||
return false
|
||||
}
|
||||
false
|
||||
// !queue.sync { () -> [UInt32] in
|
||||
// defer {
|
||||
// preKeysMarkedForRemoval.removeAll()
|
||||
// }
|
||||
// print("removing queued prekeys: \(preKeysMarkedForRemoval)")
|
||||
// do {
|
||||
// Database.shared.dbQueue.write { db in
|
||||
// try db.execute(
|
||||
// sql: "DETLETE FROM omemo_pre_keys WHERE account = :account AND id IN (:ids)",
|
||||
// arguments: ["account": credentials.bareJid, "ids": preKeysMarkedForRemoval]
|
||||
// )
|
||||
// }
|
||||
// } catch {
|
||||
// logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||
// return [0]
|
||||
// }
|
||||
//
|
||||
// // return preKeysMarkedForRemoval.filter { id in DBOMEMOStore.instance.deletePreKey(forAccount: context!.sessionObject.userBareJid!, withId: id) }
|
||||
// }.isEmpty
|
||||
//
|
||||
//
|
||||
//
|
||||
// do {
|
||||
// try Database.shared.dbQueue.write { db in
|
||||
// try db.execute(
|
||||
// sql: """
|
||||
// DELETE FROM omemo_pre_keys
|
||||
// WHERE account = :account
|
||||
// AND id IN (
|
||||
// SELECT id
|
||||
// FROM omemo_pre_keys
|
||||
// WHERE account = :account
|
||||
// AND id NOT IN (
|
||||
// SELECT id
|
||||
// FROM omemo_pre_keys
|
||||
// WHERE account = :account
|
||||
// ORDER BY id DESC
|
||||
// LIMIT 100)
|
||||
// )
|
||||
// """,
|
||||
// arguments: ["account": credentials.bareJid]
|
||||
// )
|
||||
// }
|
||||
// return true
|
||||
// } catch {
|
||||
// logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||
// return false
|
||||
// }
|
||||
}
|
||||
|
||||
func preKeysWipe() {
|
||||
|
|
Loading…
Reference in a new issue