2024-09-03 15:13:58 +00:00
|
|
|
import Combine
|
|
|
|
import Foundation
|
|
|
|
import GRDB
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct Credentials: DBStorable, Hashable {
|
|
|
|
static let databaseTableName = "credentials"
|
|
|
|
|
|
|
|
var id: String { bareJid }
|
|
|
|
var bareJid: String
|
|
|
|
var pass: String
|
|
|
|
var isActive: Bool
|
|
|
|
|
|
|
|
func save() async throws {
|
|
|
|
let db = Database.shared.dbQueue
|
|
|
|
try await db.write { db in
|
|
|
|
try self.save(db)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func delete() async throws {
|
|
|
|
let db = Database.shared.dbQueue
|
|
|
|
_ = try await db.write { db in
|
|
|
|
try self.delete(db)
|
|
|
|
}
|
|
|
|
}
|
2024-10-07 17:10:03 +00:00
|
|
|
|
|
|
|
func setActive(flag: Bool) async throws {
|
|
|
|
let db = Database.shared.dbQueue
|
|
|
|
_ = try await db.write { db in
|
|
|
|
var updated = self
|
|
|
|
updated.isActive = flag
|
|
|
|
try updated.save(db)
|
|
|
|
}
|
|
|
|
}
|
2024-09-03 15:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Credentials: UniversalInputSelectionElement {
|
|
|
|
var text: String? { bareJid }
|
|
|
|
var icon: Image? { nil }
|
|
|
|
}
|