This commit is contained in:
Woit 2024-12-06 13:34:31 +01:00
parent 406b2fde1d
commit 8e3bc01632
2 changed files with 10 additions and 22 deletions

View file

@ -12,16 +12,18 @@ final class WrapperChat: ObservableObject {
} }
let contact: Contact let contact: Contact
let account: Account
private let xmpp: MLXMPPManager private let xmpp: MLXMPPManager
private let db: DataLayer private let db: DataLayer
private let monalContact: MLContact private let monalContact: MLContact
private var notificationObservers: [AnyObject] = [] private var notificationObservers: [AnyObject] = []
init?(with: Contact) { init?(with: Contact, account: Account) {
contact = with contact = with
xmpp = MLXMPPManager.sharedInstance() xmpp = MLXMPPManager.sharedInstance()
db = DataLayer.sharedInstance() db = DataLayer.sharedInstance()
self.account = account
guard guard
let monalContact = db.contactList() let monalContact = db.contactList()
@ -36,9 +38,10 @@ final class WrapperChat: ObservableObject {
NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil) NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil)
} }
init?(with: Chat) { init?(with: Chat, account: Account) {
xmpp = MLXMPPManager.sharedInstance() xmpp = MLXMPPManager.sharedInstance()
db = DataLayer.sharedInstance() db = DataLayer.sharedInstance()
self.account = account
guard guard
let monalContact = db.contactList() let monalContact = db.contactList()
@ -73,21 +76,6 @@ final class WrapperChat: ObservableObject {
// return chatModel // 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 { deinit {
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) } notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
} }
@ -102,9 +90,7 @@ final class WrapperChat: ObservableObject {
to: contact.contactJid, to: contact.contactJid,
forAccount: monalContact.accountID, forAccount: monalContact.accountID,
withMessage: text, withMessage: text,
actuallyFrom: account.jid,
// MARK: WARNING!
actuallyFrom: "testmon3@test.anal.company",
withId: newMessageId, withId: newMessageId,
encrypted: monalContact.isEncrypted, encrypted: monalContact.isEncrypted,
messageType: kMessageTypeText, messageType: kMessageTypeText,

View file

@ -57,11 +57,13 @@ extension WrapperXMPP {
} }
func chat(with: Contact) -> WrapperChat? { 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? { 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)
} }
} }