diff --git a/Monal/another.im/Views/Main/Contacts/AddContactOrChannelScreen.swift b/Monal/another.im/Views/Main/Contacts/AddContactOrChannelScreen.swift index a3d2752..ed76069 100644 --- a/Monal/another.im/Views/Main/Contacts/AddContactOrChannelScreen.swift +++ b/Monal/another.im/Views/Main/Contacts/AddContactOrChannelScreen.swift @@ -124,7 +124,7 @@ struct AddContactOrChannelScreen: View { } do { - // try await clientsStore.addRoster(ownerCredentials, contactJID: contactJID, name: nil, groups: []) + try await wrapper.addContact(contactJid: contactJID, forAccountID: ownerAccount.id) router.dismissScreen() } catch { router.showAlert( diff --git a/Monal/another.im/XMPP/AimErrors.swift b/Monal/another.im/XMPP/AimErrors.swift index dd621d5..dbd5786 100644 --- a/Monal/another.im/XMPP/AimErrors.swift +++ b/Monal/another.im/XMPP/AimErrors.swift @@ -1,3 +1,4 @@ enum AimErrors: Error { case loginError + case addContactError } diff --git a/Monal/another.im/XMPP/MonalXmppWrapper.swift b/Monal/another.im/XMPP/MonalXmppWrapper.swift index 0634dc6..3de914f 100644 --- a/Monal/another.im/XMPP/MonalXmppWrapper.swift +++ b/Monal/another.im/XMPP/MonalXmppWrapper.swift @@ -27,8 +27,10 @@ final class MonalXmppWrapper: ObservableObject { deinit { notificationObservers.forEach { NotificationCenter.default.removeObserver($0) } } +} - // try login +// MARK: - Public +extension MonalXmppWrapper { func tryLogin(_ login: String, _ password: String) async throws { let loginObject = LoginTry(xmpp: xmpp) let result = await loginObject.tryLogin(login, password) @@ -38,6 +40,17 @@ final class MonalXmppWrapper: ObservableObject { NotificationCenter.default.post(name: Notification.Name(kMonalRefresh), object: nil) } } + + func addContact(contactJid: String, forAccountID: Int) async throws { + _ = await Task { [weak self] in + let result = self?.db.addContact(contactJid, forAccount: NSNumber(value: forAccountID), nickname: nil) ?? true + if result { + NotificationCenter.default.post(name: Notification.Name(kMonalContactRefresh), object: nil) + } else { + throw AimErrors.addContactError + } + }.result + } } // MARK: - Try login from Login screen