mv-experiment #1
|
@ -269,27 +269,94 @@ extension ClientMartinOMEMO: SignalPreKeyStoreProtocol {
|
||||||
// MARK: - SignedPreKey
|
// MARK: - SignedPreKey
|
||||||
extension ClientMartinOMEMO: SignalSignedPreKeyStoreProtocol {
|
extension ClientMartinOMEMO: SignalSignedPreKeyStoreProtocol {
|
||||||
func countSignedPreKeys() -> Int {
|
func countSignedPreKeys() -> Int {
|
||||||
0
|
do {
|
||||||
|
let data = try Database.shared.dbQueue.read { db in
|
||||||
|
try Row.fetchOne(
|
||||||
|
db,
|
||||||
|
sql: "SELECT count(1) FROM omemo_signed_pre_keys WHERE account = :account",
|
||||||
|
arguments: ["account": credentials.bareJid]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return data?["count(1)"] ?? 0
|
||||||
|
} catch {
|
||||||
|
logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadSignedPreKey(withId: UInt32) -> Data? {
|
func loadSignedPreKey(withId: UInt32) -> Data? {
|
||||||
print(withId)
|
do {
|
||||||
return nil
|
let data = try Database.shared.dbQueue.read { db in
|
||||||
|
try Row.fetchOne(
|
||||||
|
db,
|
||||||
|
sql: "SELECT key FROM omemo_signed_pre_keys WHERE account = :account AND id = :id",
|
||||||
|
arguments: ["account": credentials.bareJid, "id": withId]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return data?["key"]
|
||||||
|
} catch {
|
||||||
|
logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func storeSignedPreKey(_ data: Data, withId: UInt32) -> Bool {
|
func storeSignedPreKey(_ data: Data, withId: UInt32) -> Bool {
|
||||||
print(data, withId)
|
do {
|
||||||
return false
|
try Database.shared.dbQueue.write { db in
|
||||||
|
try db.execute(
|
||||||
|
sql: "INSERT INTO omemo_signed_pre_keys (account, id, key) VALUES (:account, :id, :key)",
|
||||||
|
arguments: ["account": credentials.bareJid, "id": withId, "key": data]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func containsSignedPreKey(withId: UInt32) -> Bool {
|
func containsSignedPreKey(withId: UInt32) -> Bool {
|
||||||
print(withId)
|
do {
|
||||||
return false
|
let rec = try Database.shared.dbQueue.read { db in
|
||||||
|
try Row.fetchOne(
|
||||||
|
db,
|
||||||
|
sql: "SELECT key FROM omemo_signed_pre_keys WHERE account = :account AND id = :id",
|
||||||
|
arguments: ["account": credentials.bareJid, "id": withId]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return rec != nil
|
||||||
|
} catch {
|
||||||
|
logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteSignedPreKey(withId: UInt32) -> Bool {
|
func deleteSignedPreKey(withId: UInt32) -> Bool {
|
||||||
print(withId)
|
do {
|
||||||
return false
|
try Database.shared.dbQueue.write { db in
|
||||||
|
try db.execute(
|
||||||
|
sql: "DELETE FROM omemo_signed_pre_keys WHERE account = :account AND id = :id",
|
||||||
|
arguments: ["account": credentials.bareJid, "id": withId]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func wipeSignedPreKeys() {
|
||||||
|
do {
|
||||||
|
try Database.shared.dbQueue.write { db in
|
||||||
|
try db.execute(
|
||||||
|
sql: "DELETE FROM omemo_signed_pre_keys WHERE account = :account",
|
||||||
|
arguments: ["account": credentials.bareJid]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
logIt(.error, "Error fetching chats: \(error.localizedDescription)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue