 
     @IBOutlet private var tableView: UITableView!
 
-    private var model = [Chat]()
+    private var searchModel: [Chat]?
+    private var fullModel = [Chat]()
+    private var activeModel: [Chat] {
+        get {
+            return searchModel ?? fullModel
+        }
+    }
     private var cellIdentifier = "ChatCell"
     private var plusButtonHeight: CGFloat = 72
 
     override func viewDidLoad() {
         ChatClient.getList(success: { chats in
-            self.model = chats
+            self.fullModel = chats
             self.tableView.reloadData()
         })
 

    }

    func addChat(chat: Chat) {
        model.append(chat)
        let path = NSIndexPath(forRow: self.model.count-1, inSection: 0)
        self.tableView.insertRowsAtIndexPaths([path], withRowAnimation: .None)
    }

    func searchBarSearchButtonClicked(searchBar: UISearchBar) {
        ChatClient.getList(search: searchBar.text, success: { chats in
            self.model = chats
            self.tableView.reloadData()
        })
        searchBar.resignFirstResponder()
    }


    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return activeModel.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ChatCell

        cell.inject(chat: activeModel[indexPath.row])

        return cell
    }
