diff --git a/GliaWidgets/Public/Glia/Glia.Deprecated.swift b/GliaWidgets/Public/Glia/Glia.Deprecated.swift index 5babc7c9c..02bf64ae8 100644 --- a/GliaWidgets/Public/Glia/Glia.Deprecated.swift +++ b/GliaWidgets/Public/Glia/Glia.Deprecated.swift @@ -206,10 +206,10 @@ extension Glia { } } - /// Deprectated, use ``Glia.startEngagement(engagementKind:in queueIds:theme:features:sceneProvider:)`` instead. + /// Deprectated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead. /// Use ``configure(with configuration:uiConfig:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``. @available(*, deprecated, message: """ - Deprectated, use ``Glia.startEngagement(engagementKind:in queueIds:theme:features:sceneProvider:)`` instead. + Deprectated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead. Use ``configure(with configuration:uiConfig:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``. """ ) @@ -256,53 +256,31 @@ extension Glia { features: Features = .all, sceneProvider: SceneProvider? = nil ) throws { - let trimmedQueueIds = queueIds - .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } - .filter { !$0.isEmpty } - guard !trimmedQueueIds.isEmpty else { throw GliaError.startingEngagementWithNoQueueIdsIsNotAllowed } - guard engagement == .none else { throw GliaError.engagementExists } - guard let configuration = self.configuration else { throw GliaError.sdkIsNotConfigured } - if let engagement = environment.coreSdk.getCurrentEngagement(), - engagement.source == .callVisualizer { - throw GliaError.callVisualizerEngagementExists - } - - // Creates interactor instance - let createdInteractor = setupInteractor( - configuration: configuration, - queueIds: trimmedQueueIds - ) - - theme.chat.connect.queue.firstText = companyName( - using: configuration, - themeCompanyName: theme.chat.connect.queue.firstText - ) - - theme.call.connect.queue.firstText = companyName( - using: configuration, - themeCompanyName: theme.call.connect.queue.firstText - ) - - let viewFactory = ViewFactory( - with: theme, - messageRenderer: messageRenderer, - environment: .init( - data: environment.data, - uuid: environment.uuid, - gcd: environment.gcd, - imageViewCache: environment.imageViewCache, - timerProviding: environment.timerProviding, - uiApplication: environment.uiApplication, - uiScreen: environment.uiScreen - ) + try startEngagement( + engagementKind: engagementKind, + in: queueIds, + features: features, + sceneProvider: sceneProvider ) + } - startRootCoordinator( - with: createdInteractor, - viewFactory: viewFactory, - sceneProvider: sceneProvider, - engagementKind: engagementKind, - features: features + /// Deprecated, use ``configure(with configuration:theme:uiConfig:assetsBuilder:completion:)`` instead. + @available(*, deprecated, message: """ + Deprecated, use ``configure(with configuration:theme:uiConfig:assetsBuilder:completion:)`` instead. + """ + ) + public func configure( + with configuration: Configuration, + uiConfig: RemoteConfiguration? = nil, + assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard, + completion: @escaping (Result) -> Void + ) throws { + try configure( + with: configuration, + theme: Theme(), + uiConfig: uiConfig, + assetsBuilder: assetsBuilder, + completion: completion ) } } diff --git a/GliaWidgets/Public/Glia/Glia.swift b/GliaWidgets/Public/Glia/Glia.swift index ea026eaa7..0cdb186cd 100644 --- a/GliaWidgets/Public/Glia/Glia.swift +++ b/GliaWidgets/Public/Glia/Glia.swift @@ -402,79 +402,6 @@ extension Glia { } } -extension Glia { - /// Deprecated, use ``configure(with configuration:theme:uiConfig:assetsBuilder:completion:)`` instead. - @available(*, deprecated, message: """ - Deprecated, use ``configure(with configuration:theme:uiConfig:assetsBuilder:completion:)`` instead. - """ - ) - public func configure( - with configuration: Configuration, - uiConfig: RemoteConfiguration? = nil, - assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard, - completion: @escaping (Result) -> Void - ) throws { - guard environment.coreSdk.getCurrentEngagement() == nil else { - throw GliaError.configuringDuringEngagementIsNotAllowed - } - if let uiConfig { - theme.apply(configuration: uiConfig, assetsBuilder: assetsBuilder) - } - - self.assetsBuilder = assetsBuilder - // `configuration` should be erased to avoid cases when integrators - // call `configure` and `startEngagement` asynchronously, and - // second-time configuration has not been complete, but `startEngagement` - // is fired and SDK has previous `configuration`. - self.configuration = nil - - self.callVisualizer.delegate = { action in - switch action { - case .visitorCodeIsRequested: - self.setupInteractor(configuration: configuration) - } - } - - try environment.coreSDKConfigurator.configureWithConfiguration(configuration) { [weak self] result in - guard let self else { return } - switch result { - case .success: - // Storing `configuration` needs to be done once configuring SDK is complete - // Otherwise integrator can call `configure` and `startEngagement` - // asynchronously, without waiting configuration completion. - self.configuration = configuration - - let getRemoteString = self.environment.coreSdk.localeProvider.getRemoteString - self.stringProviding = .init(getRemoteString: getRemoteString) - - if let engagement = self.environment.coreSdk.getCurrentEngagement(), - engagement.source == .callVisualizer { - self.setupInteractor(configuration: configuration) - } - - completion(.success(())) - case .failure(let error): - typealias ProcessError = CoreSdkClient.ConfigurationProcessError - var errorForCompletion: GliaError = .internalError - - // To avoid the integrator having to figure out if an error is a `GliaError` - // or a `ConfigurationProcessError`, the `ConfigurationProcessError` is translated - // into a `GliaError`. - if let processError = error as? ProcessError { - if processError == .invalidSiteApiKeyCredentials { - errorForCompletion = GliaError.invalidSiteApiKeyCredentials - } else if processError == .localeRetrieval { - errorForCompletion = GliaError.invalidLocale - } - } - - debugPrint("💥 Core SDK configuration is not valid. Unexpected error='\(error)'.") - completion(.failure(errorForCompletion)) - } - } - } -} - #if DEBUG extension Glia { /// Used for unit tests only