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) {
let newMessageId = UUID().uuidString
_ = db.addMessageHistory(
let histId = db.addMessageHistory(
to: contact.contactJid,
forAccount: monalContact.accountID,
withMessage: text,
@ -97,7 +97,9 @@ final class WrapperChat: ObservableObject {
mimeType: 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)
}
@ -133,13 +135,14 @@ private extension WrapperChat {
}
func processEvent(notification: Notification) {
if let mlMessage = notification.userInfo?["message"] {
print("AAAAAAAAAA", mlMessage)
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 {
// default:
// break
// }
}
func reloadMessages() {