diff --git a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift index a107ee7c9..d9e32849a 100644 --- a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift +++ b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift @@ -28,25 +28,15 @@ public class AuthenticationServiceProvider: ObservableObject { $mastodonAuthenticationBoxes .throttle(for: 3, scheduler: DispatchQueue.main, latest: true) .sink { [weak self] boxes in - let nowActive = boxes.first - guard nowActive?.authentication != self?.currentActiveUser.value?.authentication else { return } - self?.currentActiveUser.send(nowActive) - guard let nowActive = nowActive else { return } + guard let nowActive = boxes.first else { return } Task { [weak self] in try await self?.fetchFollowedBlockedUserIds(nowActive) } } .store(in: &disposeBag) - - + // TODO: verify credentials for active authentication - $authentications - .map { authentications -> [MastodonAuthenticationBox] in - return self.authenticationBoxes(authentications) - } - .assign(to: &$mastodonAuthenticationBoxes) - Task { if authenticationMigrationRequired { migrateLegacyAuthentications( @@ -64,8 +54,14 @@ public class AuthenticationServiceProvider: ObservableObject { } } - @Published private var authentications: [MastodonAuthentication] = [] { + private var authentications: [MastodonAuthentication] = [] { didSet { + let boxes = authenticationBoxes(authentications) + let nowActive = boxes.first + if nowActive?.authentication != self.currentActiveUser.value?.authentication { + self.currentActiveUser.send(nowActive) + } + mastodonAuthenticationBoxes = boxes persist(authentications) } }