diff --git a/Monal/another.im/Views/Conversation/ConversationMessageContainer.swift b/Monal/another.im/Views/Conversation/ConversationMessageContainer.swift index 2c0f90a..379669b 100644 --- a/Monal/another.im/Views/Conversation/ConversationMessageContainer.swift +++ b/Monal/another.im/Views/Conversation/ConversationMessageContainer.swift @@ -59,20 +59,21 @@ struct MessageAttr: View { .foregroundColor(.Material.Shape.separator) case .delivered: - HStack { - Image(systemName: "checkmark") - .font(.sub1) - .foregroundColor(.Material.Shape.separator) - Image(systemName: "checkmark") - .font(.sub1) - .foregroundColor(.Material.Shape.separator) - } + let img = Image(systemName: "checkmark") + Text("\(img)\(img)") + .font(.sub1) + .foregroundColor(.Material.Shape.separator) case .error: Image(systemName: "exclamationmark.circle") .font(.sub1) .foregroundColor(.Rainbow.red500) + case .pending: + Image(systemName: "clock") + .font(.sub1) + .foregroundColor(.Material.Shape.separator) + default: EmptyView() } diff --git a/Monal/another.im/XMPP/Models/Message.swift b/Monal/another.im/XMPP/Models/Message.swift index 259de75..73e31a6 100644 --- a/Monal/another.im/XMPP/Models/Message.swift +++ b/Monal/another.im/XMPP/Models/Message.swift @@ -35,18 +35,22 @@ struct Message: Identifiable { 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 { + if obj.inbound { status = .inbound + } else { + if obj.hasBeenReceived { + status = .delivered + } else if obj.hasBeenSent { + status = .sent + } else { + if !obj.errorReason.isEmpty { + status = .error + } else { + status = .pending + } + } } + + // print("AAAAAA", body, status, "\n", "orig: ", obj.hasBeenReceived, obj.hasBeenSent, " id:", dbId, " stanza:", stanzaId) } } diff --git a/Monal/another.im/XMPP/Wrappers/WrapperChat.swift b/Monal/another.im/XMPP/Wrappers/WrapperChat.swift index b4550ad..307b47f 100644 --- a/Monal/another.im/XMPP/Wrappers/WrapperChat.swift +++ b/Monal/another.im/XMPP/Wrappers/WrapperChat.swift @@ -100,6 +100,7 @@ final class WrapperChat: ObservableObject { if let newMlMessage = db.message(forHistoryID: histId), let message = Message(newMlMessage) { messages.insert(message, at: 0) } + print("CCCCC", newMessageId) xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId) } @@ -125,6 +126,9 @@ private extension WrapperChat { let notificationNames = [ kMonalNewMessageNotice, kMonalHistoryMessagesNotice, + kMonalMessageDisplayedNotice, + kMonalMessageErrorNotice, + kMonalSentMessageNotice, kMonalMessageDisplayedNotice ] notificationObservers = notificationNames.map { name in @@ -135,13 +139,23 @@ private extension WrapperChat { } func processEvent(notification: Notification) { - guard let mlMessage = notification.userInfo?["message"] as? MLMessage else { return } - guard let message = Message(mlMessage) else { return } - if let index = messages.firstIndex(where: { $0.id == message.id }) { - messages[index] = message - } else { - messages.append(message) - messages.sort { $0.timestamp > $1.timestamp } + switch notification.name.rawValue { + case kMonalSentMessageNotice: + if let stanza = notification.userInfo?["message"] as? XMPPStanza, let id = stanza.id { + if let index = messages.firstIndex(where: { $0.stanzaId == id }) { + print(index) + } + } + + default: + guard let mlMessage = notification.userInfo?["message"] as? MLMessage else { return } + guard let message = Message(mlMessage) else { return } + if let index = messages.firstIndex(where: { $0.id == message.id }) { + messages[index] = message + } else { + messages.append(message) + messages.sort { $0.timestamp > $1.timestamp } + } } }