Skip to content

Commit

Permalink
fixup! StringProviding integration
Browse files Browse the repository at this point in the history
Fixed PR discussions
  • Loading branch information
Egor Egorov committed Sep 22, 2023
1 parent 3715710 commit f63c010
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion GliaWidgets/Public/Glia/Glia.Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ extension Glia {
createdInteractor.withConfiguration { [weak createdInteractor, weak self] in
guard let createdInteractor, let self else { return }

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

createdInteractor.state = self.environment.coreSdk
.getCurrentEngagement()?.engagedOperator
Expand Down
2 changes: 1 addition & 1 deletion GliaWidgets/Public/Glia/Glia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class Glia {
createdInteractor.withConfiguration { [weak createdInteractor, weak self] in
guard let createdInteractor, let self else { return }

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

createdInteractor.state = self.environment.coreSdk
.getCurrentEngagement()?.engagedOperator
Expand Down
11 changes: 8 additions & 3 deletions GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Interface.swift
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 @@ -141,9 +142,6 @@ struct CoreSdkClient {

typealias CreateSendMessagePayload = (_ content: String, _ attachment: Attachment?) -> SendMessagePayload
var createSendMessagePayload: CreateSendMessagePayload

typealias CustomLocaleGetRemoteString = ((String) -> String?)
var getRemoteString: CustomLocaleGetRemoteString
}

extension CoreSdkClient {
Expand Down Expand Up @@ -174,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
4 changes: 2 additions & 2 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 Expand Up @@ -53,8 +54,7 @@ extension CoreSdkClient {
downloadSecureFile: GliaCore.sharedInstance.secureConversations.downloadFile(_:progress:completion:),
startSocketObservation: GliaCore.sharedInstance.startSocketObservation,
stopSocketObservation: GliaCore.sharedInstance.stopSocketObservation,
createSendMessagePayload: CoreSdkClient.SendMessagePayload.init(content:attachment:),
getRemoteString: GliaCore.sharedInstance.localeProvider.getRemoteString(_:)
createSendMessagePayload: CoreSdkClient.SendMessagePayload.init(content:attachment:)
)
}()
}
Expand Down
8 changes: 6 additions & 2 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 @@ -34,8 +35,7 @@ extension CoreSdkClient {
downloadSecureFile: { _, _, _ in .mock },
startSocketObservation: {},
stopSocketObservation: {},
createSendMessagePayload: { _, _ in .mock() },
getRemoteString: { _ in nil }
createSendMessagePayload: { _, _ in .mock() }
)
}

Expand All @@ -54,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
16 changes: 11 additions & 5 deletions 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 @@ -59,10 +60,6 @@ extension CoreSdkClient {
createSendMessagePayload: { _, _ in
fail("\(Self.self).createSendMessagePayload")
return .mock()
},
getRemoteString: { _ in
fail("\(Self.self).getRemoteString")
return nil
}
)
}
Expand Down Expand Up @@ -93,3 +90,12 @@ extension CoreSdkClient.AppDelegate {
}
)
}

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

0 comments on commit f63c010

Please sign in to comment.