Skip to content

Commit

Permalink
update for 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Sergey-K committed Jul 4, 2022
1 parent a6bd237 commit 2d75fba
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 89 deletions.
1 change: 1 addition & 0 deletions Core/UDConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public typealias UDValidModelBlock = (UseDeskModel) -> Void
@objc public protocol UDStorage {
func getMessages() -> [UDMessage]
func saveMessages(_ messages: [UDMessage])
func removeMessage(_ message: UDMessage)
}

public struct UseDeskModel {
Expand Down
60 changes: 34 additions & 26 deletions Core/UDConfigurationStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public struct ConfigurationStyle {
public var sendButtonStyle: SendButtonStyle
public var attachViewStyle: AttachViewStyle
public var messageButtonStyle: MessageButtonStyle
public var scrollButtonStyle: ScrollButtonStyle
public var feedbackFormStyle: FeedbackFormStyle
public var selectTopicFeedbackFormStyle: SelectTopicFeedbackFormStyle
public var baseStyle: BaseStyle
Expand All @@ -71,6 +72,7 @@ public struct ConfigurationStyle {
sendButtonStyle: SendButtonStyle = SendButtonStyle(),
attachViewStyle: AttachViewStyle = AttachViewStyle(),
messageButtonStyle: MessageButtonStyle = MessageButtonStyle(),
scrollButtonStyle: ScrollButtonStyle = ScrollButtonStyle(),
feedbackFormStyle: FeedbackFormStyle = FeedbackFormStyle(),
selectTopicFeedbackFormStyle: SelectTopicFeedbackFormStyle = SelectTopicFeedbackFormStyle(),
baseStyle: BaseStyle = BaseStyle(),
Expand All @@ -96,7 +98,7 @@ public struct ConfigurationStyle {
self.sendButtonStyle = sendButtonStyle
self.attachViewStyle = attachViewStyle
self.messageButtonStyle = messageButtonStyle
self.navigationBarStyle = navigationBarStyle
self.scrollButtonStyle = scrollButtonStyle
self.feedbackFormStyle = feedbackFormStyle
self.selectTopicFeedbackFormStyle = selectTopicFeedbackFormStyle
self.baseStyle = baseStyle
Expand Down Expand Up @@ -143,37 +145,13 @@ public struct ChatStyle {
public var backgroundColor: UIColor
public var backgroundColorLoaderView: UIColor
public var alphaLoaderView: CGFloat
public var scrollButtonImage: UIImage
public var scrollButtonSize: CGSize
public var scrollButtonMargin: UIEdgeInsets
public var newMessagesViewHeight: CGFloat
public var newMessagesViewMarginBottom: CGFloat
public var newMessagesViewColor: UIColor
public var newMessagesLabelFont: UIFont
public var newMessagesLabelColor: UIColor

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),
newMessagesViewDiameter: CGFloat = 20,
newMessagesViewMarginBottom: CGFloat = 10,
newMessagesViewColor: UIColor? = nil,
newMessagesLabelFont: UIFont = .systemFont(ofSize: 13),
newMessagesLabelColor: UIColor? = nil) {
alphaLoaderView: CGFloat = 0.8) {
self.backgroundColor = backgroundColor ?? UIColor(hexString: "FFFFFF")
self.backgroundColorLoaderView = backgroundColorLoaderView ?? .lightGray
self.alphaLoaderView = alphaLoaderView
self.scrollButtonImage = scrollButtonImage ?? UIImage.named("udScrollButton")
self.scrollButtonSize = scrollButtonSize
self.scrollButtonMargin = scrollButtonMargin
self.newMessagesViewHeight = newMessagesViewDiameter
self.newMessagesViewMarginBottom = newMessagesViewMarginBottom
self.newMessagesViewColor = newMessagesViewColor ?? UIColor(hexString: "EB5757")
self.newMessagesLabelFont = newMessagesLabelFont
self.newMessagesLabelColor = newMessagesLabelColor ?? .white
}
}
// MARK: - Date messages section
Expand Down Expand Up @@ -641,6 +619,36 @@ public struct MessageButtonStyle {
}
}

// MARK: - ScrollButtonStyle
public struct ScrollButtonStyle {
public var scrollButtonImage: UIImage
public var scrollButtonSize: CGSize
public var scrollButtonMargin: UIEdgeInsets
public var newMessagesViewHeight: CGFloat
public var newMessagesViewMarginBottom: CGFloat
public var newMessagesViewColor: UIColor
public var newMessagesLabelFont: UIFont
public var newMessagesLabelColor: UIColor

public init(scrollButtonImage: UIImage? = nil,
scrollButtonSize: CGSize = CGSize(width: 40, height: 40),
scrollButtonMargin: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 4, right: 12),
newMessagesViewDiameter: CGFloat = 20,
newMessagesViewMarginBottom: CGFloat = 10,
newMessagesViewColor: UIColor? = nil,
newMessagesLabelFont: UIFont = .systemFont(ofSize: 13),
newMessagesLabelColor: UIColor? = nil) {
self.scrollButtonImage = scrollButtonImage ?? UIImage.named("udScrollButton")
self.scrollButtonSize = scrollButtonSize
self.scrollButtonMargin = scrollButtonMargin
self.newMessagesViewHeight = newMessagesViewDiameter
self.newMessagesViewMarginBottom = newMessagesViewMarginBottom
self.newMessagesViewColor = newMessagesViewColor ?? UIColor(hexString: "EB5757")
self.newMessagesLabelFont = newMessagesLabelFont
self.newMessagesLabelColor = newMessagesLabelColor ?? .white
}
}

