Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBOutlet weak var chatsTableView: UITableView!
- var recentChats: [NSDictionary] = []
- var filteredChats: [NSDictionary] = []
- var recentListener: ListenerRegistration!
- override func viewDidLoad() {
- super.viewDidLoad()
- navigationController?.navigationBar.prefersLargeTitles = true
- loadRecentChats()
- }
- //MARK IBActions
- @IBAction func newChatBtnPressed(_ sender: Any) {
- let userVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "userTableView") as! YsersTableVC
- self.navigationController?.pushViewController(userVC, animated: true)
- }
- //TableViewDataSource
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- print ("here is the (recentChats.count)")
- return recentChats.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! RecentChatTableViewCell
- let recent = recentChats[indexPath.row]
- cell.generateCell(recentChat: recent, indexPath: indexPath)
- return cell
- }
- //MARK: LoadRecentChats
- func loadRecentChats() {
- recentListener = reference(.Recent).whereField(kUSERID, isEqualTo: FUser.currentId()).addSnapshotListener({ (snapshot, error) in
- guard let snapshot = snapshot else { return }
- print ("snapshot count is (snapshot.count)")
- print ("(snapshot)")
- self.recentChats = []
- if !snapshot.isEmpty {
- let sorted = ((dictionaryFromSnapshots(snapshots: snapshot.documents)) as NSArray).sortedArray(using: [NSSortDescriptor(key: kDATE, ascending: false)]) as! [NSDictionary]
- for recent in sorted {
- if recent[kLASTMESSAGE] as! String != "" && recent[kCHATROOMID] != nil && recent[kRECENTID] != nil {
- self.recentChats.append(recent)
- }
- }
- self.chatsTableView.reloadData()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement