Skip to content

Commit

Permalink
Merge pull request #17 from Teknasyon-Teknoloji/reports
Browse files Browse the repository at this point in the history
[some] Improvements for panel reports
  • Loading branch information
osmanyildirim authored Mar 20, 2023
2 parents ff5126f + fd20199 commit 9e71767
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 39 deletions.
3 changes: 1 addition & 2 deletions Desk360LiveChat.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Desk360LiveChat"
s.version = "1.0.8.1"
s.version = "1.0.9"
s.summary = "Desk360 Live Chat provides simplicity and usability in one place. With this feature, you can provide live support to your customers directly within your app just by writing a few lines of code."
s.homepage = "https://github.com/Teknasyon-Teknoloji/desk360-livechat-ios-sdk"
s.license = { :type => "Commercial", :file => "LICENSE" }
Expand All @@ -9,7 +9,6 @@ Pod::Spec.new do |s|
s.swift_version = "5.1"
s.ios.deployment_target = "12.0"
s.source_files = "Sources/**/*.swift"
#s.frameworks = "Foundation"

s.dependency 'Alamofire', '~> 5.0'
s.dependency 'PersistenceKit'
Expand Down
8 changes: 3 additions & 5 deletions Sources/Application/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ final class Session {
Storage.messageStore.deleteAll()
Storage.activeConversation.delete()
Storage.token.delete()
if forceDeleteCreds {
//Storage.credentails.delete()
}
try? Storage.isActiveConverationAvailable.save(false)
try? Storage.mesaagesCache.deleteAll()

try? Storage.isActiveConverationAvailable.save(false)
Storage.mesaagesCache.deleteAll()
try? Auth.liveChat.signOut()
NotificationCenter.default.post(.SessionTerminationNotification)
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/Core/Extensions/Foundations/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ extension NSAttributedString {
) else {
throw NSError(domain: "Parse Error", code: 0, userInfo: nil)
}
/*var attrs = attr.attributes(at: 0, effectiveRange: nil)
attrs[NSAttributedString.Key.font] = font
attr.setAttributes(attrs, range: NSRange(location: 0, length: attr.length))*/

let textRangeForFont : NSRange = NSMakeRange(0, attr.length)
attr.addAttributes([NSAttributedString.Key.font : font], range: textRangeForFont)
Expand Down
19 changes: 18 additions & 1 deletion Sources/Networking/Services/LoginService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Foundation
protocol LoginProvider {
func login(using credential: Credentials, smartPlugs: SmartPlug?, path: Int?, payload: [CannedResponsePayload]?) -> Future<AuthResponse, Error>
func authenticateSession(with token: Token) -> Future<Void, Error>
func startChatbotMessaging()
}

final class LoginProviding: LoginProvider {
Expand All @@ -33,7 +34,7 @@ final class LoginProviding: LoginProvider {
params["path_id"] = path
}

if let payload = payload {
if let payload = payload, !payload.isEmpty {
params["canned_response_payload"] = payload
}

Expand All @@ -60,6 +61,15 @@ final class LoginProviding: LoginProvider {
}
return promise.future
}

func startChatbotMessaging() {
var params: [String: Encodable] = ["source": "iOS", "application_id": ""]

if let appId = Storage.settings.object?.applicationID {
params["application_id"] = appId
}
let _: Future<EmptyResponse, Error> = client.post(to: .chatbotMessaging, parameters: params)
}
}

extension Endpoint {
Expand All @@ -82,4 +92,11 @@ extension Endpoint {
queryItems: notificationsParams
)
}

static var chatbotMessaging: Endpoint {
Endpoint(
path: "/api/v1/chat/sdk/canned-response/start",
queryItems: []
)
}
}
20 changes: 10 additions & 10 deletions Sources/Scenes/CannedResponse/CannedResponsePathCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ internal struct CannedResponsePayload: Encodable {
}

