2024-08-11 23:52:45 +00:00
|
|
|
import Foundation
|
|
|
|
import GRDB
|
|
|
|
|
|
|
|
enum ConversationType: Int, Codable, DatabaseValueConvertible {
|
|
|
|
case chat = 0
|
|
|
|
case room = 1
|
|
|
|
case channel = 2
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Chat: DBStorable {
|
|
|
|
static let databaseTableName = "chats"
|
|
|
|
|
|
|
|
var id: String
|
|
|
|
var account: String
|
|
|
|
var participant: String
|
|
|
|
var type: ConversationType
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Chat: Equatable {}
|
2024-08-14 09:29:51 +00:00
|
|
|
|
|
|
|
extension Chat {
|
|
|
|
func fetchRoster() async throws -> Roster {
|
|
|
|
try await Database.shared.dbQueue.read { db in
|
|
|
|
guard
|
|
|
|
let roster = try Roster
|
|
|
|
.filter(Column("bareJid") == account && Column("contactBareJid") == participant)
|
|
|
|
.fetchOne(db)
|
|
|
|
else {
|
2024-08-18 15:56:47 +00:00
|
|
|
throw AppError.rosterNotFound
|
2024-08-14 09:29:51 +00:00
|
|
|
}
|
|
|
|
return roster
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|