From f8030ed60eb04e245dd35beea6620991e62262ab Mon Sep 17 00:00:00 2001 From: Woit Date: Wed, 4 Dec 2024 16:03:20 +0100 Subject: [PATCH] wip --- Monal/another.im/XMPP/Models/Contact.swift | 2 +- .../XMPP/Wrappers/WrapperXMPP.swift | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) 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