mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
ios: use single call to initialize chat controller (#1110)
* ios: use single call to initialize chat controller * update logs * comments
This commit is contained in:
committed by
GitHub
parent
c94691c89e
commit
ab7fed1628
@@ -14,19 +14,12 @@ private var migrationResult: (Bool, DBMigrationResult)?
|
||||
|
||||
public func getChatCtrl(_ useKey: String? = nil) -> chat_ctrl {
|
||||
if let controller = chatController { return controller }
|
||||
let dbPath = getAppDatabasePath().path
|
||||
let dbKey = useKey ?? getDatabaseKey() ?? ""
|
||||
logger.debug("getChatCtrl DB path: \(dbPath)")
|
||||
var cPath = dbPath.cString(using: .utf8)!
|
||||
var cKey = dbKey.cString(using: .utf8)!
|
||||
chatController = chat_init_key(&cPath, &cKey)
|
||||
logger.debug("getChatCtrl: chat_init_key")
|
||||
return chatController!
|
||||
fatalError("chat controller not initialized")
|
||||
}
|
||||
|
||||
public func migrateChatDatabase(_ useKey: String? = nil) -> (Bool, DBMigrationResult) {
|
||||
public func chatMigrateInit(_ useKey: String? = nil) -> (Bool, DBMigrationResult) {
|
||||
if let res = migrationResult { return res }
|
||||
logger.debug("migrateChatDatabase \(storeDBPassphraseGroupDefault.get())")
|
||||
logger.debug("chatMigrateInit \(storeDBPassphraseGroupDefault.get())")
|
||||
let dbPath = getAppDatabasePath().path
|
||||
var dbKey = ""
|
||||
let useKeychain = storeDBPassphraseGroupDefault.get()
|
||||
@@ -40,11 +33,12 @@ public func migrateChatDatabase(_ useKey: String? = nil) -> (Bool, DBMigrationRe
|
||||
dbKey = key
|
||||
}
|
||||
}
|
||||
logger.debug("migrateChatDatabase DB path: \(dbPath)")
|
||||
// logger.debug("migrateChatDatabase DB key: \(dbKey)")
|
||||
logger.debug("chatMigrateInit DB path: \(dbPath)")
|
||||
logger.debug("chatMigrateInit DB key: \(dbKey)")
|
||||
var cPath = dbPath.cString(using: .utf8)!
|
||||
var cKey = dbKey.cString(using: .utf8)!
|
||||
let cjson = chat_migrate_db(&cPath, &cKey)!
|
||||
// the last parameter of chat_migrate_init is used to return the pointer to chat controller
|
||||
let cjson = chat_migrate_init(&cPath, &cKey, &chatController)!
|
||||
let dbRes = dbMigrationResult(fromCString(cjson))
|
||||
let encrypted = dbKey != ""
|
||||
let keychainErr = dbRes == .ok && useKeychain && encrypted && !setDatabaseKey(dbKey)
|
||||
|
||||
Reference in New Issue
Block a user