2024-06-19 15:15:27 +00:00
|
|
|
import Foundation
|
|
|
|
import GRDB
|
2024-06-24 10:44:55 +00:00
|
|
|
import Martin
|
2024-06-19 15:15:27 +00:00
|
|
|
|
|
|
|
enum MessageType: String, Codable, DatabaseValueConvertible {
|
2024-06-24 10:44:55 +00:00
|
|
|
case chat
|
|
|
|
case channel
|
|
|
|
case groupchat
|
|
|
|
}
|
|
|
|
|
|
|
|
enum MessageContentType: String, Codable, DatabaseValueConvertible {
|
2024-06-19 15:15:27 +00:00
|
|
|
case text
|
|
|
|
case image
|
|
|
|
case video
|
|
|
|
case audio
|
|
|
|
case file
|
|
|
|
case location
|
2024-06-24 10:44:55 +00:00
|
|
|
case typing
|
|
|
|
case invite
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
|
|
|
|
2024-06-24 10:44:55 +00:00
|
|
|
struct MessageContainer: Stateable, DatabaseValueConvertible {
|
2024-06-19 15:15:27 +00:00
|
|
|
let id: String
|
2024-06-24 10:44:55 +00:00
|
|
|
let type: MessageType
|
|
|
|
let content: any MessageContent
|
|
|
|
}
|
2024-06-19 15:15:27 +00:00
|
|
|
|
2024-06-24 10:44:55 +00:00
|
|
|
protocol MessageContent: Stateable, DatabaseValueConvertible {
|
|
|
|
var type: MessageContentType { get }
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
2024-06-24 10:44:55 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// // )
|
|
|
|
// }
|
|
|
|
// }
|