40 lines
927 B
Swift
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
|
|
}
|
|
}
|
|
}
|