From e6b3d856a7bcebc4182068521c3d080f7eec159f Mon Sep 17 00:00:00 2001 From: Woit Date: Fri, 6 Dec 2024 22:32:17 +0100 Subject: [PATCH] wip --- .../ConversationMessageContainer.swift | 34 +++++++++++++------ Monal/another.im/XMPP/Models/Message.swift | 23 +++++++++++++ .../XMPP/Wrappers/WrapperChat.swift | 14 +++++--- 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/Monal/another.im/Views/Conversation/ConversationMessageContainer.swift b/Monal/another.im/Views/Conversation/ConversationMessageContainer.swift index 7fdfed8..33b646d 100644 --- a/Monal/another.im/Views/Conversation/ConversationMessageContainer.swift +++ b/Monal/another.im/Views/Conversation/ConversationMessageContainer.swift @@ -45,16 +45,30 @@ struct MessageAttr: View { .foregroundColor(.Material.Shape.separator) } - // message state commented for now - // if message.status == .error { - // Image(systemName: "exclamationmark.circle") - // .font(.body3) - // .foregroundColor(.Rainbow.red500) - // } else if message.status == .pending { - // Image(systemName: "clock") - // .font(.body3) - // .foregroundColor(.Material.Shape.separator) - // } + switch message.status { + case .sent: + Image(systemName: "checkmark") + .font(.body3) + .foregroundColor(.Material.Shape.separator) + + case .delivered: + HStack { + Image(systemName: "checkmark") + .font(.body3) + .foregroundColor(.Material.Shape.separator) + Image(systemName: "checkmark") + .font(.body3) + .foregroundColor(.Material.Shape.separator) + } + + case .error: + Image(systemName: "exclamationmark.circle") + .font(.body3) + .foregroundColor(.Rainbow.red500) + + default: + EmptyView() + } } } } diff --git a/Monal/another.im/XMPP/Models/Message.swift b/Monal/another.im/XMPP/Models/Message.swift index dbceecc..259de75 100644 --- a/Monal/another.im/XMPP/Models/Message.swift +++ b/Monal/another.im/XMPP/Models/Message.swift @@ -1,6 +1,14 @@ 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 @@ -10,6 +18,7 @@ struct Message: Identifiable { let body: String let isInbound: Bool let encrypted: Bool + let status: MessageStatus var id: String { "\(accountId)|\(dbId)" @@ -25,5 +34,19 @@ struct Message: Identifiable { body = obj.messageText isInbound = obj.inbound encrypted = obj.encrypted + + if !obj.inbound { + if obj.hasBeenSent { + status = .sent + } else if obj.hasBeenReceived { + status = .delivered + } else if !obj.errorType.isEmpty { + status = .error + } else { + status = .pending + } + } else { + status = .inbound + } } } diff --git a/Monal/another.im/XMPP/Wrappers/WrapperChat.swift b/Monal/another.im/XMPP/Wrappers/WrapperChat.swift index 98b2133..3cac784 100644 --- a/Monal/another.im/XMPP/Wrappers/WrapperChat.swift +++ b/Monal/another.im/XMPP/Wrappers/WrapperChat.swift @@ -112,7 +112,7 @@ final class WrapperChat: ObservableObject { acc.setMAMQueryMostRecentFor(monalContact, before: lastStanzaId) { [weak self] msgs, _ in DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in self?.mamRequestInProgress = false - print(msgs) + print(msgs ?? []) } } } @@ -122,7 +122,8 @@ private extension WrapperChat { func subscribe() { let notificationNames = [ kMonalNewMessageNotice, - kMonalHistoryMessagesNotice + kMonalHistoryMessagesNotice, + kMonalMessageDisplayedNotice ] notificationObservers = notificationNames.map { name in NotificationCenter.default.addObserver(forName: Notification.Name(name), object: nil, queue: .main) { [weak self] notification in @@ -132,10 +133,13 @@ private extension WrapperChat { } func processEvent(notification: Notification) { - switch notification.name.rawValue { - default: - break + if let mlMessage = notification.userInfo?["message"] { + print("AAAAAAAAAA", mlMessage) } + // switch notification.name.rawValue { + // default: + // break + // } } func reloadMessages() {