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>
35 lines
796 B
Swift
35 lines
796 B
Swift
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 {}
|
|
|
|
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 {
|
|
throw AppError.rosterNotFound
|
|
}
|
|
return roster
|
|
}
|
|
}
|
|
}
|