Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#F StringProviding integration #779

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions GliaWidgets/Public/Glia/Glia.Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,15 @@ extension Glia {
interactor = createdInteractor

if let callback = completion {
createdInteractor.withConfiguration { [weak createdInteractor] in
guard let interactor = createdInteractor else { return }
interactor.state = GliaCore.sharedInstance
.getCurrentEngagement()?.engagedOperator
.map(InteractorState.engaged) ?? interactor.state
callback()
createdInteractor.withConfiguration { [weak createdInteractor, weak self] in
guard let createdInteractor, let self else { return }

self.stringProviding = .init(getRemoteString: self.environment.coreSdk.localeProvider.getRemoteString)

createdInteractor.state = self.environment.coreSdk
.getCurrentEngagement()?.engagedOperator
.map(InteractorState.engaged) ?? createdInteractor.state
callback()
}
}

Expand Down
12 changes: 6 additions & 6 deletions GliaWidgets/Public/Glia/Glia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ public class Glia {
interactor = createdInteractor

if let callback = completion {
createdInteractor.withConfiguration { [weak createdInteractor] in
guard let interactor = createdInteractor else { return }
createdInteractor.withConfiguration { [weak createdInteractor, weak self] in
guard let createdInteractor, let self else { return }

// TODO: Configure string providing from Core SDK here.
self.stringProviding = .init(getRemoteString: self.environment.coreSdk.localeProvider.getRemoteString)

interactor.state = GliaCore.sharedInstance
createdInteractor.state = self.environment.coreSdk
.getCurrentEngagement()?.engagedOperator
.map(InteractorState.engaged) ?? interactor.state
.map(InteractorState.engaged) ?? createdInteractor.state

callback()
}
Expand All @@ -149,7 +149,7 @@ public class Glia {
rootCoordinator?.minimize()
}

/// Maximizes engagement view if ongoing engagment exists.
/// Maximizes engagement view if ongoing engagement exists.
/// Throws error if ongoing engagement not exist.
/// Use this function for resuming engagement view If bubble is hidden programmatically and you need to
/// present engagement view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct CoreSdkClient {
var pushNotifications: PushNotifications
var createAppDelegate: () -> AppDelegate
var clearSession: () -> Void
var localeProvider: LocaleProvider

typealias FetchVisitorInfo = (_ completion: @escaping (Result<Self.Salemove.VisitorInfo, Error>) -> Void) -> Void
var fetchVisitorInfo: FetchVisitorInfo
Expand Down Expand Up @@ -171,6 +172,13 @@ extension CoreSdkClient {
}
}

extension CoreSdkClient {
struct LocaleProvider {
typealias CustomLocaleGetRemoteString = ((String) -> String?)
var getRemoteString: CustomLocaleGetRemoteString
}
}

extension CoreSdkClient {
typealias AnswerBlock = GliaCoreSDK.AnswerBlock
typealias AnswerWithSuccessBlock = GliaCoreSDK.AnswerWithSuccessBlock
Expand Down
1 change: 1 addition & 0 deletions GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extension CoreSdkClient {
pushNotifications: .live,
createAppDelegate: Self.AppDelegate.live,
clearSession: GliaCore.sharedInstance.clearSession,
localeProvider: .init(getRemoteString: GliaCore.sharedInstance.localeProvider.getRemoteString(_:)),
fetchVisitorInfo: GliaCore.sharedInstance.fetchVisitorInfo(_:),
updateVisitorInfo: GliaCore.sharedInstance.updateVisitorInfo(_:completion:),
configureWithConfiguration: GliaCore.sharedInstance.configure(with:completion:),
Expand Down
5 changes: 5 additions & 0 deletions GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extension CoreSdkClient {
pushNotifications: .mock,
createAppDelegate: { .mock },
clearSession: {},
localeProvider: .mock,
fetchVisitorInfo: { _ in },
updateVisitorInfo: { _, _ in },
configureWithConfiguration: { _, _ in },
Expand Down Expand Up @@ -53,6 +54,10 @@ extension CoreSdkClient.AppDelegate {
)
}

extension CoreSdkClient.LocaleProvider {
static let mock = Self(getRemoteString: { _ in nil })
}

extension CoreSdkClient.EngagementFile {
static func mock(id: String = "") -> CoreSdkClient.EngagementFile {
.init(id: id)
Expand Down
12 changes: 11 additions & 1 deletion GliaWidgetsTests/CoreSDKClient.Failing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ extension CoreSdkClient {
pushNotifications: .failing,
createAppDelegate: { .failing },
clearSession: { fail("\(Self.self).clearSession") },
localeProvider: .failing,
fetchVisitorInfo: { _ in fail("\(Self.self).fetchVisitorInfo") },
updateVisitorInfo: { _, _ in fail("\(Self.self).updateVisitorInfo") },
configureWithConfiguration: { _, _ in fail("\(Self.self).configureWithConfiguration") },
configureWithInteractor: { _ in fail("\(Self.self).configureWithInteractor") },
listQueues: {_ in fail("\(Self.self).listQueues") },
listQueues: { _ in fail("\(Self.self).listQueues") },
queueForEngagement: { _, _ in fail("\(Self.self).queueForEngagement") },
requestMediaUpgradeWithOffer: { _, _ in fail("\(Self.self).requestMediaUpgradeWithOffer") },
sendMessagePreview: { _, _ in fail("\(Self.self).sendMessagePreview") },
Expand Down Expand Up @@ -89,3 +90,12 @@ extension CoreSdkClient.AppDelegate {
}
)
}

extension CoreSdkClient.LocaleProvider {
static let failing = Self(
getRemoteString: { _ in
fail("\(Self.self).getRemoteString")
return nil
}
)
}