Skip to content

Commit 393e84d

Browse files
authored
Merge pull request #501 from Kommunicate-io/CM-2361
[CM-2361] File Titles and Comments update to KMCore and KMChat from AL | iOS SDK (Part - 1)
2 parents 7818877 + e0f8122 commit 393e84d

13 files changed

+62
-62
lines changed

Example/Tests/ConversationVCNavBarSnapshotTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class ConversationVCNavBarSnapshotTests: QuickSpec, NavigationBarCallbacks {
2222
return alContact
2323
}()
2424

25-
let mockChannel: ALChannel = {
26-
let channel = ALChannel()
25+
let mockChannel: KMCoreChannel = {
26+
let channel = KMCoreChannel()
2727
channel.key = 1_244_444
2828
channel.name = "Demo Display Name"
2929
channel.type = Int16(SUPPORT_GROUP.rawValue)

Example/Tests/KommunicateTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class KommunicateTests: XCTestCase {
3939
override func getLatestMessages(_: Bool, withCompletionHandler completion: ((NSMutableArray?, Error?) -> Void)!) {
4040
let messageList: NSMutableArray = []
4141
for _ in 0 ..< KommunicateClientMock.messageCount {
42-
let message = ALMessage()
42+
let message = KMCoreMessage()
4343
messageList.add(message)
4444
}
4545
completion(messageList, nil)

Example/Tests/Mocks/ConversationDetailMock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import KommunicateCore_iOS_SDK
1313
class ConversationDetailMock: ConversationDetail {
1414
var groupId: NSNumber!
1515

16-
override func updatedAssigneeDetails(groupId: NSNumber?, userId _: String?, completion: @escaping (ALContact?, ALChannel?) -> Void) {
16+
override func updatedAssigneeDetails(groupId: NSNumber?, userId _: String?, completion: @escaping (ALContact?, KMCoreChannel?) -> Void) {
1717
self.groupId = groupId
1818
completion(nil, nil)
1919
}

Sources/Kommunicate/Classes/ConversationDetail.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import Foundation
99
import KommunicateCore_iOS_SDK
1010

1111
class ConversationDetail {
12-
let channelService = ALChannelService()
12+
let channelService = KMCoreChannelService()
1313
let userService = ALUserService()
1414
let contactDbService = ALContactDBService()
15-
let channelDbService = ALChannelDBService()
15+
let channelDbService = KMCoreChannelDBService()
1616

17-
func conversationAssignee(groupId: NSNumber?, userId: String?) -> (ALContact?, ALChannel?) {
17+
func conversationAssignee(groupId: NSNumber?, userId: String?) -> (ALContact?, KMCoreChannel?) {
1818
// Check if group conversation.
1919
guard let channelKey = groupId else {
2020
guard let userId = userId else {
@@ -43,7 +43,7 @@ class ConversationDetail {
4343

4444
func updatedAssigneeDetails(groupId: NSNumber?,
4545
userId: String?,
46-
completion: @escaping (ALContact?, ALChannel?) -> Void) {
46+
completion: @escaping (ALContact?, KMCoreChannel?) -> Void) {
4747
var (assignee, alChannel) = conversationAssignee(groupId: groupId, userId: userId)
4848
guard let contact = assignee else {
4949
completion(nil, alChannel)
@@ -105,14 +105,14 @@ class ConversationDetail {
105105
}
106106
}
107107

108-
extension ALChannel {
108+
extension KMCoreChannel {
109109
static let ClosedStatus = 2
110110

111111
var isClosedConversation: Bool {
112112
guard let conversationStatus = metadata[AL_CHANNEL_CONVERSATION_STATUS] as? String else {
113113
return false
114114
}
115115
return type == Int16(SUPPORT_GROUP.rawValue) &&
116-
Int(conversationStatus) ?? 0 == ALChannel.ClosedStatus
116+
Int(conversationStatus) ?? 0 == KMCoreChannel.ClosedStatus
117117
}
118118
}

Sources/Kommunicate/Classes/ConversationVCNavBar.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class ConversationVCNavBar: UIView, Localizable {
150150
fatalError("init(coder:) has not been implemented")
151151
}
152152

153-
func updateView(assignee: ALContact?, channel: ALChannel) {
153+
func updateView(assignee: ALContact?, channel: KMCoreChannel) {
154154
setupProfile(assignee, channel)
155155
}
156156

@@ -276,7 +276,7 @@ class ConversationVCNavBar: UIView, Localizable {
276276
backButton.setImage(image.imageFlippedForRightToLeftLayoutDirection(), for: .normal)
277277
}
278278

279-
private func setupProfile(_ contact: ALContact?, _ channel: ALChannel) {
279+
private func setupProfile(_ contact: ALContact?, _ channel: KMCoreChannel) {
280280
var url: URL?
281281

282282
if let imageUrl = contact?.contactImageUrl {
@@ -303,7 +303,7 @@ class ConversationVCNavBar: UIView, Localizable {
303303
profileName.text = name
304304
}
305305

306-
private func placeHolderImage(channel: ALChannel) -> UIImage? {
306+
private func placeHolderImage(channel: KMCoreChannel) -> UIImage? {
307307
var placeHolder: UIImage?
308308

309309
if channel.type == Int16(SUPPORT_GROUP.rawValue) {

Sources/Kommunicate/Classes/KMBotService.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import KommunicateCore_iOS_SDK
1010

1111
/// `KMBotService` will have all the API releated to bots
1212
public struct KMBotService {
13-
var channelService: ALChannelService
14-
var channelDBService: ALChannelDBService
13+
var channelService: KMCoreChannelService
14+
var channelDBService: KMCoreChannelDBService
1515
static let conversationAssignee = "CONVERSATION_ASSIGNEE"
1616

1717
public init() {
18-
channelService = ALChannelService()
19-
channelDBService = ALChannelDBService()
18+
channelService = KMCoreChannelService()
19+
channelDBService = KMCoreChannelDBService()
2020
}
2121

2222
/// This method is used for fetching `BotDetail`

Sources/Kommunicate/Classes/KMConversationDetail.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public protocol KMGroupUserType {
5050
var role: KMGroupUser.RoleType { get }
5151
}
5252

53-
public class KMGroupUser: ALGroupUser, KMGroupUserType, Encodable {
53+
public class KMGroupUser: KMCoreGroupUser, KMGroupUserType, Encodable {
5454
public enum RoleType: Int {
5555
case agent = 1
5656
case bot = 2

Sources/Kommunicate/Classes/KMConversationListViewController.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public class KMConversationListViewController: ALKBaseViewController, Localizabl
2828
public var conversationListTableViewController: ALKConversationListTableViewController
2929
private let registerUserClientService = ALRegisterUserClientService()
3030

31-
let channelService = ALChannelService()
31+
let channelService = KMCoreChannelService()
3232
var searchController: UISearchController!
3333
var searchBar: KMCustomSearchBar!
3434
lazy var resultVC = ALKSearchResultViewController(configuration: configuration)
3535

36-
public var dbService = ALMessageDBService()
36+
public var dbService = KMCoreMessageDBService()
3737
public var viewModel = ALKConversationListViewModel()
3838

3939
var isSingleThreadedEnabled = KMCoreSettings.getIsSingleThreadedEnabled()
@@ -273,7 +273,7 @@ public class KMConversationListViewController: ALKBaseViewController, Localizabl
273273
}
274274

275275
@objc func addMessages(notification: NSNotification) {
276-
guard let msgArray = notification.object as? [ALMessage] else { return }
276+
guard let msgArray = notification.object as? [KMCoreMessage] else { return }
277277
print("new notification received: ", msgArray.first?.message ?? "")
278278
guard let list = notification.object as? [Any], !list.isEmpty else { return }
279279
viewModel.addMessages(messages: list)
@@ -305,7 +305,7 @@ public class KMConversationListViewController: ALKBaseViewController, Localizabl
305305
contactId = object
306306
}
307307

308-
let message = ALMessage()
308+
let message = KMCoreMessage()
309309
message.contactIds = contactId
310310
message.groupId = groupId
311311
let info = notification.userInfo
@@ -353,12 +353,12 @@ public class KMConversationListViewController: ALKBaseViewController, Localizabl
353353
}
354354

355355
@objc func conversationDeleted(notification: NSNotification) {
356-
guard let conversation = notification.object as? ALMessage else { return }
356+
guard let conversation = notification.object as? KMCoreMessage else { return }
357357
deleteConversation(conversation: conversation)
358358
}
359359

360-
private func deleteConversation(conversation: ALMessage) {
361-
ALMessageService().deleteMessageThread(nil, orChannelKey: conversation.groupId, withCompletion: {
360+
private func deleteConversation(conversation: KMCoreMessage) {
361+
KMCoreMessageService().deleteMessageThread(nil, orChannelKey: conversation.groupId, withCompletion: {
362362
_, error in
363363
guard error == nil else {
364364
print("Failed to delete the conversation: \(error.debugDescription)")
@@ -367,7 +367,7 @@ public class KMConversationListViewController: ALKBaseViewController, Localizabl
367367
})
368368

369369
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
370-
let channelDbService = ALChannelDBService()
370+
let channelDbService = KMCoreChannelDBService()
371371
channelDbService.deleteChannel(conversation.groupId)
372372
self.viewModel.remove(message: conversation)
373373
self.tableView.reloadData()
@@ -466,7 +466,7 @@ public class KMConversationListViewController: ALKBaseViewController, Localizabl
466466
createConversationAndLaunch()
467467
}
468468

469-
func sync(message: ALMessage) {
469+
func sync(message: KMCoreMessage) {
470470
if let viewController = conversationViewController,
471471
ALPushAssist().topViewController is KMConversationViewController,
472472
viewController.viewModel != nil,
@@ -638,7 +638,7 @@ public class KMConversationListViewController: ALKBaseViewController, Localizabl
638638
}
639639
}
640640

641-
extension KMConversationListViewController: ALMessagesDelegate {
641+
extension KMConversationListViewController: KMCoreMessagesDelegate {
642642
public func getMessagesArray(_ messagesArray: NSMutableArray!) {
643643
guard let messages = messagesArray as? [Any], !messages.isEmpty else {
644644
viewModel.delegate?.listUpdated()
@@ -705,7 +705,7 @@ extension KMConversationListViewController: ALMQTTConversationDelegate {
705705
}
706706
}
707707

708-
public func isNewMessageForActiveThread(alMessage: ALMessage, vm: ALKConversationViewModel) -> Bool {
708+
public func isNewMessageForActiveThread(alMessage: KMCoreMessage, vm: ALKConversationViewModel) -> Bool {
709709
let isGroupMessage = alMessage.groupId != nil && alMessage.groupId == vm.channelKey
710710
let isOneToOneMessage = alMessage.groupId == nil && vm.channelKey == nil && alMessage.contactId == vm.contactId
711711
if isGroupMessage || isOneToOneMessage {
@@ -714,14 +714,14 @@ extension KMConversationListViewController: ALMQTTConversationDelegate {
714714
return false
715715
}
716716

717-
func isMessageSentByLoggedInUser(alMessage: ALMessage) -> Bool {
717+
func isMessageSentByLoggedInUser(alMessage: KMCoreMessage) -> Bool {
718718
if alMessage.isSentMessage() {
719719
return true
720720
}
721721
return false
722722
}
723723

724-
open func syncCall(_ alMessage: ALMessage!, andMessageList _: NSMutableArray!) {
724+
open func syncCall(_ alMessage: KMCoreMessage!, andMessageList _: NSMutableArray!) {
725725
print("sync call: ", alMessage.message ?? "empty")
726726
guard let message = alMessage else { return }
727727
let viewController = navigationController?.visibleViewController as? KMConversationViewController
@@ -825,7 +825,7 @@ extension KMConversationListViewController: ALKConversationListTableViewDelegate
825825
viewModel.userBlockNotification(userId: userId, isBlocked: isBlocked)
826826
}
827827

828-
public func muteNotification(conversation: ALMessage, isMuted: Bool) {
828+
public func muteNotification(conversation: KMCoreMessage, isMuted: Bool) {
829829
viewModel.muteNotification(conversation: conversation, isMuted: isMuted)
830830
}
831831

Sources/Kommunicate/Classes/KMConversationService.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class KMConversationService: KMConservationServiceable, Localizable {
5555

5656
let groupMetadata: NSMutableDictionary = {
5757
let metadata = NSMutableDictionary(
58-
dictionary: ALChannelService().metadataToHideActionMessagesAndTurnOffNotifications())
58+
dictionary: KMCoreChannelService().metadataToHideActionMessagesAndTurnOffNotifications())
5959

6060
// Required for features like setting user language in server.
6161
guard let messageMetadata = Kommunicate.defaultConfiguration.messageMetadata,
@@ -67,7 +67,7 @@ public class KMConversationService: KMConservationServiceable, Localizable {
6767
return metadata
6868
}()
6969

70-
let channelService = ALChannelService()
70+
let channelService = KMCoreChannelService()
7171

7272
// MARK: - Initialization
7373

@@ -423,7 +423,7 @@ public class KMConversationService: KMConservationServiceable, Localizable {
423423

424424
func getMetaDataWith(_ conversation: KMConversation) -> NSMutableDictionary {
425425
let metadata = NSMutableDictionary(
426-
dictionary: ALChannelService().metadataToHideActionMessagesAndTurnOffNotifications())
426+
dictionary: KMCoreChannelService().metadataToHideActionMessagesAndTurnOffNotifications())
427427

428428
if !conversation.conversationMetadata.isEmpty {
429429
metadata.addEntries(from: conversation.conversationMetadata)
@@ -542,8 +542,8 @@ public class KMConversationService: KMConservationServiceable, Localizable {
542542
return agentIds.map { createAgentGroupUserFrom(agentId: $0) }
543543
}
544544

545-
internal func isGroupPresent(clientId: String, completion: @escaping (_ isPresent: Bool, _ channel: ALChannel?) -> Void) {
546-
let client = ALChannelService()
545+
internal func isGroupPresent(clientId: String, completion: @escaping (_ isPresent: Bool, _ channel: KMCoreChannel?) -> Void) {
546+
let client = KMCoreChannelService()
547547
client.getChannelInformation(byResponse: nil, orClientChannelKey: clientId, withCompletion: {
548548
_, channel, _ in
549549
guard let channel = channel else {
@@ -588,7 +588,7 @@ public class KMConversationService: KMConservationServiceable, Localizable {
588588
if let agentUsers = agentGroupUsersFor(agentIds: conversation.agentIds) {
589589
members.append(contentsOf: agentUsers)
590590
}
591-
let alChannelService = ALChannelService()
591+
let alChannelService = KMCoreChannelService()
592592
let groupUsers = members.map { $0.toDict() }
593593

594594
alChannelService.createChannel(
@@ -688,7 +688,7 @@ public class KMConversationService: KMConservationServiceable, Localizable {
688688
metadata: NSMutableDictionary,
689689
completion: @escaping ((Response) -> Void)
690690
) {
691-
ALChannelService().updateChannelMetaData(groupId, orClientChannelKey: channelKey, metadata: metadata) { error in
691+
KMCoreChannelService().updateChannelMetaData(groupId, orClientChannelKey: channelKey, metadata: metadata) { error in
692692
guard error == nil else {
693693
completion(Response(success: false, clientChannelKey: nil, error: error))
694694
return
@@ -702,7 +702,7 @@ public class KMConversationService: KMConservationServiceable, Localizable {
702702
metadata: NSMutableDictionary,
703703
completion: @escaping ((Response) -> Void)
704704
) {
705-
ALChannelService().updateChannelMetaData(nil, orClientChannelKey: groupId, metadata: metadata) { error in
705+
KMCoreChannelService().updateChannelMetaData(nil, orClientChannelKey: groupId, metadata: metadata) { error in
706706
guard error == nil else {
707707
completion(Response(success: false, clientChannelKey: nil, error: error))
708708
return
@@ -717,12 +717,12 @@ public class KMConversationService: KMConservationServiceable, Localizable {
717717
completion: @escaping ((Response) -> Void)
718718
) {
719719
let metadata = NSMutableDictionary(
720-
dictionary: ALChannelService().metadataToHideActionMessagesAndTurnOffNotifications())
720+
dictionary: KMCoreChannelService().metadataToHideActionMessagesAndTurnOffNotifications())
721721
if !teamID.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
722722
metadata.setValue(teamID, forKey: ChannelMetadataKeys.teamId)
723723
}
724724

725-
ALChannelService().updateChannelMetaData(NSNumber(pointer: groupID), orClientChannelKey: groupID, metadata: metadata) { error in
725+
KMCoreChannelService().updateChannelMetaData(NSNumber(pointer: groupID), orClientChannelKey: groupID, metadata: metadata) { error in
726726
guard error == nil else {
727727
completion(Response(success: false, clientChannelKey: nil, error: error))
728728
return

Sources/Kommunicate/Classes/KMConversationViewController.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ open class KMConversationViewController: ALKConversationViewController, KMUpdate
2020
private var kmBusinessHoursDataArray: [KMBusinessHoursViewModel]?
2121
let kmBotService = KMBotService()
2222
private var assigneeUserId: String?
23-
var messageArray = [ALMessage]()
23+
var messageArray = [KMCoreMessage]()
2424
var timer = Timer()
2525
var count = 0
26-
var currentMessage = ALMessage()
26+
var currentMessage = KMCoreMessage()
2727
var delayInterval = 0
2828
private var isWaitingQueueFetching: Bool = false
2929

@@ -113,7 +113,7 @@ open class KMConversationViewController: ALKConversationViewController, KMUpdate
113113

114114
private var isClosedConversation: Bool {
115115
guard let channelId = viewModel.channelKey,
116-
!ALChannelService.isChannelDeleted(channelId),
116+
!KMCoreChannelService.isChannelDeleted(channelId),
117117
conversationDetail.isClosedConversation(channelId: channelId.intValue)
118118
else {
119119
return false
@@ -193,7 +193,7 @@ open class KMConversationViewController: ALKConversationViewController, KMUpdate
193193
}
194194

195195
open override func addMessagesToList(_ messageList: [Any]) {
196-
guard var messages = messageList as? [ALMessage] else { return }
196+
guard var messages = messageList as? [KMCoreMessage] else { return }
197197

198198
if KMConversationScreenConfiguration.showTypingIndicatorWhileFetchingResponse {
199199
updateTyingStatus(status: false, userId: "")
@@ -385,7 +385,7 @@ open class KMConversationViewController: ALKConversationViewController, KMUpdate
385385
// This method is used to delay the bot message as well as to show typing indicator
386386
func showDelayAndTypingIndicatorForMessage() {
387387
if count >= messageArray.count {
388-
currentMessage = ALMessage()
388+
currentMessage = KMCoreMessage()
389389
return
390390
}
391391

@@ -709,7 +709,7 @@ open class KMConversationViewController: ALKConversationViewController, KMUpdate
709709
if let alChannel = channel {
710710
setupTopBar(alChannel: alChannel, contact: contact)
711711
} else {
712-
let alChannelService = ALChannelService()
712+
let alChannelService = KMCoreChannelService()
713713
alChannelService.getChannelInformation(viewModel.channelKey, orClientChannelKey: nil) { channel in
714714
guard let alChannel = channel else {
715715
print("Channel is nil in conversationAssignee")
@@ -719,7 +719,7 @@ open class KMConversationViewController: ALKConversationViewController, KMUpdate
719719
}
720720
}
721721
}
722-
private func setupTopBar(alChannel: ALChannel, contact: ALContact?) {
722+
private func setupTopBar(alChannel: KMCoreChannel, contact: ALContact?) {
723723
customNavigationView.updateView(assignee: contact, channel: alChannel)
724724
assigneeUserId = contact?.userId
725725
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: customNavigationView)
@@ -740,7 +740,7 @@ open class KMConversationViewController: ALKConversationViewController, KMUpdate
740740
subscribeChannelToMqtt()
741741
viewModel.prepareController()
742742
self.updatePlaceholder()
743-
ALMessageService.syncMessages()
743+
KMCoreMessageService.syncMessages()
744744
syncAutoSuggestionMessage(message: viewModel?.lastMessage)
745745
}
746746

0 commit comments

Comments
 (0)