From 006ae2a612d8b485a9acb0d30f79ba09b94f84a6 Mon Sep 17 00:00:00 2001 From: Woit Date: Thu, 5 Dec 2024 18:14:22 +0100 Subject: [PATCH] wip --- .../XMPP/Wrappers/WrapperXMPP.swift | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift b/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift index 942bec1..9d07dc8 100644 --- a/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift +++ b/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift @@ -26,8 +26,6 @@ final class WrapperXMPP: ObservableObject { // subscribe to monalxmpp notifications and fire notification for update subscribeToUpdates() processOnStart() - // xmpp.reconnectAll() - // NotificationCenter.default.post(name: Notification.Name(kMonalRefresh), object: nil) } deinit { @@ -42,8 +40,6 @@ extension WrapperXMPP { let result = await scenario.tryLogin(login, password) if !result { throw AimErrors.loginError - } else { - processOnStart() } } @@ -78,8 +74,6 @@ extension WrapperXMPP { semaphore.signal() } semaphore.wait() - refreshChats() - refreshContacts() contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid }) } @@ -95,17 +89,24 @@ private extension WrapperXMPP { func subscribeToUpdates() { notificationObservers.append( NotificationCenter.default.addObserver(forName: Notification.Name(kMonalRefresh), object: nil, queue: .main) { [weak self] notification in - self?.processEvent(kMonalRefresh, notification.object) + self?.processEvent(kMonalRefresh, notification.userInfo?["contact"]) } ) notificationObservers.append( NotificationCenter.default.addObserver(forName: Notification.Name(kMonalContactRefresh), object: nil, queue: .main) { [weak self] notification in - self?.processEvent(kMonalContactRefresh, notification.object) + self?.processEvent(kMonalContactRefresh, notification.userInfo?["contact"]) } ) notificationObservers.append( NotificationCenter.default.addObserver(forName: Notification.Name(kMonalContactRemoved), object: nil, queue: .main) { [weak self] notification in - self?.processEvent(kMonalContactRemoved, notification.object) + self?.processEvent(kMonalContactRemoved, notification.userInfo?["contact"]) + } + ) + notificationObservers.append( + NotificationCenter.default.addObserver(forName: Notification.Name(kMLResourceBoundNotice), object: nil, queue: .main) { [weak self] _ in + self?.processOnStart() + // DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + // } } ) } @@ -117,9 +118,14 @@ private extension WrapperXMPP { print("refresh?") case kMonalContactRefresh: - if let mlContact = object as? MLContact { - if let updated = Contact(mlContact), let index = contacts.firstIndex(where: { $0.id == mlContact.id }) { - contacts[index] = updated + if let mlContact = object as? MLContact, !mlContact.isSelfChat { + if let contact = Contact(mlContact) { + if let index = contacts.firstIndex(where: { $0.id == mlContact.id }) { + contacts[index] = contact + } else { + contacts.append(contact) + contacts.sort { $0.name < $1.name } + } } }