// MARK: - FeedbackFormStyle
public struct FeedbackFormStyle {
public var buttonColor: UIColor
Expand Down
7 changes: 5 additions & 2 deletions Core/UDNetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import Alamofire
public class UDNetworkManager {

public var model = UseDeskModel()
weak var usedesk: UseDeskSDK?

public weak var socket: SocketIOClient?
private var isAuthInited = false
private var isSendedAdditionalField = false
private var isSendedFirstMessage = false
private var isAuthSuccess = false
private var token: String? {
return model.token != "" ? model.token : loadToken()
Expand Down Expand Up @@ -398,7 +400,8 @@ public class UDNetworkManager {
}, setClientBlock: { [weak self] in
guard let wSelf = self else {return}
wSelf.socket?.emit("dispatch", with: UseDeskSDKHelp.dataClient(wSelf.model.email, phone: wSelf.model.phone, name: wSelf.model.name, note: wSelf.model.note, token: wSelf.token ?? "", additional_id: wSelf.model.additional_id)!) { [weak self] in
if self?.isAuthSuccess ?? false {
if (self?.isAuthSuccess ?? false) && !wSelf.isSendedFirstMessage {
wSelf.isSendedFirstMessage = true
if wSelf.model.firstMessage != "" {
let id = wSelf.newIdLoadingMessages()
wSelf.model.idLoadingMessages.append(id)
Expand Down Expand Up @@ -485,7 +488,7 @@ public class UDNetworkManager {
}

private func save(token: String) {
model.token = token
usedesk?.model.token = token
if model.isSaveTokensInUserDefaults {
let key = "usedeskClientToken\(model.email)\(model.phone)\(model.name)\(model.chanelId)"
UserDefaults.standard.set(token, forKey: key)
Expand Down
9 changes: 9 additions & 0 deletions Core/UDStorageMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public class UDStorageMessages: NSObject, UDStorage {
}
}

public func removeMessage(_ message: UDMessage) {
guard token.count > 0 else {return}
var messages = getMessages()
if let index = messages.firstIndex(of: message) {
messages.remove(at: index)
}
saveMessages(messages)
}

public func remove() {
if urlStorage != nil {
do {
Expand Down
8 changes: 5 additions & 3 deletions Core/UseDeskSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ public class UseDeskSDK: NSObject {

// MARK: - Ppivate Methods
private func startWithGUI(storageOutside: UDStorage? = nil, isCacheMessagesWithFile: Bool = true, parentController: UIViewController? = nil, startBlock: @escaping UDStartBlock, errorBlock: @escaping UDErrorBlock) {
storage = storageOutside != nil ? storageOutside : UDStorageMessages(token: model.token)
self.isCacheMessagesWithFile = isCacheMessagesWithFile

networkManager = UDNetworkManager(model: model)
setupUI()
isOpenSDKUI = true
setNetworkTracking()
storage = storageOutside

if model.isOpenKnowledgeBase {
startOnlyKnowledgeBase(parentController: parentController) { success in
Expand All @@ -188,6 +188,7 @@ public class UseDeskSDK: NSObject {
}
startWithoutGUICompanyID(companyID: model.companyID, chanelId: model.chanelId, url: model.urlWithoutPort, port: model.port, api_token: model.api_token, knowledgeBaseID: model.knowledgeBaseID, name: model.name, email: model.email, phone: model.phone, additionalFields: model.additionalFields, additionalNestedFields: model.additionalNestedFields) { [weak self] success, feedbackStatus, token in
guard let wSelf = self else { return }
wSelf.storage = storageOutside != nil ? storageOutside : UDStorageMessages(token: token)
wSelf.uiManager?.reloadDialogFlow(success: success, feedBackStatus: feedbackStatus, url: wSelf.model.url)
startBlock(success, feedbackStatus, token)
} errorStatus: { [weak self] error, description in
Expand Down Expand Up @@ -215,14 +216,15 @@ public class UseDeskSDK: NSObject {
if networkManager == nil {
networkManager = UDNetworkManager(model: model)
}
networkManager?.usedesk = self
networkManager?.model = model
networkManager?.socket = socket

networkManager?.socketConnect(socket: socket, connectBlock: connectBlock)
networkManager?.socketError(socket: socket, errorBlock: errorBlock)
networkManager?.socketDisconnect(socket: socket, connectBlock: connectBlock)
networkManager?.socketDispatch(socket: socket, startBlock: { [weak self] success, feedbackstatus, error in
startBlock(success, feedbackstatus, error)
networkManager?.socketDispatch(socket: socket, startBlock: { [weak self] success, feedbackstatus, token in
startBlock(success, feedbackstatus, token)
self?.connectBlock?(true)
}, historyMessagesBlock: { [weak self] messages in
self?.historyMess = messages
Expand Down
19 changes: 2 additions & 17 deletions Example/UseDesk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
A5CBE51F286C656900C3E4C7 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
);
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0B10A8E7AF3E75F60A94A1D6 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
2023EDE6BA4F6C85E59BE07C /* Pods_UseDesk_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_UseDesk_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -222,7 +209,6 @@
6003F588195388D20070C39A /* Resources */,
369CB9D3511D16A4B22EF133 /* [CP] Embed Pods Frameworks */,
4AD0D91D98463B258C5C9302 /* [CP] Copy Pods Resources */,
A5CBE51F286C656900C3E4C7 /* Embed App Extensions */,
);
buildRules = (
);
Expand Down Expand Up @@ -259,7 +245,6 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = UseDesk;
LastSwiftUpdateCheck = 1340;
LastUpgradeCheck = 1310;
ORGANIZATIONNAME = "serega@budyakov.com";
TargetAttributes = {
Expand Down Expand Up @@ -602,7 +587,7 @@
INFOPLIST_FILE = "UseDesk/UseDesk-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.1.0;
MARKETING_VERSION = 3.1.1;
MODULE_NAME = ExampleApp;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = UseDeskExampleSDK.ru;
Expand Down Expand Up @@ -634,7 +619,7 @@
INFOPLIST_FILE = "UseDesk/UseDesk-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.1.0;
MARKETING_VERSION = 3.1.1;
MODULE_NAME = ExampleApp;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = UseDeskExampleSDK.ru;
Expand Down
7 changes: 5 additions & 2 deletions UseDesk/Classes/DialogflowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ class DialogflowView: UDMessagesView {
DispatchQueue.main.async { [weak self] in
guard let wSelf = self else {return}
wSelf.loadMessagesFromStorage()
wSelf.messagesWithSection = wSelf.generateSectionFromModel(messages: wSelf.allMessages)
wSelf.messagesWithSection = wSelf.generateSection()
wSelf.configureAttachCollection()
wSelf.setFirstTextInTextInput()
wSelf.buttonAttach.isEnabled = true
wSelf.textInput.isUserInteractionEnabled = true
if !wSelf.isFromOfflineForm && !wSelf.isFromBase {
Expand Down Expand Up @@ -375,7 +377,7 @@ class DialogflowView: UDMessagesView {
newMessages.append(wSelf.allMessages[wSelf.allMessages.count - 1 - index])
}
wSelf.allMessages = newMessages
wSelf.messagesWithSection = wSelf.generateSectionFromModel(messages: wSelf.allMessages)
wSelf.messagesWithSection = wSelf.generateSection()
wSelf.tableNode.reloadData()
wSelf.buttonAttach.isEnabled = true
wSelf.textInput.isUserInteractionEnabled = true
Expand Down Expand Up @@ -550,6 +552,7 @@ class DialogflowView: UDMessagesView {
let repeatAction = UIAlertAction(title: usedesk!.model.stringFor("SendAgain"), style: .default, handler: { [weak self] (alert: UIAlertAction!) in
guard let wSelf = self else {return}
let message = wSelf.messagesWithSection[indexPath.section][indexPath.row]
wSelf.usedesk!.storage?.removeMessage(message)
message.statusSend = UD_STATUS_SEND_DRAFT
DispatchQueue.main.async {
if let index = wSelf.failMessages.firstIndex(where: {$0.loadingMessageId == message.loadingMessageId}) {
Expand Down
1 change: 1 addition & 0 deletions UseDesk/Classes/UDBaseKnowledgeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class UDBaseKnowledgeVC: UIViewController {
usedesk?.startWithoutGUICompanyID(companyID: usedesk!.model.companyID, chanelId: usedesk!.model.chanelId, url: usedesk!.model.urlWithoutPort, port: usedesk!.model.port, api_token: usedesk!.model.api_token, knowledgeBaseID: usedesk!.model.knowledgeBaseID, name: usedesk!.model.name, email: usedesk!.model.email, phone: usedesk!.model.phone, token: usedesk!.model.token, connectionStatus: { [weak self] success, feedbackStatus, token in
guard let wSelf = self else {return}
guard wSelf.usedesk != nil else {return}
wSelf.usedesk?.storage = wSelf.usedesk?.storage != nil ? wSelf.usedesk?.storage : UDStorageMessages(token: token)
if wSelf.usedesk!.closureStartBlock != nil {
wSelf.usedesk!.closureStartBlock!(success, feedbackStatus, token)
}
Expand Down
Loading

0 comments on commit 2d75fba

Please sign in to comment.