another.im-ios/Monal/another.im/XMPP/MonalXmppWrapper.swift
2024-11-19 15:05:27 +01:00

40 lines
927 B
Swift

import Foundation
import monalxmpp
enum AccountsAvailability {
case noAccounts
case allDisabled
case someEnabled
}
final class MonalXmppWrapper: ObservableObject {
@Published var accountsAvailability: AccountsAvailability = .noAccounts
let xmpp: MLXMPPManager
let db: DataLayer
init() {
xmpp = MLXMPPManager.sharedInstance()
db = DataLayer.sharedInstance()
checkAccountsOnLoad()
}
}
// MARK: - Accounts
private extension MonalXmppWrapper {
// Check accounts state on launch
func checkAccountsOnLoad() {
let enabledAcocunts = db.enabledAccountList()
let allAccounts = db.accountList()
if allAccounts.isEmpty {
accountsAvailability = .noAccounts
} else if !enabledAcocunts.isEmpty {
accountsAvailability = .someEnabled
} else {
accountsAvailability = .allDisabled
}
}
}