internal struct CannedResponsePathCollector {

static var shared = CannedResponsePathCollector()

private var paths: [CannedResponsePayload] = []
mutating func append(_ path: ResponseElement) {

func append(_ path: ResponseElement) {
let date = Double(Date().timeIntervalSince1970)
let payload = CannedResponsePayload(id: path.id, date: date)
self.paths.append(payload)
Self.shared.paths.append(payload)
}
mutating func reset() {
self.paths.removeAll()

func reset() {
Self.shared.paths.removeAll()
}

func getPayload() -> [CannedResponsePayload] {
return self.paths
return Self.shared.paths
}

}
15 changes: 7 additions & 8 deletions Sources/Scenes/CannedResponse/CannedResponseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Alper Tabak on 23.02.2022.
//

import Foundation
import FirebaseAuth

protocol CannedResponseViewModelType: AnyObject {
Expand Down Expand Up @@ -50,7 +49,6 @@ final class CannedResponseViewModel: CannedResponseViewModelType {
private var loginHandler: ((Agent?) -> Void)?
private var onlineAgentCount = 0
private var disabledElementFlag = 0
private var payloadCollector = CannedResponsePathCollector()
private var messages = [MessageCellViewModel]()

// MARK: - Computed Properties
Expand All @@ -77,6 +75,7 @@ final class CannedResponseViewModel: CannedResponseViewModelType {
self.agentProvider = agentProvider
self.loginProvider = loginProvider
self.router = router
CannedResponsePathCollector.shared.reset()
}

// MARK: - Methods
Expand All @@ -93,7 +92,7 @@ final class CannedResponseViewModel: CannedResponseViewModelType {
guard self.sections.indices.contains(lastSection) else { return }
guard let lastRow = self.sections.last?.lastIndex(where: { $0.id == element.id }) else { return }
self.sections[lastSection][lastRow].setSelected(value: true)
self.payloadCollector.append(element)
CannedResponsePathCollector.shared.append(element)
}

func goToPath(id: Int) {
Expand Down Expand Up @@ -125,12 +124,12 @@ final class CannedResponseViewModel: CannedResponseViewModelType {
self.resetHandler?()
disabledElementFlag = 0
self.latestUnitIndex = 0
self.payloadCollector.reset()
CannedResponsePathCollector.shared.reset()
self.start()
}

func sendFeedback(for survey: CannedResponseSurveyType) {
let payload = self.payloadCollector.getPayload()
let payload = CannedResponsePathCollector.shared.getPayload()
guard !payload.isEmpty else { return }
guard latestPathId != 0 else { return }
_ = self.feedbackProvider.send(pathId: self.latestPathId, type: survey, for: payload)
Expand Down Expand Up @@ -174,14 +173,14 @@ final class CannedResponseViewModel: CannedResponseViewModelType {
statusHandler?(.loading)

getOnlineCountFromCompany { [weak self] onlineCount in
guard let self = self else { return }
guard let self else { return }

guard onlineCount > 0 else {
self.statusHandler?(.showingData)
self.presentChatOrLoginPage(for: nil)
return
}
self.login(path: pathId, payload: self.payloadCollector.getPayload())
self.login(path: pathId, payload: CannedResponsePathCollector.shared.getPayload())
}

loginHandler = { [weak self] agent in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class TextMessageSizeCalculator: MessageSizeCalculator {
}
extraHeight += noOfLines > 20 ? 30 : 0
messageContainerSize.height += messageInsets.vertical + extraHeight
if cannedResponseActive && noOfLines > 4 {
//messageContainerSize.height += 40.0 //bottom gap
}

return messageContainerSize
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private extension ChatViewController {
if case .video(let item) = fileType {
self.viewModel.send(message: .video(item)) { _ in }
} else {
self.viewModel.send(message: .photo(fileType.item )) { _ in
self.viewModel.send(message: .photo(fileType.item)) { _ in

}
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/Scenes/Login/ViewModels/ContactInfoViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ final class ContactInfoViewModel {

func login(using name: String, email: String) -> Future<Void, Error> {
let creds = Credentials(name: name, email: email)
let payload = (Storage.settings.object?.isActiveCannedResponse ?? false) ? CannedResponsePathCollector.shared.getPayload() : []

return Session.shared
.startFlowWith(credentials: creds, smartPlug: self.smartPlug)
.startFlowWith(credentials: creds, smartPlug: self.smartPlug, payload: payload)
.flatMap(getOnlineAgent)
.observe(on: .main)
.map { agent in
Expand Down
15 changes: 10 additions & 5 deletions Sources/Scenes/Main/ViewModels/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import FirebaseAuth
import Foundation
import FirebaseDatabase

final class MainViewModel {
Expand Down Expand Up @@ -109,10 +108,12 @@ final class MainViewModel {
}

if let settings = Storage.settings.object, settings.isActiveCannedResponse {
DispatchQueue.main.async {
self.router?.trigger(.cannedResponse)
}
self.redirectHandler?()
startChatbotMessaging()

DispatchQueue.main.async {
self.router?.trigger(.cannedResponse)
}
self.redirectHandler?()
return
}

Expand Down Expand Up @@ -175,6 +176,10 @@ final class MainViewModel {
return agentProvider.getOnlineAgentInfo(uid: uid)
}

private func startChatbotMessaging() {
loginProvider.startChatbotMessaging()
}

// Normaly if the credentals are provided
func reLogin(credentails: Credentials) {
statusHandler?(.loading)
Expand Down

0 comments on commit 9e71767

Please sign in to comment.