diff --git a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift index 3e32485cc..be40a17be 100644 --- a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift +++ b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift @@ -39,6 +39,15 @@ public class AuthenticationServiceProvider: ObservableObject { .store(in: &disposeBag) // TODO: verify credentials for active authentication + currentActiveUser + .throttle(for: 3, scheduler: DispatchQueue.main, latest: true) + .sink { authBox in + guard let domain = authBox?.domain else { return } + Task { + await InstanceService.shared.updateInstance(domain: domain) + } + } + .store(in: &disposeBag) Task { if authenticationMigrationRequired { diff --git a/MastodonSDK/Sources/MastodonCore/Service/InstanceService.swift b/MastodonSDK/Sources/MastodonCore/Service/InstanceService.swift index 50ba5a624..49c73cb00 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/InstanceService.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/InstanceService.swift @@ -16,22 +16,6 @@ public final class InstanceService { static let shared = InstanceService() - var disposeBag = Set() - - // output - - init() { - AuthenticationServiceProvider.shared.currentActiveUser - .receive(on: DispatchQueue.main) - .asyncMap { [weak self] in - if let domain = $0?.domain { - await self?.updateInstance(domain: domain) - } - } - .sink {} - .store(in: &disposeBag) - } - } extension InstanceService {