wip
This commit is contained in:
parent
bb76ac49a1
commit
339aab2bb4
|
@ -94,12 +94,20 @@ extension Database {
|
|||
table.primaryKey(["account", "id"], onConflict: .replace)
|
||||
}
|
||||
|
||||
try db.alter(table: "messages") { table in
|
||||
table.add(column: "secure", .boolean).notNull().defaults(to: false)
|
||||
do {
|
||||
try db.alter(table: "messages") { table in
|
||||
table.add(column: "secure", .boolean).notNull().defaults(to: false)
|
||||
}
|
||||
} catch {
|
||||
print("Error adding columns: \(error)\nProbably already added")
|
||||
}
|
||||
|
||||
try db.alter(table: "chats") { table in
|
||||
table.add(column: "encrypted", .boolean).notNull().defaults(to: false)
|
||||
do {
|
||||
try db.alter(table: "chats") { table in
|
||||
table.add(column: "encrypted", .boolean).notNull().defaults(to: false)
|
||||
}
|
||||
} catch {
|
||||
print("Error adding columns: \(error)\nProbably already added")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,11 +60,20 @@ private extension Database {
|
|||
#if DEBUG
|
||||
extension Database {
|
||||
func flushAllData() {
|
||||
// nullable queue and remove db file
|
||||
do {
|
||||
try FileManager.default.removeItem(atPath: dbPath)
|
||||
try dbQueue.write { db in
|
||||
// Fetch all table names
|
||||
let tables = try String.fetchAll(db, sql: """
|
||||
SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';
|
||||
""")
|
||||
|
||||
// Generate and execute DELETE statements for each table
|
||||
for table in tables {
|
||||
try db.execute(sql: "DELETE FROM \(table);")
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print("Error: \(error)")
|
||||
print("Error flushing all data: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,7 +202,6 @@ private extension ClientsStore {
|
|||
clients.removeAll()
|
||||
actualRosters.removeAll()
|
||||
actualChats.removeAll()
|
||||
ready = false
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -33,4 +33,9 @@ enum UserSettings {
|
|||
|
||||
@Storage(key: kSecureChatsByDefault, defaultValue: false)
|
||||
static var secureChatsByDefault: Bool
|
||||
|
||||
static func reset() {
|
||||
omemoDeviceId = 0
|
||||
secureChatsByDefault = false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ struct SettingsScreen: View {
|
|||
Button("Delete", role: .destructive) {
|
||||
clientsStore.flushAllData()
|
||||
Database.shared.flushAllData()
|
||||
UserSettings.reset()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue