From 54861dcf6ff3083ac59767b28e9d96f652334711 Mon Sep 17 00:00:00 2001 From: shannon Date: Mon, 27 Jan 2025 10:19:25 -0500 Subject: [PATCH] Quick fix for missing instance configuration For further work, see IOS-363 Fixes #1394 [BUG] Max. character limit server not honored Fixes #1396 [REGRESSION] Cannot translate posts --- .../MastodonCore/MastodonAuthentication.swift | 3 +++ .../MastodonCore/Service/InstanceService.swift | 15 ++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/MastodonSDK/Sources/MastodonCore/MastodonAuthentication.swift b/MastodonSDK/Sources/MastodonCore/MastodonAuthentication.swift index 4b2abcc45..1cb05deb4 100644 --- a/MastodonSDK/Sources/MastodonCore/MastodonAuthentication.swift +++ b/MastodonSDK/Sources/MastodonCore/MastodonAuthentication.swift @@ -87,6 +87,9 @@ public struct MastodonAuthentication: Codable, Hashable, UserIdentifier { accountCreatedAt: Date ) -> Self { let now = Date() + Task { + await InstanceService.shared.updateInstance(domain: domain) + } return MastodonAuthentication( identifier: .init(), domain: domain, diff --git a/MastodonSDK/Sources/MastodonCore/Service/InstanceService.swift b/MastodonSDK/Sources/MastodonCore/Service/InstanceService.swift index 25539a6cc..50ba5a624 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/InstanceService.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/InstanceService.swift @@ -14,20 +14,13 @@ import MastodonSDK @MainActor public final class InstanceService { + static let shared = InstanceService() + var disposeBag = Set() - - // input - let backgroundManagedObjectContext: NSManagedObjectContext - weak var apiService: APIService? // output - init( - apiService: APIService - ) { - self.backgroundManagedObjectContext = apiService.backgroundManagedObjectContext - self.apiService = apiService - + init() { AuthenticationServiceProvider.shared.currentActiveUser .receive(on: DispatchQueue.main) .asyncMap { [weak self] in @@ -45,7 +38,7 @@ extension InstanceService { @MainActor func updateInstance(domain: String) async { - guard let apiService else { return } + let apiService = APIService.shared guard let authBox = AuthenticationServiceProvider.shared.currentActiveUser.value, authBox.domain == domain else { return } let response = try? await apiService.instance(domain: domain, authenticationBox: authBox)