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) .foregroundColor(.Material.Shape.separator)
case .delivered: case .delivered:
HStack { let img = Image(systemName: "checkmark")
Image(systemName: "checkmark") Text("\(img)\(img)")
.font(.sub1) .font(.sub1)
.foregroundColor(.Material.Shape.separator) .foregroundColor(.Material.Shape.separator)
Image(systemName: "checkmark")
.font(.sub1)
.foregroundColor(.Material.Shape.separator)
}
case .error: case .error:
Image(systemName: "exclamationmark.circle") Image(systemName: "exclamationmark.circle")
.font(.sub1) .font(.sub1)
.foregroundColor(.Rainbow.red500) .foregroundColor(.Rainbow.red500)
case .pending:
Image(systemName: "clock")
.font(.sub1)
.foregroundColor(.Material.Shape.separator)
default: default:
EmptyView() EmptyView()
} }

View file

@ -35,18 +35,22 @@ struct Message: Identifiable {
isInbound = obj.inbound isInbound = obj.inbound
encrypted = obj.encrypted encrypted = obj.encrypted
if !obj.inbound { if obj.inbound {
if obj.hasBeenSent { status = .inbound
status = .sent } else {
} else if obj.hasBeenReceived { if obj.hasBeenReceived {
status = .delivered status = .delivered
} else if !obj.errorType.isEmpty { } else if obj.hasBeenSent {
status = .sent
} else {
if !obj.errorReason.isEmpty {
status = .error status = .error
} else { } else {
status = .pending 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) { if let newMlMessage = db.message(forHistoryID: histId), let message = Message(newMlMessage) {
messages.insert(message, at: 0) messages.insert(message, at: 0)
} }
print("CCCCC", newMessageId)
xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId) xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId)
} }
@ -125,6 +126,9 @@ private extension WrapperChat {
let notificationNames = [ let notificationNames = [
kMonalNewMessageNotice, kMonalNewMessageNotice,
kMonalHistoryMessagesNotice, kMonalHistoryMessagesNotice,
kMonalMessageDisplayedNotice,
kMonalMessageErrorNotice,
kMonalSentMessageNotice,
kMonalMessageDisplayedNotice kMonalMessageDisplayedNotice
] ]
notificationObservers = notificationNames.map { name in notificationObservers = notificationNames.map { name in
@ -135,6 +139,15 @@ private extension WrapperChat {
} }
func processEvent(notification: Notification) { 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 mlMessage = notification.userInfo?["message"] as? MLMessage else { return }
guard let message = Message(mlMessage) else { return } guard let message = Message(mlMessage) else { return }
if let index = messages.firstIndex(where: { $0.id == message.id }) { if let index = messages.firstIndex(where: { $0.id == message.id }) {
@ -144,6 +157,7 @@ private extension WrapperChat {
messages.sort { $0.timestamp > $1.timestamp } messages.sort { $0.timestamp > $1.timestamp }
} }
} }
}
func reloadMessages() { func reloadMessages() {
let messages = db.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId)) let messages = db.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId))