From 86745dc87db1f9e60d639404b94319635481e7ca Mon Sep 17 00:00:00 2001 From: fmodf Date: Tue, 23 Jul 2024 18:05:19 +0200 Subject: [PATCH] wip --- .../AppCore/Middlewares/LoggerMiddleware.swift | 2 +- .../AppCore/Models/Message.swift | 8 +++++++- .../AppCore/XMPP/XMPPService.swift | 18 +++--------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/ConversationsClassic/AppCore/Middlewares/LoggerMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/LoggerMiddleware.swift index eeeb308..811151b 100644 --- a/ConversationsClassic/AppCore/Middlewares/LoggerMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/LoggerMiddleware.swift @@ -5,7 +5,7 @@ import SwiftUI let isConsoleLoggingEnabled = false #if DEBUG - let prefixLength = 200 + let prefixLength = 400 func loggerMiddleware() -> Middleware { { state, action in let timeStr = dateFormatter.string(from: Date()) diff --git a/ConversationsClassic/AppCore/Models/Message.swift b/ConversationsClassic/AppCore/Models/Message.swift index 4e1dc30..c5fd963 100644 --- a/ConversationsClassic/AppCore/Models/Message.swift +++ b/ConversationsClassic/AppCore/Models/Message.swift @@ -81,6 +81,12 @@ extension Message { 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 var msg = Message( id: martinMessage.id ?? UUID().uuidString, @@ -92,7 +98,7 @@ extension Message { subject: martinMessage.subject, thread: martinMessage.thread, oobUrl: martinMessage.oob, - date: Date(), + date: date, pending: false, sentError: false, attachmentType: nil, diff --git a/ConversationsClassic/AppCore/XMPP/XMPPService.swift b/ConversationsClassic/AppCore/XMPP/XMPPService.swift index c753409..f3ce6a4 100644 --- a/ConversationsClassic/AppCore/XMPP/XMPPService.swift +++ b/ConversationsClassic/AppCore/XMPP/XMPPService.swift @@ -80,23 +80,11 @@ final class XMPPService: ObservableObject { }) .store(in: &clientMessagesCancellables) - // MAM - // client.module(.mam).$availableVersions.sink(receiveValue: { [weak client] versions in - // guard !versions.isEmpty, let client = client else { - // return - // } - // print("MAM available versions: \(versions)") - // // MessageEventHandler.syncMessagesScheduled(for: client) - // }).store(in: &clientMessagesCancellables) - client.module(.mam).archivedMessagesPublisher .sink(receiveValue: { [weak self] archived in - self?.clientMessagesPublisher.send((client, archived.message)) - // print("MAM archived message: \(archived.message)") - // guard let conversation = MessageEventHandler.conversationKey(for: archived.message, on: account) else { - // return - // } - // DBChatHistoryStore.instance.append(for: conversation, message: archived.message, source: .archive(source: archived.source, version: archived.query.version, messageId: archived.messageId, timestamp: archived.timestamp)) + let message = archived.message + message.attribute("archived_date", newValue: "\(archived.timestamp.timeIntervalSince1970)") + self?.clientMessagesPublisher.send((client, message)) }) .store(in: &clientMessagesCancellables)