57 lines
1.3 KiB
Swift
57 lines
1.3 KiB
Swift
import Foundation
|
|
import monalxmpp
|
|
|
|
enum MessageStatus {
|
|
case pending
|
|
case sent
|
|
case delivered
|
|
case error
|
|
case inbound
|
|
}
|
|
|
|
struct Message: Identifiable {
|
|
let accountId: Int
|
|
let participantJid: String
|
|
let dbId: Int
|
|
let messageId: String
|
|
let stanzaId: String
|
|
let timestamp: Date
|
|
let body: String
|
|
let isInbound: Bool
|
|
let encrypted: Bool
|
|
var status: MessageStatus
|
|
|
|
var id: String {
|
|
"\(accountId)|\(dbId)"
|
|
}
|
|
|
|
init?(_ obj: MLMessage) {
|
|
guard let accId = obj.accountID as? Int, let dbId = obj.messageDBId as? Int else { return nil }
|
|
accountId = accId
|
|
participantJid = obj.participantJid
|
|
self.dbId = dbId
|
|
messageId = obj.messageId
|
|
stanzaId = obj.stanzaId
|
|
timestamp = obj.timestamp
|
|
body = obj.messageText
|
|
isInbound = obj.inbound
|
|
encrypted = obj.encrypted
|
|
|
|
if obj.inbound {
|
|
status = .inbound
|
|
} else {
|
|
if obj.hasBeenReceived {
|
|
status = .delivered
|
|
} else if obj.hasBeenSent {
|
|
status = .sent
|
|
} else {
|
|
if !obj.errorReason.isEmpty {
|
|
status = .error
|
|
} else {
|
|
status = .pending
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|