This commit is contained in:
Woit 2024-12-07 00:09:49 +01:00
parent cbe67fe3f1
commit b4a708ffad
3 changed files with 45 additions and 26 deletions

View file

@ -59,20 +59,21 @@ struct MessageAttr: View {
.foregroundColor(.Material.Shape.separator)
case .delivered:
HStack {
Image(systemName: "checkmark")
let img = Image(systemName: "checkmark")
Text("\(img)\(img)")
.font(.sub1)
.foregroundColor(.Material.Shape.separator)
Image(systemName: "checkmark")
.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()
}

View file

@ -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 {
if obj.inbound {
status = .inbound
} else {
if obj.hasBeenReceived {
status = .delivered
} else if !obj.errorType.isEmpty {
} else if obj.hasBeenSent {
status = .sent
} else {
if !obj.errorReason.isEmpty {
status = .error
} else {
status = .pending
}
} else {
status = .inbound
}
}
// print("AAAAAA", body, status, "\n", "orig: ", obj.hasBeenReceived, obj.hasBeenSent, " id:", dbId, " stanza:", stanzaId)
}
}

View file

@ -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,6 +139,15 @@ private extension WrapperChat {
}
func processEvent(notification: Notification) {
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 }) {
@ -144,6 +157,7 @@ private extension WrapperChat {
messages.sort { $0.timestamp > $1.timestamp }
}
}
}
func reloadMessages() {
let messages = db.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId))