2022-11-17 10:22:13 +01:00
|
|
|
//
|
|
|
|
// AppContext+NextAccount.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by Marcus Kida on 17.11.22.
|
|
|
|
//
|
|
|
|
|
|
|
|
import MastodonCore
|
|
|
|
import MastodonSDK
|
|
|
|
|
|
|
|
extension AppContext {
|
|
|
|
func nextAccount(in authContext: AuthContext) -> MastodonAuthentication? {
|
2023-05-25 16:26:17 +02:00
|
|
|
let accounts = AuthenticationServiceProvider.shared.authentications
|
|
|
|
guard accounts.count > 1 else { return nil }
|
2022-11-17 10:22:13 +01:00
|
|
|
|
|
|
|
let nextSelectedAccountIndex: Int? = {
|
|
|
|
for (index, account) in accounts.enumerated() {
|
|
|
|
guard account == authContext.mastodonAuthenticationBox
|
2023-05-25 16:26:17 +02:00
|
|
|
.authentication
|
2022-11-17 10:22:13 +01:00
|
|
|
else { continue }
|
|
|
|
|
|
|
|
let nextAccountIndex = index + 1
|
|
|
|
|
|
|
|
if accounts.count > nextAccountIndex {
|
|
|
|
return nextAccountIndex
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}()
|
|
|
|
|
|
|
|
guard
|
|
|
|
let nextSelectedAccountIndex = nextSelectedAccountIndex,
|
|
|
|
accounts.count > nextSelectedAccountIndex
|
|
|
|
else { return nil }
|
|
|
|
|
|
|
|
return accounts[nextSelectedAccountIndex]
|
|
|
|
}
|
|
|
|
}
|