diff --git a/Monal/another.im/XMPP/Models/Contact.swift b/Monal/another.im/XMPP/Models/Contact.swift index 51f1f63..fde0c18 100644 --- a/Monal/another.im/XMPP/Models/Contact.swift +++ b/Monal/another.im/XMPP/Models/Contact.swift @@ -6,7 +6,7 @@ struct Contact: Identifiable { let contactJid: String private let nickname: String? - var id: String { contactJid } + var id: String { "\(ownerId)|\(contactJid)" } var name: String { if let nickname { diff --git a/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift b/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift index d3bb5b8..942bec1 100644 --- a/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift +++ b/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift @@ -112,7 +112,25 @@ private extension WrapperXMPP { // Process monalxmpp events func processEvent(_ notificationName: String, _ object: Any?) { - print(notificationName, object) + switch notificationName { + case kMonalRefresh: + 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 + } + } + + case kMonalContactRemoved: + if let mlContact = object as? MLContact { + contacts = contacts.filter { $0.id != mlContact.id } + } + + default: + break + } } // Initital monalxmpp db fetch