From 8e3bc0163210fe260d790eac25e8ae2a692149a1 Mon Sep 17 00:00:00 2001 From: Woit Date: Fri, 6 Dec 2024 13:34:31 +0100 Subject: [PATCH] wip --- .../XMPP/Wrappers/WrapperChat.swift | 26 +++++-------------- .../XMPP/Wrappers/WrapperXMPP.swift | 6 +++-- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Monal/another.im/XMPP/Wrappers/WrapperChat.swift b/Monal/another.im/XMPP/Wrappers/WrapperChat.swift index 4af1d81..20655e9 100644 --- a/Monal/another.im/XMPP/Wrappers/WrapperChat.swift +++ b/Monal/another.im/XMPP/Wrappers/WrapperChat.swift @@ -12,16 +12,18 @@ final class WrapperChat: ObservableObject { } let contact: Contact + let account: Account private let xmpp: MLXMPPManager private let db: DataLayer private let monalContact: MLContact private var notificationObservers: [AnyObject] = [] - init?(with: Contact) { + init?(with: Contact, account: Account) { contact = with xmpp = MLXMPPManager.sharedInstance() db = DataLayer.sharedInstance() + self.account = account guard let monalContact = db.contactList() @@ -36,9 +38,10 @@ final class WrapperChat: ObservableObject { NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil) } - init?(with: Chat) { + init?(with: Chat, account: Account) { xmpp = MLXMPPManager.sharedInstance() db = DataLayer.sharedInstance() + self.account = account guard let monalContact = db.contactList() @@ -73,21 +76,6 @@ final class WrapperChat: ObservableObject { // return chatModel } - // init(account: Account, contact: Contact, db: DataLayer, xmpp: MLXMPPManager) { - // self.contact = contact - // self.account = account - // self.db = db - // self.xmpp = xmpp - // - // monalContact = db.contactList().first { $0.accountID.intValue == contact.ownerId && $0.contactJid == contact.contactJid }! - // isOmemoEnabled = monalContact.isEncrypted - // - // subscribe() - // NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil) - // - // // - // } - deinit { notificationObservers.forEach { NotificationCenter.default.removeObserver($0) } } @@ -102,9 +90,7 @@ final class WrapperChat: ObservableObject { to: contact.contactJid, forAccount: monalContact.accountID, withMessage: text, - - // MARK: WARNING! - actuallyFrom: "testmon3@test.anal.company", + actuallyFrom: account.jid, withId: newMessageId, encrypted: monalContact.isEncrypted, messageType: kMessageTypeText, diff --git a/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift b/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift index 436eb98..2865913 100644 --- a/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift +++ b/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift @@ -57,11 +57,13 @@ extension WrapperXMPP { } func chat(with: Contact) -> WrapperChat? { - WrapperChat(with: with) + guard let account = accounts.first(where: { $0.id == with.ownerId }) else { return nil } + return WrapperChat(with: with, account: account) } func chat(with: Chat) -> WrapperChat? { - WrapperChat(with: with) + guard let account = accounts.first(where: { $0.id == with.accountId }) else { return nil } + return WrapperChat(with: with, account: account) } }