From f63c010f36be73536bf39bb1b23c0619a59dce7c Mon Sep 17 00:00:00 2001 From: Egor Egorov Date: Thu, 21 Sep 2023 17:21:56 +0300 Subject: [PATCH] fixup! StringProviding integration Fixed PR discussions --- GliaWidgets/Public/Glia/Glia.Deprecated.swift | 2 +- GliaWidgets/Public/Glia/Glia.swift | 2 +- .../CoreSDKClient/CoreSDKClient.Interface.swift | 11 ++++++++--- .../CoreSDKClient/CoreSDKClient.Live.swift | 4 ++-- .../CoreSDKClient/CoreSDKClient.Mock.swift | 8 ++++++-- GliaWidgetsTests/CoreSDKClient.Failing.swift | 16 +++++++++++----- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/GliaWidgets/Public/Glia/Glia.Deprecated.swift b/GliaWidgets/Public/Glia/Glia.Deprecated.swift index e71181e8b..96e8c7dd4 100644 --- a/GliaWidgets/Public/Glia/Glia.Deprecated.swift +++ b/GliaWidgets/Public/Glia/Glia.Deprecated.swift @@ -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 diff --git a/GliaWidgets/Public/Glia/Glia.swift b/GliaWidgets/Public/Glia/Glia.swift index d601a4af4..5fbf3c006 100644 --- a/GliaWidgets/Public/Glia/Glia.swift +++ b/GliaWidgets/Public/Glia/Glia.swift @@ -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 diff --git a/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Interface.swift b/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Interface.swift index b1c27b483..cb14acb1c 100644 --- a/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Interface.swift +++ b/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Interface.swift @@ -6,6 +6,7 @@ struct CoreSdkClient { var pushNotifications: PushNotifications var createAppDelegate: () -> AppDelegate var clearSession: () -> Void + var localeProvider: LocaleProvider typealias FetchVisitorInfo = (_ completion: @escaping (Result) -> Void) -> Void var fetchVisitorInfo: FetchVisitorInfo @@ -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 { @@ -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 diff --git a/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Live.swift b/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Live.swift index 67b0e31d7..c4823553a 100644 --- a/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Live.swift +++ b/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Live.swift @@ -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:), @@ -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:) ) }() } diff --git a/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Mock.swift b/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Mock.swift index f6f2f1ab6..f73d91be2 100644 --- a/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Mock.swift +++ b/GliaWidgets/Sources/CoreSDKClient/CoreSDKClient.Mock.swift @@ -7,6 +7,7 @@ extension CoreSdkClient { pushNotifications: .mock, createAppDelegate: { .mock }, clearSession: {}, + localeProvider: .mock, fetchVisitorInfo: { _ in }, updateVisitorInfo: { _, _ in }, configureWithConfiguration: { _, _ in }, @@ -34,8 +35,7 @@ extension CoreSdkClient { downloadSecureFile: { _, _, _ in .mock }, startSocketObservation: {}, stopSocketObservation: {}, - createSendMessagePayload: { _, _ in .mock() }, - getRemoteString: { _ in nil } + createSendMessagePayload: { _, _ in .mock() } ) } @@ -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) diff --git a/GliaWidgetsTests/CoreSDKClient.Failing.swift b/GliaWidgetsTests/CoreSDKClient.Failing.swift index cd9369450..b8f342fa4 100644 --- a/GliaWidgetsTests/CoreSDKClient.Failing.swift +++ b/GliaWidgetsTests/CoreSDKClient.Failing.swift @@ -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") }, @@ -59,10 +60,6 @@ extension CoreSdkClient { createSendMessagePayload: { _, _ in fail("\(Self.self).createSendMessagePayload") return .mock() - }, - getRemoteString: { _ in - fail("\(Self.self).getRemoteString") - return nil } ) } @@ -93,3 +90,12 @@ extension CoreSdkClient.AppDelegate { } ) } + +extension CoreSdkClient.LocaleProvider { + static let failing = Self( + getRemoteString: { _ in + fail("\(Self.self).getRemoteString") + return nil + } + ) +}