99 lines
2.8 KiB
Swift
99 lines
2.8 KiB
Swift
import Foundation
|
|
import GRDB
|
|
import Martin
|
|
|
|
enum MessageType: String, Codable, DatabaseValueConvertible {
|
|
case chat
|
|
case channel
|
|
case groupchat
|
|
}
|
|
|
|
enum MessageContentType: String, Codable, DatabaseValueConvertible {
|
|
case text
|
|
case image
|
|
case video
|
|
case audio
|
|
case file
|
|
case location
|
|
case typing
|
|
case invite
|
|
}
|
|
|
|
struct MessageContainer: Stateable, DatabaseValueConvertible {
|
|
let id: String
|
|
let type: MessageType
|
|
let content: any MessageContent
|
|
}
|
|
|
|
protocol MessageContent: Stateable, DatabaseValueConvertible {
|
|
var type: MessageContentType { get }
|
|
}
|
|
|
|
//
|
|
// enum MessageType: String, Codable, DatabaseValueConvertible {
|
|
// case text
|
|
// case image
|
|
// case video
|
|
// case audio
|
|
// case file
|
|
// case location
|
|
// case writingProcessUpdate
|
|
// }
|
|
//
|
|
// struct Message: DBStorable, Equatable {
|
|
// static let databaseTableName = "messages"
|
|
//
|
|
// let id: String
|
|
// let chatId: String
|
|
// let fromJid: String
|
|
// let toJid: String
|
|
// let timestamp: Date
|
|
// let body: String?
|
|
// let type: MessageType
|
|
// }
|
|
//
|
|
// // Special extnesion for mapping Martin.Message to Message
|
|
// extension Message {
|
|
// static func mapMartinMessage(_ martinMessage: Martin.Message) -> Message? {
|
|
// // for draft messages
|
|
// if martinMessage.hints.contains(.noStore) {
|
|
// return Message(
|
|
// id: martinMessage.id ?? UUID().uuidString,
|
|
// chatId: "none", // chat id will be filled later
|
|
// fromJid: martinMessage.from?.bareJid.stringValue ?? "",
|
|
// toJid: martinMessage.to?.bareJid.stringValue ?? "",
|
|
// timestamp: Date(),
|
|
// body: nil,
|
|
// type: .writingProcessUpdate
|
|
// )
|
|
// }
|
|
//
|
|
// // if regular message contains no body - return nil
|
|
// guard let body = martinMessage.body else {
|
|
// return nil
|
|
// }
|
|
//
|
|
// print("Message received: \(martinMessage)")
|
|
// print("From: \(martinMessage.from)")
|
|
// print("To: \(martinMessage.to)")
|
|
// print("Body: \(martinMessage.body)")
|
|
// print("Type: \(martinMessage.type)")
|
|
// print("Id: \(martinMessage.id)")
|
|
// print("Subject: \(martinMessage.subject)")
|
|
// print("----")
|
|
// print("!!!!!-----Message body: \(body)")
|
|
//
|
|
// // parse regular message
|
|
// return nil
|
|
// // Message(
|
|
// // id: message.id,
|
|
// // chatId: message.chatId,
|
|
// // fromJid: message.from,
|
|
// // toJid: message.to,
|
|
// // timestamp: message.timestamp,
|
|
// // body: message.body,
|
|
// // type: MessageType(rawValue: message.type) ?? .text
|
|
// // )
|
|
// }
|
|
// }
|