Skip to content

Commit

Permalink
update for 2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Sergey-K committed Oct 27, 2021
1 parent aa5a057 commit 21207e8
Show file tree
Hide file tree
Showing 19 changed files with 218 additions and 90 deletions.
27 changes: 26 additions & 1 deletion Core/UDConfigurationStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public struct ConfigurationStyle {
public var pictureStyle: PictureStyle
public var videoStyle: VideoStyle
public var fileStyle: FileStyle
public var fileViewingStyle: FileViewingStyle
public var inputViewStyle: InputViewStyle
public var attachButtonStyle: AttachButtonStyle
public var sendButtonStyle: SendButtonStyle
Expand All @@ -80,6 +81,7 @@ public struct ConfigurationStyle {
pictureStyle: PictureStyle = PictureStyle(),
videoStyle: VideoStyle = VideoStyle(),
fileStyle: FileStyle = FileStyle(),
fileViewingStyle: FileViewingStyle = FileViewingStyle(),
inputViewStyle: InputViewStyle = InputViewStyle(),
attachButtonStyle: AttachButtonStyle = AttachButtonStyle(),
sendButtonStyle: SendButtonStyle = SendButtonStyle(),
Expand All @@ -103,6 +105,7 @@ public struct ConfigurationStyle {
self.pictureStyle = pictureStyle
self.videoStyle = videoStyle
self.fileStyle = fileStyle
self.fileViewingStyle = fileViewingStyle
self.inputViewStyle = inputViewStyle
self.attachButtonStyle = attachButtonStyle
self.sendButtonStyle = sendButtonStyle
Expand Down Expand Up @@ -153,19 +156,25 @@ public struct ChatStyle {
public var scrollButtonImage: UIImage
public var scrollButtonSize: CGSize
public var scrollButtonMargin: UIEdgeInsets
public var topMarginPortrait: CGFloat
public var topMarginLandscape: CGFloat

public init(backgroundColor: UIColor? = nil,
backgroundColorLoaderView: UIColor? = nil,
alphaLoaderView: CGFloat = 0.8,
scrollButtonImage: UIImage? = nil,
scrollButtonSize: CGSize = CGSize(width: 40, height: 40),
scrollButtonMargin: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 4, right: 12)) {
scrollButtonMargin: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 4, right: 12),
topMarginPortrait: CGFloat = 0,
topMarginLandscape: CGFloat = 0) {
self.backgroundColor = backgroundColor != nil ? backgroundColor! : UIColor(hexString: "FFFFFF")
self.backgroundColorLoaderView = backgroundColorLoaderView != nil ? backgroundColorLoaderView! : .lightGray
self.alphaLoaderView = alphaLoaderView
self.scrollButtonImage = scrollButtonImage != nil ? scrollButtonImage! : UIImage.named("udScrollButton")
self.scrollButtonSize = scrollButtonSize
self.scrollButtonMargin = scrollButtonMargin
self.topMarginPortrait = topMarginPortrait
self.topMarginLandscape = topMarginLandscape
}
}
// MARK: - Date messages section
Expand Down Expand Up @@ -465,6 +474,22 @@ public struct FileStyle {
self.sizeIncomingColor = sizeIncomingColor != nil ? sizeIncomingColor! : UIColor(hexString: "989FB3")
}
}

// MARK: - FileViewing
public struct FileViewingStyle {
public var backButtonMargin: UIEdgeInsets
public var backButtonImage: UIImage
public var backButtonSize: CGSize

public init(backButtonMargin: UIEdgeInsets = UIEdgeInsets(top: 5, left: 2, bottom: 0, right: 0),
backButtonImage: UIImage? = nil,
backButtonSize: CGSize = CGSize(width: 26, height: 26)) {
self.backButtonMargin = backButtonMargin
self.backButtonImage = backButtonImage != nil ? backButtonImage! : UIImage.named("udBackInFileButton")
self.backButtonSize = backButtonSize
}
}

