This commit is contained in:
Woit 2024-12-05 18:14:22 +01:00
parent f8030ed60e
commit 006ae2a612

View file

@ -26,8 +26,6 @@ final class WrapperXMPP: ObservableObject {
// subscribe to monalxmpp notifications and fire notification for update // subscribe to monalxmpp notifications and fire notification for update
subscribeToUpdates() subscribeToUpdates()
processOnStart() processOnStart()
// xmpp.reconnectAll()
// NotificationCenter.default.post(name: Notification.Name(kMonalRefresh), object: nil)
} }
deinit { deinit {
@ -42,8 +40,6 @@ extension WrapperXMPP {
let result = await scenario.tryLogin(login, password) let result = await scenario.tryLogin(login, password)
if !result { if !result {
throw AimErrors.loginError throw AimErrors.loginError
} else {
processOnStart()
} }
} }
@ -78,8 +74,6 @@ extension WrapperXMPP {
semaphore.signal() semaphore.signal()
} }
semaphore.wait() semaphore.wait()
refreshChats()
refreshContacts()
contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid }) contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid })
} }
@ -95,17 +89,24 @@ private extension WrapperXMPP {
func subscribeToUpdates() { func subscribeToUpdates() {
notificationObservers.append( notificationObservers.append(
NotificationCenter.default.addObserver(forName: Notification.Name(kMonalRefresh), object: nil, queue: .main) { [weak self] notification in 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( notificationObservers.append(
NotificationCenter.default.addObserver(forName: Notification.Name(kMonalContactRefresh), object: nil, queue: .main) { [weak self] notification in 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( notificationObservers.append(
NotificationCenter.default.addObserver(forName: Notification.Name(kMonalContactRemoved), object: nil, queue: .main) { [weak self] notification in 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?") print("refresh?")
case kMonalContactRefresh: case kMonalContactRefresh:
if let mlContact = object as? MLContact { if let mlContact = object as? MLContact, !mlContact.isSelfChat {
if let updated = Contact(mlContact), let index = contacts.firstIndex(where: { $0.id == mlContact.id }) { if let contact = Contact(mlContact) {
contacts[index] = updated if let index = contacts.firstIndex(where: { $0.id == mlContact.id }) {
contacts[index] = contact
} else {
contacts.append(contact)
contacts.sort { $0.name < $1.name }
}
} }
} }