From 3e6d75e1b5f0bd7a03f27e1206750f85b87bef01 Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Tue, 9 May 2023 16:03:37 +0200 Subject: [PATCH] Update in-memory following/blocking states upon (un)follow/block action (IOS-140) --- .../Protocol/Provider/DataSourceFacade+Block.swift | 1 + .../Protocol/Provider/DataSourceFacade+Follow.swift | 1 + .../MastodonCore/Service/AuthenticationService.swift | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Block.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Block.swift index 2cf6e3419..3f8693476 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Block.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Block.swift @@ -28,5 +28,6 @@ extension DataSourceFacade { try await dependency.context.apiService.getBlocked( authenticationBox: authBox ) + dependency.context.authenticationService.fetchFollowingAndBlockedAsync() } // end func } diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift index a85de703a..2c221bc9b 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift @@ -24,6 +24,7 @@ extension DataSourceFacade { user: user, authenticationBox: dependency.authContext.mastodonAuthenticationBox ) + dependency.context.authenticationService.fetchFollowingAndBlockedAsync() } // end func } diff --git a/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift b/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift index a865286cb..10a37613e 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift @@ -67,6 +67,16 @@ public final class AuthenticationService: NSObject { return (ids, maxID) } + public func fetchFollowingAndBlockedAsync() { + /// we're dispatching this as a separate async call to not block the callee + Task { + for authBox in mastodonAuthenticationBoxes { + do { try await fetchFollowedBlockedUserIds(authBox) } + catch {} + } + } + } + public let updateActiveUserAccountPublisher = PassthroughSubject() init(