wip
This commit is contained in:
parent
d1e3bc54bf
commit
4c42b21559
|
@ -124,7 +124,7 @@ struct AddContactOrChannelScreen: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
// try await clientsStore.addRoster(ownerCredentials, contactJID: contactJID, name: nil, groups: [])
|
try await wrapper.addContact(contactJid: contactJID, forAccountID: ownerAccount.id)
|
||||||
router.dismissScreen()
|
router.dismissScreen()
|
||||||
} catch {
|
} catch {
|
||||||
router.showAlert(
|
router.showAlert(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
enum AimErrors: Error {
|
enum AimErrors: Error {
|
||||||
case loginError
|
case loginError
|
||||||
|
case addContactError
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,10 @@ final class MonalXmppWrapper: ObservableObject {
|
||||||
deinit {
|
deinit {
|
||||||
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
|
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// try login
|
// MARK: - Public
|
||||||
|
extension MonalXmppWrapper {
|
||||||
func tryLogin(_ login: String, _ password: String) async throws {
|
func tryLogin(_ login: String, _ password: String) async throws {
|
||||||
let loginObject = LoginTry(xmpp: xmpp)
|
let loginObject = LoginTry(xmpp: xmpp)
|
||||||
let result = await loginObject.tryLogin(login, password)
|
let result = await loginObject.tryLogin(login, password)
|
||||||
|
@ -38,6 +40,17 @@ final class MonalXmppWrapper: ObservableObject {
|
||||||
NotificationCenter.default.post(name: Notification.Name(kMonalRefresh), object: nil)
|
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
|
// MARK: - Try login from Login screen
|
||||||
|
|
Loading…
Reference in a new issue