From 79fb5ceb2cf8b522dfdfe97e7c110b7ab33ecd99 Mon Sep 17 00:00:00 2001 From: fmodf Date: Sat, 31 Aug 2024 10:55:51 +0200 Subject: [PATCH] wip --- .../AppData/Client/Client+MartinOMEMO.swift | 45 ++++++++++++++++--- .../Services/Database+Migrations.swift | 16 +++---- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/ConversationsClassic/AppData/Client/Client+MartinOMEMO.swift b/ConversationsClassic/AppData/Client/Client+MartinOMEMO.swift index 0a4aa3b..cb298e5 100644 --- a/ConversationsClassic/AppData/Client/Client+MartinOMEMO.swift +++ b/ConversationsClassic/AppData/Client/Client+MartinOMEMO.swift @@ -230,17 +230,17 @@ extension ClientMartinOMEMO: SignalPreKeyStoreProtocol { 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 ( + 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] ) @@ -362,7 +362,40 @@ extension ClientMartinOMEMO: SignalSignedPreKeyStoreProtocol { // MARK: - Identity extension ClientMartinOMEMO: SignalIdentityKeyStoreProtocol { + // func regenerateKeys(wipe: Bool = false) -> Bool { + // if wipe { + // wipeSignedPreKeys() + // } + // } + // if wipe { + // DBOMEMOStore.instance.wipe(forAccount: context!.sessionObject.userBareJid!) + // } + // + // let hasKeyPair = identityKeyStore.keyPair() != nil + // if wipe || identityKeyStore.localRegistrationId() == 0 || !hasKeyPair { + // let regId: UInt32 = signalContext.generateRegistrationId() + // AccountSettings.omemoRegistrationId(for: context!.sessionObject.userBareJid!, value: regId) + // + // let keyPair = SignalIdentityKeyPair.generateKeyPair(context: signalContext) + // if !identityKeyStore.save(identity: SignalAddress(name: context!.sessionObject.userBareJid!.stringValue, deviceId: Int32(identityKeyStore.localRegistrationId())), key: keyPair) {} + // } + // return true + // } + func keyPair() -> (any MartinOMEMO.SignalIdentityKeyPairProtocol)? { + // guard let deviceId = localRegistrationId(forAccount: account) else { + // return nil + // } + // + // guard + // let data = try! Database.main.reader({ database in + // try database.select(query: .omemoKeyPairForAccount, params: ["account": account, "name": account.stringValue, "deviceId": deviceId]).mapFirst { $0.data(for: "key") } + // }) + // else { + // return nil + // } + // + // return SignalIdentityKeyPair(fromKeyPairData: data) nil } diff --git a/ConversationsClassic/AppData/Services/Database+Migrations.swift b/ConversationsClassic/AppData/Services/Database+Migrations.swift index 7f08b48..f43c54a 100644 --- a/ConversationsClassic/AppData/Services/Database+Migrations.swift +++ b/ConversationsClassic/AppData/Services/Database+Migrations.swift @@ -93,14 +93,14 @@ extension Database { table.primaryKey(["account", "id"], onConflict: .replace) } - try db.alter(table: "chats") { table in - table.add(column: "encryption", .text) - } - - try db.alter(table: "chat_history") { table in - table.add(column: "encryption", .integer) - table.add(column: "fingerprint", .text) - } + // try db.alter(table: "chats") { table in + // table.add(column: "encryption", .text) + // } + // + // try db.alter(table: "chat_history") { table in + // table.add(column: "encryption", .integer) + // table.add(column: "fingerprint", .text) + // } } // return migrator