This commit is contained in:
Woit 2024-12-06 22:57:59 +01:00
parent 4378b2806c
commit cbe67fe3f1

View file

@ -86,7 +86,7 @@ final class WrapperChat: ObservableObject {
func sendText(_ text: String) { func sendText(_ text: String) {
let newMessageId = UUID().uuidString let newMessageId = UUID().uuidString
_ = db.addMessageHistory( let histId = db.addMessageHistory(
to: contact.contactJid, to: contact.contactJid,
forAccount: monalContact.accountID, forAccount: monalContact.accountID,
withMessage: text, withMessage: text,
@ -97,7 +97,9 @@ final class WrapperChat: ObservableObject {
mimeType: nil, mimeType: nil,
size: nil size: nil
) )
print(newMessageId) if let newMlMessage = db.message(forHistoryID: histId), let message = Message(newMlMessage) {
messages.insert(message, at: 0)
}
xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId) xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId)
} }
@ -133,13 +135,14 @@ private extension WrapperChat {
} }
func processEvent(notification: Notification) { func processEvent(notification: Notification) {
if let mlMessage = notification.userInfo?["message"] { guard let mlMessage = notification.userInfo?["message"] as? MLMessage else { return }
print("AAAAAAAAAA", mlMessage) 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 {
// default:
// break
// }
} }
func reloadMessages() { func reloadMessages() {