This commit is contained in:
fmodf 2024-10-07 18:58:02 +02:00
parent bb76ac49a1
commit 339aab2bb4
5 changed files with 30 additions and 8 deletions

View file

@ -94,13 +94,21 @@ extension Database {
table.primaryKey(["account", "id"], onConflict: .replace)
}
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")
}
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")
}
}
// return migrator

View file

@ -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)")
}
}
}

View file

@ -202,7 +202,6 @@ private extension ClientsStore {
clients.removeAll()
actualRosters.removeAll()
actualChats.removeAll()
ready = false
}
}
#endif

View file

@ -33,4 +33,9 @@ enum UserSettings {
@Storage(key: kSecureChatsByDefault, defaultValue: false)
static var secureChatsByDefault: Bool
static func reset() {
omemoDeviceId = 0
secureChatsByDefault = false
}
}

View file

@ -66,6 +66,7 @@ struct SettingsScreen: View {
Button("Delete", role: .destructive) {
clientsStore.flushAllData()
Database.shared.flushAllData()
UserSettings.reset()
}
}
}