// MARK: - Input View
public struct InputViewStyle {
public var viewBackColor: UIColor
Expand Down
3 changes: 3 additions & 0 deletions Core/UDError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Alamofire
case tokenError
case falseInitChatError
case serverError
case socketError
case emptyKnowledgeBaseID

public init(errorCode: Int) {
Expand Down Expand Up @@ -51,6 +52,8 @@ import Alamofire
return "False init chat"
case .serverError:
return "Error in server"
case .socketError:
return "Error in socket"
case .emptyKnowledgeBaseID:
return "Empty knowledgeBaseID"
}
Expand Down
31 changes: 19 additions & 12 deletions Core/UseDeskSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public typealias UDSErrorSocketBlock = ([Any]?) -> Void
public typealias UDSErrorBlock = (UDError, String?) -> Void
public typealias UDSFeedbackMessageBlock = (UDMessage?) -> Void
public typealias UDSFeedbackAnswerMessageBlock = (Bool) -> Void
public typealias UDSVoidBlock = () -> Void

@objc public protocol UDStorage {
func getMessages() -> [UDMessage]
Expand All @@ -27,9 +28,9 @@ public typealias UDSFeedbackAnswerMessageBlock = (Bool) -> Void
public class UseDeskSDK: NSObject, UDUISetupable {
@objc public var newMessageBlock: UDSNewMessageBlock?
@objc public var connectBlock: UDSConnectBlock?
@objc public var errorBlock: UDSErrorSocketBlock?
@objc public var feedbackMessageBlock: UDSFeedbackMessageBlock?
@objc public var feedbackAnswerMessageBlock: UDSFeedbackAnswerMessageBlock?
@objc public var presentationCompletionBlock: UDSVoidBlock?
@objc public var historyMess: [UDMessage] = []
@objc public var maxCountAssets: Int = 10
@objc public var isSupportedAttachmentOnlyPhoto: Bool = false
Expand Down Expand Up @@ -71,6 +72,7 @@ public class UseDeskSDK: NSObject, UDUISetupable {
var token = ""
var additionalFields: [Int : String] = [:]
var additionalNestedFields: [[Int : String]] = []
var isPresentDefaultControllers = true
// Lolace
var locale: [String:String] = [:]

Expand All @@ -79,7 +81,7 @@ public class UseDeskSDK: NSObject, UDUISetupable {
private var serverToken = ""
private var isSendedAdditionalField = false

@objc public func start(withCompanyID _companyID: String, chanelId _chanelId: String, urlAPI _urlAPI: String? = nil, knowledgeBaseID _knowledgeBaseID: String? = nil, api_token _api_token: String, email _email: String? = nil, phone _phone: String? = nil, url _url: String, urlToSendFile _urlToSendFile: String? = nil, port _port: String? = nil, name _name: String? = nil, operatorName _operatorName: String? = nil, nameChat _nameChat: String? = nil, firstMessage _firstMessage: String? = nil, note _note: String? = nil, additionalFields _additionalFields: [Int : String] = [:], additionalNestedFields _additionalNestedFields: [[Int : String]] = [], token _token: String? = nil, localeIdentifier: String? = nil, customLocale: [String : String]? = nil, storage storageOutside: UDStorage? = nil, isCacheMessagesWithFile: Bool = true, presentIn parentController: UIViewController? = nil, isPresentDefaultControllers: Bool = true, connectionStatus startBlock: @escaping UDSStartBlock, errorStatus errorBlock: @escaping UDSErrorBlock) {
@objc public func start(withCompanyID _companyID: String, chanelId _chanelId: String, urlAPI _urlAPI: String? = nil, knowledgeBaseID _knowledgeBaseID: String? = nil, api_token _api_token: String, email _email: String? = nil, phone _phone: String? = nil, url _url: String, urlToSendFile _urlToSendFile: String? = nil, port _port: String? = nil, name _name: String? = nil, operatorName _operatorName: String? = nil, nameChat _nameChat: String? = nil, firstMessage _firstMessage: String? = nil, note _note: String? = nil, additionalFields _additionalFields: [Int : String] = [:], additionalNestedFields _additionalNestedFields: [[Int : String]] = [], token _token: String? = nil, localeIdentifier: String? = nil, customLocale: [String : String]? = nil, storage storageOutside: UDStorage? = nil, isCacheMessagesWithFile: Bool = true, presentIn parentController: UIViewController? = nil, isPresentDefaultControllers _isPresentDefaultControllers: Bool = true, connectionStatus startBlock: @escaping UDSStartBlock, errorStatus errorBlock: @escaping UDSErrorBlock) {
setupUI()
closureStartBlock = startBlock
closureErrorBlock = errorBlock
Expand Down Expand Up @@ -220,6 +222,8 @@ public class UseDeskSDK: NSObject, UDUISetupable {
locale = UDLocalizeManager().getLocaleFor(localeId: "ru")!
}

isPresentDefaultControllers = _isPresentDefaultControllers

storage = storageOutside != nil ? storageOutside : UDStorageMessages(token: token)
self.isCacheMessagesWithFile = isCacheMessagesWithFile

Expand All @@ -234,8 +238,8 @@ public class UseDeskSDK: NSObject, UDUISetupable {
}
startWithoutGUICompanyID(companyID: companyID, chanelId: chanelId, knowledgeBaseID: knowledgeBaseID, api_token: api_token, email: email, phone: _phone, url: urlWithoutPort, port: port, name: _name, operatorName: operatorName, nameChat: _nameChat, additionalFields: additionalFields, additionalNestedFields: additionalNestedFields) { [weak self] success, feedbackStatus, token in
guard let wSelf = self else { return }
startBlock(success, feedbackStatus, token)
wSelf.uiManager?.reloadDialogFlow(success: success, feedBackStatus: feedbackStatus, url: wSelf.url)
startBlock(success, feedbackStatus, token)
} errorStatus: { error, description in
errorBlock(error, description)
}
Expand Down Expand Up @@ -424,13 +428,11 @@ public class UseDeskSDK: NSObject, UDUISetupable {
wSelf.socket?.emit("dispatch", with: arrConfStart!, completion: nil)
})

socket?.on("error", callback: { [weak self] data, ack in
guard let wSelf = self else {return}
if (wSelf.errorBlock != nil) {
wSelf.errorBlock!(data)
if !isAuthInited {
errorBlock(.falseInitChatError, UDError.falseInitChatError.description)
}
socket?.on("error", callback: { data, ack in
if !isAuthInited {
errorBlock(.falseInitChatError, UDError.falseInitChatError.description)
} else {
errorBlock(.socketError, data.description)
}
})
socket?.on("disconnect", callback: { [weak self] data, ack in
Expand Down Expand Up @@ -508,7 +510,9 @@ public class UseDeskSDK: NSObject, UDUISetupable {
]
var url = urlBase()
url += "/v1/addFieldsToChat"
AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON{ responseJSON in }
AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseJSON{ responseJSON in

}
}

@objc public func getCollections(connectionStatus baseBlock: @escaping UDSBaseBlock, errorStatus errorBlock: @escaping UDSErrorBlock) {
Expand Down Expand Up @@ -768,7 +772,7 @@ public class UseDeskSDK: NSObject, UDUISetupable {
if self.urlAPI != "" {
url += self.urlAPI + "/uapi"
} else {
url += "api.usedesk.ru"
url += "https://secure.usedesk.ru/uapi"
}
return url
}
Expand Down Expand Up @@ -830,6 +834,7 @@ public class UseDeskSDK: NSObject, UDUISetupable {
}
}
socket?.emit("dispatch", with: UseDeskSDKHelp.dataClient(email, phone: phone, name: name, note: note, token: serverToken)!, completion: nil)
serverToken = ""
}
}

Expand Down Expand Up @@ -1385,7 +1390,9 @@ public class UseDeskSDK: NSObject, UDUISetupable {
firstMessage = ""
note = ""
token = ""
serverToken = ""
isOpenSDKUI = false
presentationCompletionBlock?()
}

public func newIdLoadingMessages() -> String {
Expand Down
8 changes: 4 additions & 4 deletions Example/UseDesk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,14 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.0;
CURRENT_PROJECT_VERSION = 2.0;
DEVELOPMENT_TEAM = HTC25B4YP8;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "UseDesk/UseDesk-Prefix.pch";
INFOPLIST_FILE = "UseDesk/UseDesk-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 2.2.0;
MARKETING_VERSION = 2.2.2;
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = UseDeskExampleSDK.ru;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -605,14 +605,14 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3.0;
CURRENT_PROJECT_VERSION = 2.0;
DEVELOPMENT_TEAM = HTC25B4YP8;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "UseDesk/UseDesk-Prefix.pch";
INFOPLIST_FILE = "UseDesk/UseDesk-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 2.2.0;
MARKETING_VERSION = 2.2.2;
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = UseDeskExampleSDK.ru;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
30 changes: 26 additions & 4 deletions Example/UseDesk/UDStartViewController/UDStartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class UDStartViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var lastViewBC: NSLayoutConstraint!
@IBOutlet weak var isNeedChatSwitch: UISwitch!
@IBOutlet weak var isNeedReviewSwitch: UISwitch!
@IBOutlet weak var isTabBarSwitch: UISwitch!

@IBOutlet weak var idField1: UITextField!
@IBOutlet weak var value1: UITextField!
Expand All @@ -47,6 +48,7 @@ class UDStartViewController: UIViewController, UITextFieldDelegate {

var collection: UDBaseCollection? = nil
var usedesk = UseDeskSDK()
let tabBarVC = UITabBarController()

override func viewDidLoad() {

Expand Down Expand Up @@ -172,11 +174,31 @@ class UDStartViewController: UIViewController, UITextFieldDelegate {
nameChat = nameChatTextField.text!
}
}
if isTabBarSwitch.isOn {
usedesk.configurationStyle = ConfigurationStyle(chatStyle: ChatStyle(topMarginPortrait: 80, topMarginLandscape: 40), baseStyle: BaseStyle(isNeedChat: isNeedChatSwitch.isOn), baseArticleStyle: BaseArticleStyle(isNeedReview: isNeedReviewSwitch.isOn))
} else {
usedesk.configurationStyle = ConfigurationStyle(baseStyle: BaseStyle(isNeedChat: isNeedChatSwitch.isOn), baseArticleStyle: BaseArticleStyle(isNeedReview: isNeedReviewSwitch.isOn))
}
usedesk.start(withCompanyID: companyIdTextField.text!, chanelId: chanelIdTextField.text != nil ? chanelIdTextField.text! : "", urlAPI: urlBaseTextField.text != nil ? urlBaseTextField.text! : nil, knowledgeBaseID: knowledgeBaseID, api_token: apiTokenTextField.text!, email: emailTextField.text!, phone: phoneTextField.text != nil ? phoneTextField.text! : nil, url: urlTextField.text!, urlToSendFile: urlToSendFileTextField.text!, port: portTextField.text!, name: nameTextField.text != nil ? nameTextField.text! : nil, operatorName: operatorNameTextField.text != nil ? operatorNameTextField.text! : nil, nameChat: nameChat, firstMessage: firstMessageTextField.text != nil ? firstMessageTextField.text : nil, note: noteTextField.text != nil ? noteTextField.text : nil, additionalFields: additionalFields(), additionalNestedFields: additionalNestedFields(), token: tokenTextField.text != nil ? tokenTextField.text : nil, localeIdentifier: localeIdTextField.text != nil ? localeIdTextField.text : nil, presentIn: self, isPresentDefaultControllers: !isTabBarSwitch.isOn, connectionStatus: { success, feedbackStatus, token in
if self.isTabBarSwitch.isOn && success {
let chatVC = self.usedesk.chatViewController() ?? UIViewController()
let firstVC = ViewController()
firstVC.title = "Second"
chatVC.title = "Chat"
self.tabBarVC.setViewControllers([chatVC, firstVC], animated: true)
self.navigationController?.pushViewController(self.tabBarVC, animated: true)
}
}, errorStatus: { _, _ in})

usedesk.configurationStyle = ConfigurationStyle(baseStyle: BaseStyle(isNeedChat: isNeedChatSwitch.isOn), baseArticleStyle: BaseArticleStyle(isNeedReview: isNeedReviewSwitch.isOn))
usedesk.presentationCompletionBlock = {
print("close SDK")
}
}
}
class ViewController: UIViewController {

usedesk.start(withCompanyID: companyIdTextField.text!, chanelId: chanelIdTextField.text != nil ? chanelIdTextField.text! : "", urlAPI: urlBaseTextField.text != nil ? urlBaseTextField.text! : nil, knowledgeBaseID: knowledgeBaseID, api_token: apiTokenTextField.text!, email: emailTextField.text!, phone: phoneTextField.text != nil ? phoneTextField.text! : nil, url: urlTextField.text!, urlToSendFile: urlToSendFileTextField.text!, port: portTextField.text!, name: nameTextField.text != nil ? nameTextField.text! : nil, operatorName: operatorNameTextField.text != nil ? operatorNameTextField.text! : nil, nameChat: nameChat, firstMessage: firstMessageTextField.text != nil ? firstMessageTextField.text : nil, note: noteTextField.text != nil ? noteTextField.text : nil, additionalFields: additionalFields(), additionalNestedFields: additionalNestedFields(), token: tokenTextField.text != nil ? tokenTextField.text : nil, localeIdentifier: localeIdTextField.text != nil ? localeIdTextField.text : nil, presentIn: self, connectionStatus: { success, feedbackStatus, token in
}, errorStatus: { _, _ in})
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .red
}
}
Loading

0 comments on commit 21207e8

Please sign in to comment.