Skip to content

Commit

Permalink
fixup! Deprecate startEngagementWithConfig method
Browse files Browse the repository at this point in the history
This PR deprecates startEngagementWithConfig method and moves it to
deprecated methods file

MOB-2817
  • Loading branch information
rasmustautsglia committed Nov 10, 2023
1 parent f4233b5 commit 6aa5da3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 120 deletions.
72 changes: 25 additions & 47 deletions GliaWidgets/Public/Glia/Glia.Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
"""
)
Expand Down Expand Up @@ -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, Error>) -> Void
) throws {
try configure(
with: configuration,
theme: Theme(),
uiConfig: uiConfig,
assetsBuilder: assetsBuilder,
completion: completion
)
}
}
Expand Down
73 changes: 0 additions & 73 deletions GliaWidgets/Public/Glia/Glia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, Error>) -> 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
Expand Down

0 comments on commit 6aa5da3

Please sign in to comment.