Skip to content

Commit

Permalink
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 authored and github-review-helper committed Nov 13, 2023
1 parent f6352e1 commit c7c4b99
Show file tree
Hide file tree
Showing 14 changed files with 4,143 additions and 100 deletions.
4 changes: 0 additions & 4 deletions GliaWidgets.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@
755D187929A6A6F80009F5E8 /* WelcomeStyle+FilePickerButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D187829A6A6F80009F5E8 /* WelcomeStyle+FilePickerButtonStyle.swift */; };
755D187B29A6A7180009F5E8 /* WelcomeStyle+TitleImageStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D187A29A6A7180009F5E8 /* WelcomeStyle+TitleImageStyle.swift */; };
755D187F29A6B1B90009F5E8 /* Glia+StartEngagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D187E29A6B1B90009F5E8 /* Glia+StartEngagement.swift */; };
7562B2ED28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7562B2EC28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift */; };
756979C52A1E5E3C002ED254 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 756979C42A1E5E3C002ED254 /* Assets.xcassets */; };
756B8B1C2996B116001D2BB2 /* ChatCoordinator.Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756B8B1B2996B116001D2BB2 /* ChatCoordinator.Environment.swift */; };
756B8B1E2996BAEA001D2BB2 /* HeaderButton.Props.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756B8B1D2996BAEA001D2BB2 /* HeaderButton.Props.swift */; };
Expand Down Expand Up @@ -987,7 +986,6 @@
755D187829A6A6F80009F5E8 /* WelcomeStyle+FilePickerButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WelcomeStyle+FilePickerButtonStyle.swift"; sourceTree = "<group>"; };
755D187A29A6A7180009F5E8 /* WelcomeStyle+TitleImageStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WelcomeStyle+TitleImageStyle.swift"; sourceTree = "<group>"; };
755D187E29A6B1B90009F5E8 /* Glia+StartEngagement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Glia+StartEngagement.swift"; sourceTree = "<group>"; };
7562B2EC28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Glia.RemoteConfiguration.swift; sourceTree = "<group>"; };
756979C42A1E5E3C002ED254 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
756B8B1B2996B116001D2BB2 /* ChatCoordinator.Environment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatCoordinator.Environment.swift; sourceTree = "<group>"; };
756B8B1D2996BAEA001D2BB2 /* HeaderButton.Props.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderButton.Props.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2799,7 +2797,6 @@
children = (
AFBBF5772851C391004993B3 /* Glia.Deprecated.swift */,
7594098E298D3929008B173A /* Glia.OpaqueAuthentication.swift */,
7562B2EC28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift */,
1A60AF7D25656F0400E53F53 /* Glia.swift */,
755D187E29A6B1B90009F5E8 /* Glia+StartEngagement.swift */,
);
Expand Down Expand Up @@ -4529,7 +4526,6 @@
1A60AF93256674F900E53F53 /* Color.swift in Sources */,
1A38A8BA258B94D60089DE7B /* ImageView.swift in Sources */,
C0857DE528D470C1008D171D /* Theme+Shadow.swift in Sources */,
7562B2ED28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift in Sources */,
9AB196E227C4045B00FD60AB /* ChatViewController.Mock.swift in Sources */,
1A60B031256BF81500E53F53 /* VisitorChatMessageView.swift in Sources */,
1A5892B12608C68000E183CC /* QuickLookController.swift in Sources */,
Expand Down
2 changes: 0 additions & 2 deletions GliaWidgets/Public/Glia/Glia+StartEngagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extension Glia {
/// - Parameters:
/// - engagementKind: Engagement media type.
/// - in: Queue identifiers
/// - theme: A custom theme to use with the engagement.
/// - visitorContext: Visitor context.
/// - features: Set of features to be enabled in the SDK.
/// - sceneProvider: Used to provide `UIWindowScene` to the framework. Defaults to the first active foreground scene.
Expand All @@ -24,7 +23,6 @@ extension Glia {
public func startEngagement(
engagementKind: EngagementKind,
in queueIds: [String],
theme: Theme = Theme(),
features: Features = .all,
sceneProvider: SceneProvider? = nil
) throws {
Expand Down
81 changes: 80 additions & 1 deletion GliaWidgets/Public/Glia/Glia.Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension Glia {
/// Deprecated.
@available(
*,
deprecated,
unavailable,
message: "Use start(_:configuration:queueID:visitorContext:theme:features:sceneProvider:) with Optional<VisitorContext> instead."
)
public func start(
Expand Down Expand Up @@ -205,6 +205,85 @@ extension Glia {
debugPrint("💥 Core SDK configuration is not valid. Unexpected error='\(error)'.")
}
}

/// Deprecated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead.
/// Use ``configure(with configuration:uiConfig:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``.
@available(*, deprecated, message: """
Deprecated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead.
Use ``configure(with configuration:uiConfig:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``.
"""
)
public func startEngagementWithConfig(
engagement: EngagementKind,
in queueIds: [String],
uiConfig: RemoteConfiguration,
assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard,
features: Features = .all,
sceneProvider: SceneProvider? = nil
) throws {
// Store assetsBuilder and apply remote config to have ability to
// apply them for Call Visualizer flow if integrator use
// old `configure` method
theme.apply(configuration: uiConfig, assetsBuilder: assetsBuilder)
self.assetsBuilder = assetsBuilder

if let config = configuration {
theme.showsPoweredBy = !config.isWhiteLabelApp
theme.chat.connect.queue.firstText = config.companyName
theme.call.connect.queue.firstText = config.companyName
}

try startEngagement(
engagementKind: engagement,
in: queueIds,
theme: theme,
features: features,
sceneProvider: sceneProvider
)
}

/// Deprecated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead.
/// Use ``configure(with configuration:uiConfig:theme:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``.
@available(*, deprecated, message: """
Deprecated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead.
Use ``configure(with configuration:uiConfig:theme:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``.
"""
)
public func startEngagement(
engagementKind: EngagementKind,
in queueIds: [String],
theme: Theme = Theme(),
features: Features = .all,
sceneProvider: SceneProvider? = nil
) throws {
self.theme = theme
try startEngagement(
engagementKind: engagementKind,
in: queueIds,
features: features,
sceneProvider: sceneProvider
)
}

/// 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
)
}
}

extension Glia.Authentication {
Expand Down
57 changes: 0 additions & 57 deletions GliaWidgets/Public/Glia/Glia.RemoteConfiguration.swift

This file was deleted.

13 changes: 10 additions & 3 deletions GliaWidgets/Public/Glia/Glia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class Glia {
engagedOperator: { [weak self] in
self?.environment.coreSdk.getCurrentEngagement()?.engagedOperator
},
uiConfig: { [weak self] in self?.uiConfig },
theme: theme,
assetsBuilder: { [weak self] in self?.assetsBuilder ?? .standard },
getCurrentEngagement: environment.coreSdk.getCurrentEngagement,
eventHandler: onEvent,
Expand All @@ -92,31 +92,38 @@ public class Glia {
var interactor: Interactor?
var environment: Environment
var messageRenderer: MessageRenderer? = .webRenderer
var uiConfig: RemoteConfiguration?
var theme: Theme
var assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard

private(set) var configuration: Configuration?

init(environment: Environment) {
self.environment = environment
self.theme = Theme()
}

/// Setup SDK using specific engagement configuration without starting the engagement.
/// - Parameters:
/// - configuration: Engagement configuration.
/// - theme: A custom theme to use with the engagement.
/// - uiConfig: Remote UI configuration.
/// - assetsBuilder: Provides assets for remote configuration.
/// - completion: Completion handler that will be fired once configuration is complete.
public func configure(
with configuration: Configuration,
theme: Theme = Theme(),
uiConfig: RemoteConfiguration? = nil,
assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard,
completion: @escaping (Result<Void, Error>) -> Void
) throws {
guard environment.coreSdk.getCurrentEngagement() == nil else {
throw GliaError.configuringDuringEngagementIsNotAllowed
}
self.uiConfig = uiConfig

if let uiConfig {
theme.apply(configuration: uiConfig, assetsBuilder: assetsBuilder)
}
self.theme = theme
self.assetsBuilder = assetsBuilder
// `configuration` should be erased to avoid cases when integrators
// call `configure` and `startEngagement` asynchronously, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension CallVisualizer {
var audioSession: Glia.Environment.AudioSession
var date: () -> Date
var engagedOperator: () -> CoreSdkClient.Operator?
var uiConfig: () -> RemoteConfiguration?
var theme: Theme
var assetsBuilder: () -> RemoteConfiguration.AssetsBuilder
var getCurrentEngagement: CoreSdkClient.GetCurrentEngagement
var eventHandler: ((GliaEvent) -> Void)?
Expand Down
6 changes: 1 addition & 5 deletions GliaWidgets/Sources/CallVisualizer/CallVisualizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ public final class CallVisualizer {
private var environment: Environment
var delegate: ((Action) -> Void)?
lazy var coordinator: Coordinator = {
var theme = Theme()
if let uiConfig = environment.uiConfig() {
theme = .init(uiConfig: uiConfig, assetsBuilder: environment.assetsBuilder())
}
let viewFactory = ViewFactory(
with: theme,
with: environment.theme,
messageRenderer: nil,
environment: .init(
data: environment.data,
Expand Down
46 changes: 46 additions & 0 deletions GliaWidgets/Sources/Theme/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,50 @@ public class Theme {
assetsBuilder: assetsBuilder
)
}

func apply(
configuration: RemoteConfiguration,
assetsBuilder: RemoteConfiguration.AssetsBuilder
) {
color.apply(
configuration: configuration.globalColors
)

call.apply(
configuration: configuration.callScreen,
assetsBuilder: assetsBuilder
)
survey.apply(
configuration: configuration.surveyScreen,
assetsBuilder: assetsBuilder
)
alert.apply(
configuration: configuration.alert,
assetsBuilder: assetsBuilder
)
minimizedBubble.apply(
configuration: configuration.bubble,
assetsBuilder: assetsBuilder
)
chat.apply(
configuration: configuration.chatScreen,
assetsBuilder: assetsBuilder
)
visitorCode.apply(
configuration: configuration.callVisualizer?.visitorCode,
assetBuilder: assetsBuilder
)
screenSharing.apply(
configuration: configuration.callVisualizer?.screenSharing,
assetBuilder: assetsBuilder
)
secureConversationsWelcome.apply(
configuration: configuration.secureConversationsWelcomeScreen,
assetsBuilder: assetsBuilder
)
secureConversationsConfirmation.apply(
configuration: configuration.secureConversationsConfirmationScreen,
assetsBuilder: assetsBuilder
)
}
}
36 changes: 36 additions & 0 deletions GliaWidgets/Sources/Theme/ThemeColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,40 @@ public struct ThemeColor {
self.systemNegative = systemNegative ?? Color.systemNegative
self.baseNeutral = baseNeutral ?? Color.baseNeutral
}

mutating func apply(
configuration: RemoteConfiguration.GlobalColors?
) {
configuration?.primary.unwrap {
primary = UIColor(hex: $0)
}

configuration?.secondary.unwrap {
secondary = UIColor(hex: $0)
}

configuration?.baseNormal.unwrap {
baseNormal = UIColor(hex: $0)
}

configuration?.baseLight.unwrap {
baseLight = UIColor(hex: $0)
}

configuration?.baseDark.unwrap {
baseDark = UIColor(hex: $0)
}

configuration?.baseShade.unwrap {
baseShade = UIColor(hex: $0)
}

configuration?.systemNegative.unwrap {
systemNegative = UIColor(hex: $0)
}

configuration?.baseNeutral.unwrap {
baseNeutral = UIColor(hex: $0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension CallVisualizer.Environment {
audioSession: .mock,
date: { .mock },
engagedOperator: { .mock() },
uiConfig: { nil },
theme: .init(),
assetsBuilder: { .standard },
getCurrentEngagement: CoreSdkClient.mock.getCurrentEngagement,
orientationManager: .mock(),
Expand Down
8 changes: 4 additions & 4 deletions GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ extension GliaTests {
theme.call.connect.queue.firstText = "Glia 1"
theme.chat.connect.queue.firstText = "Glia 2"

try sdk.configure(with: .mock()) {
try sdk.configure(with: .mock(), theme: theme) { _ in
do {
try sdk.startEngagement(engagementKind: .chat, in: ["queueId"], theme: theme)
try sdk.startEngagement(engagementKind: .chat, in: ["queueId"])
} catch {
XCTFail("startEngagement unexpectedly failed with error \(error), but should succeed instead.")
}
Expand Down Expand Up @@ -275,9 +275,9 @@ extension GliaTests {
theme.call.connect.queue.firstText = "Glia 1"
theme.chat.connect.queue.firstText = "Glia 2"

try sdk.configure(with: .mock()) {
try sdk.configure(with: .mock(), theme: theme) { _ in
do {
try sdk.startEngagement(engagementKind: .chat, in: ["queueId"], theme: theme)
try sdk.startEngagement(engagementKind: .chat, in: ["queueId"])
} catch {
XCTFail("startEngagement unexpectedly failed with error \(error), but should succeed instead.")
}
Expand Down
Loading

0 comments on commit c7c4b99

Please sign in to comment.