fmodf
b3b3b3aef7
Reviewed-on: narayana/conversations-classic-ios#1 Co-authored-by: fmodf <fmodf.ios@gmail.com> Co-committed-by: fmodf <fmodf.ios@gmail.com>
50 lines
1.2 KiB
Swift
50 lines
1.2 KiB
Swift
import Foundation
|
|
import GRDB
|
|
|
|
struct Settings: DBStorable {
|
|
static let databaseTableName = "settings"
|
|
|
|
let bareJid: String
|
|
var omemoRegId: Int
|
|
|
|
var id: String {
|
|
bareJid
|
|
}
|
|
}
|
|
|
|
extension Settings {
|
|
static func getFor(_ bareJid: String) -> Settings? {
|
|
do {
|
|
return try Database.shared.dbQueue.read { db in
|
|
let settings = try Settings.filter(Column("bareJid") == bareJid).fetchOne(db)
|
|
return settings
|
|
}
|
|
} catch {
|
|
logIt(.error, "Settings not exists for \(bareJid)")
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func wipeOmemoRegId() {
|
|
do {
|
|
_ = try Database.shared.dbQueue.write { db in
|
|
try Settings
|
|
.filter(Column("bareJid") == bareJid)
|
|
.updateAll(db, Column("omemoRegId").set(to: 0))
|
|
}
|
|
} catch {
|
|
logIt(.error, "Failed to wipe omemoRegId for \(bareJid)")
|
|
}
|
|
}
|
|
|
|
func save() {
|
|
do {
|
|
try Database.shared.dbQueue.write { db in
|
|
try self.insert(db)
|
|
}
|
|
} catch {
|
|
logIt(.error, "Failed to save settings for \(bareJid)")
|
|
}
|
|
}
|
|
}
|