diff --git a/ANAChat.podspec b/ANAChat.podspec index a8362d8..a824e8f 100644 --- a/ANAChat.podspec +++ b/ANAChat.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'ANAChat' - s.version = '0.2.5' + s.version = '0.2.6' s.summary = 'ANAChat iOS' # This description is used to generate tags and improve search results. diff --git a/ANAChat/Classes/APIHelpers/APIManager.swift b/ANAChat/Classes/APIHelpers/APIManager.swift index b2048c7..cb51a38 100644 --- a/ANAChat/Classes/APIHelpers/APIManager.swift +++ b/ANAChat/Classes/APIHelpers/APIManager.swift @@ -117,8 +117,8 @@ class APIManager: NSObject { task.resume() } - func get(params : Dictionary?, apiPath : String? ,completionHandler:@escaping ([String: Any]) -> ()) { - + func get(params : [String: Any]?, apiPath : String? ,completionHandler:@escaping ([String: Any]) -> ()) { + var finalApiPathString = String() if let apiPath = apiPath{ @@ -174,6 +174,14 @@ class APIManager: NSObject { } } + //History API + + func getHistoryFromServer(params : [String: Any], apiPath : String? , completionHandler:@escaping ([String: Any]) -> ()){ + get(params: params, apiPath: apiPath) { (response) in + completionHandler(response) + } + } + // upload event func uploadMedia(withMedia videoPath: URL,completionHandler:@escaping ([String: Any]) -> ()){ let url = NSURL(string: String(format:"%@files/", APIManager.sharedInstance.getAPIBaseUrl())) diff --git a/ANAChat/Classes/DBHelpers/CoreDataContentManager.swift b/ANAChat/Classes/DBHelpers/CoreDataContentManager.swift index cf25902..6f9c531 100644 --- a/ANAChat/Classes/DBHelpers/CoreDataContentManager.swift +++ b/ANAChat/Classes/DBHelpers/CoreDataContentManager.swift @@ -118,6 +118,12 @@ public class CoreDataContentManager: NSObject { } } + class func fetchMessagesCount() -> Int{ + let fetchRequest = NSFetchRequest(entityName: "Message") + let count = try! CoreDataContentManager.backgroundObjectContext().count(for: fetchRequest) + return count + } + class func fetchRequest(withEntityName entity: String , predicate : NSPredicate , sortDescriptor : NSSortDescriptor) -> [Any]{ var request: NSFetchRequest = NSFetchRequest() request = NSFetchRequest(entityName: entity) @@ -1540,6 +1546,9 @@ public class CoreDataContentManager: NSObject { if let timeStamp = inputModel.messageTimeStamp{ messageObject.timestamp = timeStamp } + if let dateStamp = inputModel.messageDateStamp{ + messageObject.dateStamp = dateStamp + } messageObject.syncedWithServer = NSNumber(value: true) as! Bool CoreDataContentManager.saveBackgroundContextWith(successBlock: { (success) in successCompletion(true) diff --git a/ANAChat/Classes/MockJson/allChatsMock.json b/ANAChat/Classes/MockJson/allChatsMock.json index bcf3ab0..7d1524a 100644 --- a/ANAChat/Classes/MockJson/allChatsMock.json +++ b/ANAChat/Classes/MockJson/allChatsMock.json @@ -1,5 +1,5 @@ { - "chats":[ + "content":[ {"meta":{"id":"638d440e-b3f9-47ea-9d8a-3c3a5dcbb37c", "sender": { "id": "business", "medium": 1 diff --git a/ANAChat/Classes/UIComponents/Cells/ChatCarouselCollectionCell.swift b/ANAChat/Classes/UIComponents/Cells/ChatCarouselCollectionCell.swift index 722138c..3e5360d 100644 --- a/ANAChat/Classes/UIComponents/Cells/ChatCarouselCollectionCell.swift +++ b/ANAChat/Classes/UIComponents/Cells/ChatCarouselCollectionCell.swift @@ -1,5 +1,9 @@ // // ChatCarouselCollectionCell.swift +// NowFloats-iOSSDK +// +// Created by Rakesh Tatekonda on 29/09/17. +// Copyright © 2017 NowFloats. All rights reserved. // import UIKit @@ -20,6 +24,7 @@ class ChatCarouselCollectionCell: UICollectionViewCell { @IBOutlet weak var cellContentView: UIView! @IBOutlet weak var buttonsTableViewHeightConstraint: NSLayoutConstraint! + @IBOutlet weak var imageViewHeightConstraint: NSLayoutConstraint! var item: CarouselItem? var delegate: ChatCarouselCollectionCellDelegate? var options: [Any]? @@ -45,7 +50,7 @@ class ChatCarouselCollectionCell: UICollectionViewCell { super.prepareForReuse() self.imageView.image = nil } - + func configureCell(_ item:CarouselItem, showOptions : Bool){ self.playButton.isHidden = true self.showOptions = showOptions @@ -54,6 +59,11 @@ class ChatCarouselCollectionCell: UICollectionViewCell { self.options = item.options?.sortedArray(using: [sortDescriptor]) self.titleLabel.text = item.title self.descriptionLabel.text = item.desc + if item.title?.characters.count == 0, item.desc?.characters.count == 0{ + self.imageViewHeightConstraint.constant = 210 + }else{ + self.imageViewHeightConstraint.constant = 130 + } if item.mediaType == 0{ self.playButton.isHidden = true if let url = item.mediaUrl{ diff --git a/ANAChat/Classes/UIComponents/Cells/ChatCarouselCollectionCell.xib b/ANAChat/Classes/UIComponents/Cells/ChatCarouselCollectionCell.xib index 4e2ab62..a3cc662 100644 --- a/ANAChat/Classes/UIComponents/Cells/ChatCarouselCollectionCell.xib +++ b/ANAChat/Classes/UIComponents/Cells/ChatCarouselCollectionCell.xib @@ -108,6 +108,7 @@ + diff --git a/ANAChat/Classes/UIComponents/Cells/ChatReceiveCarouselCell.swift b/ANAChat/Classes/UIComponents/Cells/ChatReceiveCarouselCell.swift index 53de77b..d32e47e 100644 --- a/ANAChat/Classes/UIComponents/Cells/ChatReceiveCarouselCell.swift +++ b/ANAChat/Classes/UIComponents/Cells/ChatReceiveCarouselCell.swift @@ -12,6 +12,8 @@ class ChatReceiveCarouselCell: UITableViewCell ,ChatCarouselCollectionCellDelega var delegate: InputCellProtocolDelegate? var showOptions : Bool? + var previousMessageTimeStamp = NSDate() + override func awakeFromNib() { super.awakeFromNib() collectionview.delegate = self @@ -19,6 +21,10 @@ class ChatReceiveCarouselCell: UITableViewCell ,ChatCarouselCollectionCellDelega collectionview.register(UINib.init(nibName: "ChatCarouselCollectionCell", bundle: CommonUtility.getFrameworkBundle()), forCellWithReuseIdentifier: "ChatCarouselCollectionCell") } + override func prepareForReuse() { + super.prepareForReuse() + } + override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) @@ -34,11 +40,10 @@ class ChatReceiveCarouselCell: UITableViewCell ,ChatCarouselCollectionCellDelega self.sortedItems = carousel.items?.sortedArray(using: [sortDescriptor]) self.collectionview.reloadData() self.collectionview.scrollRectToVisible(CGRect.zero, animated: false) - /* - if (self.sortedItems?.count)! > 0{ - self.collectionview.scrollToItem(at: IndexPath(item: 0, section: 0), at: .left, animated: false) - } - */ + } + if (self.sortedItems?.count)! > 0 , self.previousMessageTimeStamp != self.messageObject.timestamp{ + self.previousMessageTimeStamp = self.messageObject.timestamp! + self.collectionview.scrollToItem(at: IndexPath(item: 0, section: 0), at: .left, animated: false) } } diff --git a/ANAChat/Classes/UIComponents/ViewControllers/BaseViewController.swift b/ANAChat/Classes/UIComponents/ViewControllers/BaseViewController.swift index 6e5fb16..789445d 100644 --- a/ANAChat/Classes/UIComponents/ViewControllers/BaseViewController.swift +++ b/ANAChat/Classes/UIComponents/ViewControllers/BaseViewController.swift @@ -6,7 +6,7 @@ import UIKit @objc public class BaseViewController: UIViewController { - private var reachability:Reachability! + public var reachability:Reachability! override public func viewDidLoad() { super.viewDidLoad() diff --git a/ANAChat/Classes/UIComponents/ViewControllers/ChatViewController.swift b/ANAChat/Classes/UIComponents/ViewControllers/ChatViewController.swift index e4642bf..f19c210 100644 --- a/ANAChat/Classes/UIComponents/ViewControllers/ChatViewController.swift +++ b/ANAChat/Classes/UIComponents/ViewControllers/ChatViewController.swift @@ -38,6 +38,11 @@ import MobileCoreServices var isTableViewScrolling = Bool() var visibleSectionIndex = Int() + var isSyncInProgress = Bool() + var isLastPage = Bool() + + var refreshControl: UIRefreshControl! + @IBOutlet weak var headerLogo: UIImageView! @IBOutlet weak var headerDescriptionLabel: UILabel! @IBOutlet weak var headerTitleLabel: UILabel! @@ -59,6 +64,13 @@ import MobileCoreServices let sortDescriptor = NSSortDescriptor(key: Constants.kTimeStampKey, ascending: true) messagesFetchRequest.sortDescriptors = [sortDescriptor] + if CoreDataContentManager.fetchMessagesCount() > ConfigurationConstants.pageLimit{ + messagesFetchRequest.fetchOffset = CoreDataContentManager.fetchMessagesCount() - ConfigurationConstants.pageLimit + }else{ + messagesFetchRequest.fetchOffset = 0 + } + messagesFetchRequest.fetchBatchSize = ConfigurationConstants.pageLimit*2 + let frc = NSFetchedResultsController(fetchRequest: messagesFetchRequest, managedObjectContext: CoreDataContentManager.managedObjectContext(), sectionNameKeyPath: "dateStamp", cacheName: nil) frc.delegate = self frc.fetchRequest.shouldRefreshRefetchedObjects = true @@ -85,6 +97,7 @@ import MobileCoreServices self.headerView.backgroundColor = PreferencesManager.sharedInstance.getBaseThemeColor() if let baseUrl = self.baseAPIUrl , self.baseAPIUrl.characters.count > 0{ APIManager.sharedInstance.configureAPIBaseUrl(withString: baseUrl) + self.loadHistory(isOnLoad: true) }else{ self.didTappedBackButton() } @@ -102,7 +115,6 @@ import MobileCoreServices override public func viewDidLoad() { super.viewDidLoad() self.configureUI() - self.loadHistory() // Do any additional setup after loading the view, typically from a nib. } @@ -111,6 +123,7 @@ import MobileCoreServices } override public func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) { + /* if motion == .motionShake{ let actionSheetController: UIAlertController = UIAlertController(title: "Alert", message: "Do you want to start the chat again.?", preferredStyle: .alert) let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in @@ -134,8 +147,143 @@ import MobileCoreServices actionSheetController.addAction(clearAction) self.present(actionSheetController, animated: true, completion: nil) } + */ } + // MARK: - + // MARK: History Helper Methods + + func loadHistory(isOnLoad onLoad : Bool) { + + if self.isSyncInProgress || self.isLastPage{ + return + } + + self.isSyncInProgress = true + + if reachability.isReachable{ + var interval = Int() + + CoreDataContentManager.deleteAllWaitingPlaceholderImages { (success) in + + } + + if onLoad == false{ + if let lastObject = self.messagesFetchController?.fetchedObjects?.first{ + interval = CommonUtility.getTimeInterval(fromDate: lastObject.timestamp!) + } + } + + var requestDictionary = [String: Any]() + requestDictionary[Constants.kUserIdKey] = PreferencesManager.getUserId() + requestDictionary[Constants.kBusinessIdKey] = PreferencesManager.sharedInstance.getBusinessId() + requestDictionary[Constants.kSizeKey] = String(ConfigurationConstants.pageLimit) + if onLoad{ + requestDictionary[Constants.kPageKey] = String(0) + }else{ + if interval > 0{ + requestDictionary[Constants.kLastMessageTimeStampKey] = String(interval) + } + } + + dataHelper.syncHistoryFromServer(params: requestDictionary, apiPath: nil) { (response) in + if let chatsArray = response["content"] as? NSArray{ + if chatsArray.count == 0 && (self.messagesFetchController?.fetchedObjects?.count)! == 0{ + let responseDict = CommonUtility.loadJson(forFilename: "allChatsMock") + FCMMessagesManager.syncHistory(withResponseObject: responseDict!) { (success) in + self.isSyncInProgress = false + DispatchQueue.main.async { + if (self.messagesFetchController?.fetchedObjects?.count)! > 0{ + self.tableView.reloadData() + if onLoad{ + if let lastObject = self.messagesFetchController?.fetchedObjects?.last{ + self.loadInputView(lastObject) + } + } + } + } + } + }else{ + DispatchQueue.global().async { + FCMMessagesManager.syncHistory(withResponseObject: response as NSDictionary) { (success) in + + DispatchQueue.main.async { + if onLoad == false{ + if let numberOfElements = response[Constants.kNumberOfElementsKey] as? NSInteger , numberOfElements > 0{ + let dbOffset = (self.messagesFetchController?.fetchedObjects?.count)! + numberOfElements + if CoreDataContentManager.fetchMessagesCount() > dbOffset{ + self.messagesFetchController?.fetchRequest.fetchOffset = CoreDataContentManager.fetchMessagesCount() - dbOffset + }else{ + self.messagesFetchController?.fetchRequest.fetchOffset = 0 + } + do { + NSFetchedResultsController.deleteCache(withName: nil) + let sortDescriptor = NSSortDescriptor(key: Constants.kTimeStampKey, ascending: true) + self.messagesFetchController?.fetchRequest.sortDescriptors = [sortDescriptor] + try self.messagesFetchController?.performFetch() + } + catch { + print("Unable to fetch cart Objects") + } + } + } + self.isSyncInProgress = false + + if let isLastPage = response[Constants.kIsLastKey] as? Bool{ + if isLastPage == true{ + self.isLastPage = true + } + } + DispatchQueue.main.async { + if (self.messagesFetchController?.fetchedObjects?.count)! > 0{ + if onLoad{ + if let lastObject = self.messagesFetchController?.fetchedObjects?.last{ + self.loadInputView(lastObject) + } + }else{ + self.updateTableViewContentAfterLoadmoreMessages() + } + } + } + } + } + } + } + } + } + }else{ + if (self.messagesFetchController?.fetchedObjects?.count)! > 0{ + self.isSyncInProgress = false + if onLoad{ + if let lastObject = self.messagesFetchController?.fetchedObjects?.last{ + self.loadInputView(lastObject) + } + }else{ + let dbOffset = (self.messagesFetchController?.fetchedObjects?.count)! + ConfigurationConstants.pageLimit + if CoreDataContentManager.fetchMessagesCount() > dbOffset{ + self.messagesFetchController?.fetchRequest.fetchOffset = CoreDataContentManager.fetchMessagesCount() - dbOffset + }else{ + self.messagesFetchController?.fetchRequest.fetchOffset = 0 + } + + do { + NSFetchedResultsController.deleteCache(withName: nil) + let sortDescriptor = NSSortDescriptor(key: Constants.kTimeStampKey, ascending: true) + self.messagesFetchController?.fetchRequest.sortDescriptors = [sortDescriptor] + try self.messagesFetchController?.performFetch() + + self.updateTableViewContentAfterLoadmoreMessages() + } + catch { + print("Unable to fetch cart Objects") + } + + self.updateTableViewContentAfterLoadmoreMessages() + } + } + } + } + override public func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. @@ -187,6 +335,16 @@ import MobileCoreServices self.tapGestureRecognizers() self.scrollToTableBottom() ImageCache.sharedInstance.initilizeImageDirectory() + refreshControl = UIRefreshControl() + refreshControl.addTarget(self, action: #selector(refresh), for: .valueChanged) + refreshControl.tintColor = PreferencesManager.sharedInstance.getBaseThemeColor() + if #available(iOS 10.0, *) { + self.tableView.refreshControl = refreshControl + } else { + self.tableView.addSubview(refreshControl) + } + self.automaticallyAdjustsScrollViewInsets = false + } func registerNibs(){ @@ -203,32 +361,6 @@ import MobileCoreServices self.delegate?.registerCells?(self.tableView) } - func loadHistory() { - CoreDataContentManager.deleteAllWaitingPlaceholderImages { (success) in - - } - if (self.messagesFetchController?.fetchedObjects?.count)! == 0{ - dataHelper.syncHistoryFromServer(successBlock: { (responseDict) in - if (self.messagesFetchController?.fetchedObjects?.count)! > 0{ - print(self.messagesFetchController?.fetchedObjects?.last ?? Message()) - DispatchQueue.main.async { - self.tableView.reloadData() - if let lastObject = self.messagesFetchController?.fetchedObjects?.last{ - self.loadInputView(lastObject) - } - } - } - }) - }else{ - DispatchQueue.main.async { - self.tableView.reloadData() - if let lastObject = self.messagesFetchController?.fetchedObjects?.last{ - self.loadInputView(lastObject) - } - } - } - } - func tapGestureRecognizers(){ //Added tap gesture on tableview to recognize touch on tableview let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tableViewTapped(_:))) @@ -236,6 +368,12 @@ import MobileCoreServices self.tableView.addGestureRecognizer(tapGesture) } + func refresh(_ sender: Any) { + refreshControl.endRefreshing() + self.loadHistory(isOnLoad: false) + } + + // MARK: - // MARK: Delegate Methods @@ -529,6 +667,11 @@ import MobileCoreServices // MARK: InputTextFieldViewDelegate Methods func didTappedOnInputCell(_ inputDict:[String: Any], messageObject: Message?){ + if !reachability.isReachable{ + self.showAlert("Unable to connect to the network , Please check your internet settings and try again") + return + } + NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil) NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(self.keyBoardWillShow(withNotification:)), name: .UIKeyboardWillShow, object: nil) @@ -555,6 +698,11 @@ import MobileCoreServices } func syncInputMessageToServer(_ inputDict:[String: Any], messageObject: Message?) { + if !reachability.isReachable{ + self.showAlert("Unable to connect to the network , Please check your internet settings and try again") + return + } + var requestDict = [String: Any]() if let messageObject = messageObject{ requestDict = RequestHelper.getRequestDictionary(messageObject, inputDict: inputDict) @@ -576,8 +724,6 @@ import MobileCoreServices } } - print(requestDict) - print(inputDict) if messageObject is Carousel{ dataHelper.updateCarouselDBMessage(params: requestDict, successBlock: { (messageObject) in self.reloadLastPreviousCell() @@ -815,7 +961,7 @@ import MobileCoreServices let dic = notification.userInfo let duration = dic?["UIKeyboardAnimationDurationUserInfoKey"] as? Double self.inputTextViewBottomConstraint.constant = 0 - scrollToTableBottom() +// scrollToTableBottom() UIView.animate(withDuration: duration!, delay:0.0, options: UIViewAnimationOptions.allowAnimatedContent, animations: { self.view.layoutIfNeeded() }) { (_ finished: Bool) in @@ -844,10 +990,16 @@ import MobileCoreServices if (self.messagesFetchController?.fetchedObjects?.count)! > 0{ let indexPath = IndexPath(row: (self.messagesFetchController?.sections?.last?.numberOfObjects)! - 1, section: (self.messagesFetchController?.sections?.count)! - 1) UIView.animate(withDuration: 0.25, delay:0.0, options: UIViewAnimationOptions.allowAnimatedContent, animations: { - self.tableView.scrollToRow(at: indexPath, at: .none, animated: false) + self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: false) }) { (_ finished: Bool) in if(finished){ + if self.inputTextView != nil,self.textContainerViewHeightConstraint.constant == CGFloat(CellHeights.textInputViewHeight){ + if self.reachability.isReachable{ + self.inputTextView.textView.becomeFirstResponder() + } + } } + } } } @@ -1028,4 +1180,16 @@ import MobileCoreServices } imgVi?.frame = contentsFrame! } + + // MARK: - + // MARK: DBHelper Methods + + func updateTableViewContentAfterLoadmoreMessages(){ + let oldContentOffsetY = self.tableView.contentSize.height - self.tableView.contentOffset.y + self.tableView.reloadData() + let newOffset = CGPoint(x : self.tableView.contentOffset.x, y : self.tableView.contentSize.height - oldContentOffsetY) + self.tableView.contentOffset = newOffset + } + + } diff --git a/ANAChat/Classes/UIComponents/ViewControllers/ChatViewControllerHelper.swift b/ANAChat/Classes/UIComponents/ViewControllers/ChatViewControllerHelper.swift index 643e576..3d4764d 100644 --- a/ANAChat/Classes/UIComponents/ViewControllers/ChatViewControllerHelper.swift +++ b/ANAChat/Classes/UIComponents/ViewControllers/ChatViewControllerHelper.swift @@ -478,10 +478,18 @@ extension ChatViewController:NSFetchedResultsControllerDelegate { // MARK: Fetched Results Controller Delegate Methods public func controllerWillChangeContent(_ controller: NSFetchedResultsController) { self.tableView.beginUpdates() + if (isSyncInProgress) { + UIView.setAnimationsEnabled(false) + } } public func controllerDidChangeContent(_ controller: NSFetchedResultsController) { self.tableView.endUpdates() + + if self.isSyncInProgress == true{ + self.updateTableViewContentAfterLoadmoreMessages() + UIView.setAnimationsEnabled(true) + } } public func controller(_ controller: NSFetchedResultsController, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) { diff --git a/ANAChat/Classes/Utilities/CommonUtility.swift b/ANAChat/Classes/Utilities/CommonUtility.swift index ee923c1..e76d52f 100644 --- a/ANAChat/Classes/Utilities/CommonUtility.swift +++ b/ANAChat/Classes/Utilities/CommonUtility.swift @@ -46,9 +46,13 @@ import UIKit public class func getDate(fromString dateString : NSString) -> NSDate{ let date = NSDate(timeIntervalSince1970:TimeInterval(dateString.doubleValue/1000)) - return date; + return date } + public class func getTimeInterval(fromDate date : NSDate) -> Int{ + return Int(date.timeIntervalSince1970*1000) + } + public class func getTimeString(_ messageTimestamp : NSDate) -> String{ let dateFormatter = DateFormatter() dateFormatter.dateFormat = "hh:mm a" diff --git a/ANAChat/Classes/Utilities/Constants.swift b/ANAChat/Classes/Utilities/Constants.swift index 11a3055..a1ce306 100644 --- a/ANAChat/Classes/Utilities/Constants.swift +++ b/ANAChat/Classes/Utilities/Constants.swift @@ -59,6 +59,14 @@ struct Constants { static let kTimeKey = "time" static let kMultipleKey = "multiple" static let kStaticBusinessId = "ChatBot" + static let kUserIdKey = "userId" + static let kBusinessIdKey = "businessId" + static let kSizeKey = "size" + static let kPageKey = "page" + static let kNumberKey = "number" + static let kIsLastKey = "isLast" + static let kLastMessageTimeStampKey = "lastMessageTimeStamp" + static let kNumberOfElementsKey = "numberOfElements" } struct AlertTexts { @@ -89,6 +97,10 @@ struct DataBaseConstans { } +struct ConfigurationConstants { + static let pageLimit = 20 +} + enum GCMPushType:Int{ case GCMPushTypeMessage = 1 } diff --git a/ANAChat/Classes/Utilities/DataHelper.swift b/ANAChat/Classes/Utilities/DataHelper.swift index 0fdfb2e..29a821e 100644 --- a/ANAChat/Classes/Utilities/DataHelper.swift +++ b/ANAChat/Classes/Utilities/DataHelper.swift @@ -6,10 +6,9 @@ import UIKit @objc class DataHelper: NSObject { - public func syncHistoryFromServer(successBlock successCompletion: @escaping (_ response: NSDictionary) -> Void){ - let responseDict = CommonUtility.loadJson(forFilename: "allChatsMock") - FCMMessagesManager.syncHistory(withResponseObject: responseDict!) { (success) in - successCompletion(responseDict!) + public func syncHistoryFromServer(params : [String: Any], apiPath : String? ,successBlock successCompletion: @escaping (_ response: NSDictionary) -> Void){ + APIManager.sharedInstance.getHistoryFromServer(params: params, apiPath: "chatdata/messages") { (response) in + successCompletion(response as NSDictionary) } } diff --git a/ANAChat/Classes/Utilities/FCMMessagesManager.swift b/ANAChat/Classes/Utilities/FCMMessagesManager.swift index 04a73b7..1937a57 100644 --- a/ANAChat/Classes/Utilities/FCMMessagesManager.swift +++ b/ANAChat/Classes/Utilities/FCMMessagesManager.swift @@ -127,7 +127,7 @@ public class FCMMessagesManager: NSObject { */ public class func syncHistory(withResponseObject responseInfo:NSDictionary, successBlock successCompletion: @escaping (_ success: Bool) -> Void){ - if let chatsArray = responseInfo["chats"] as? NSArray{ + if let chatsArray = responseInfo["content"] as? NSArray{ if chatsArray.count == 0 { successCompletion(true) } diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index 39ff859..a871dfe 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -44,8 +44,6 @@ 30BE4ABA1FA7593100F64363 /* .gitkeep */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitkeep; sourceTree = ""; }; 30BE4ABD1FA7594500F64363 /* APIManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIManager.swift; sourceTree = ""; }; 30BE4ABE1FA7594500F64363 /* SDKReachability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDKReachability.swift; sourceTree = ""; }; - 30BE4AC21FA7594500F64363 /* ChatCarouselCollectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatCarouselCollectionCell.swift; sourceTree = ""; }; - 30BE4AC31FA7594500F64363 /* ChatCarouselCollectionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ChatCarouselCollectionCell.xib; sourceTree = ""; }; 30BE4AC41FA7594500F64363 /* ChatListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListTableViewCell.swift; sourceTree = ""; }; 30BE4AC51FA7594500F64363 /* ChatListTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ChatListTableViewCell.xib; sourceTree = ""; }; 30BE4AC61FA7594500F64363 /* ChatOptionsTableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatOptionsTableCell.swift; sourceTree = ""; }; @@ -143,6 +141,8 @@ 30BE4B2C1FA7594500F64363 /* Simple+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Simple+CoreDataProperties.swift"; sourceTree = ""; }; 30BE4B2D1FA7594500F64363 /* TimeRange+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeRange+CoreDataClass.swift"; sourceTree = ""; }; 30BE4B2E1FA7594500F64363 /* TimeRange+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeRange+CoreDataProperties.swift"; sourceTree = ""; }; + 30CFC5091FB5D24200DD95A9 /* ChatCarouselCollectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatCarouselCollectionCell.swift; sourceTree = ""; }; + 30CFC50A1FB5D24200DD95A9 /* ChatCarouselCollectionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ChatCarouselCollectionCell.xib; sourceTree = ""; }; 30F60ED81FACB0120010C26F /* InputTextFieldView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = InputTextFieldView.xib; sourceTree = ""; }; 3AA8E5965D48453B1D3AD48D2FC928BD /* ANAChat-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "ANAChat-umbrella.h"; sourceTree = ""; }; 3B0AFD2491288033548D6D938C0DCED9 /* Pods-ANAChat_Tests-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-ANAChat_Tests-acknowledgements.markdown"; sourceTree = ""; }; @@ -281,8 +281,8 @@ 30BE4AC11FA7594500F64363 /* Cells */ = { isa = PBXGroup; children = ( - 30BE4AC21FA7594500F64363 /* ChatCarouselCollectionCell.swift */, - 30BE4AC31FA7594500F64363 /* ChatCarouselCollectionCell.xib */, + 30CFC5091FB5D24200DD95A9 /* ChatCarouselCollectionCell.swift */, + 30CFC50A1FB5D24200DD95A9 /* ChatCarouselCollectionCell.xib */, 30BE4AC41FA7594500F64363 /* ChatListTableViewCell.swift */, 30BE4AC51FA7594500F64363 /* ChatListTableViewCell.xib */, 30BE4AC61FA7594500F64363 /* ChatOptionsTableCell.swift */,