another.im-ios/Monal/another.im/XMPP/MonalXmppWrapper.swift

40 lines
927 B
Swift
Raw Normal View History

2024-11-19 12:59:22 +00:00
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
}
}
}