This commit is contained in:
Woit 2024-11-22 15:45:38 +01:00
parent d1e3bc54bf
commit 4c42b21559
3 changed files with 16 additions and 2 deletions

View file

@ -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(

View file

@ -1,3 +1,4 @@
enum AimErrors: Error {
case loginError
case addContactError
}

View file

@ -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