import Combine import GRDB import Martin final class ClientMartinMessagesManager { private var cancellable: AnyCancellable? init(_ xmppConnection: XMPPClient) { cancellable = xmppConnection.module(MessageModule.self).messagesPublisher .sink { [weak self] message in self?.handleClientMessage(message) } } private func handleClientMessage(_ martinMessage: MessageModule.MessageReceived) { #if DEBUG print("---") print("Message received: \(martinMessage)") print("---") #endif } } // // extension Message { // static func map(from martinMessage: Martin.Message) -> Message? { // #if DEBUG // print("---") // print("Message received: \(martinMessage)") // print("---") // #endif // // // Check that the message type is supported // let chatTypes: [StanzaType] = [.chat, .groupchat] // guard let mType = martinMessage.type, chatTypes.contains(mType) else { // #if DEBUG // print("Unsupported message type: \(martinMessage.type?.rawValue ?? "nil")") // #endif // return nil // } // // // Type // let type = MessageType(rawValue: martinMessage.type?.rawValue ?? "") ?? .chat // // // Content type // var contentType: MessageContentType = .text // if martinMessage.hints.contains(.noStore) { // contentType = .typing // } // // // From/To // let from = martinMessage.from?.bareJid.stringValue ?? "" // let to = martinMessage.to?.bareJid.stringValue // // // Extract date or set current // var date = Date() // if let timestampStr = martinMessage.attribute("archived_date"), let timeInterval = TimeInterval(timestampStr) { // date = Date(timeIntervalSince1970: timeInterval) // } // // // Msg // let msg = Message( // id: martinMessage.id ?? UUID().uuidString, // type: type, // date: date, // contentType: contentType, // status: .sent, // from: from, // to: to, // body: martinMessage.body, // subject: martinMessage.subject, // thread: martinMessage.thread, // oobUrl: martinMessage.oob // ) // return msg // } // }