From 7b0fe1a70ba0fde00f04f3ce89176897cca9b9cf Mon Sep 17 00:00:00 2001 From: shannon Date: Tue, 19 Nov 2024 11:43:10 -0500 Subject: [PATCH] Ensure that currentActiveUser is updated by the time activateUser() returns. contributes to iOS-319 --- .../AuthenticationServiceProvider.swift | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) 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) } }