 extension ContactPicker {
   fileprivate func contact(for indexPath: IndexPath) -> String? {
     guard
-      let key = dataSource.sortedFriends.keys.sorted()[safe: indexPath.section],
-      let contacts = dataSource.sortedFriends[key]
+      let key = dataSource.sortedContacts.keys.sorted()[safe: indexPath.section],
+      let contacts = dataSource.sortedContacts[key]
     else {
         return nil
     }
     return contacts[safe: indexPath.row]!
+  }
+
+  fileprivate func selectContact(fbid: String) {
+    dataSource.selectedContacts.append(fbid)
+  }
+
+  fileprivate func unselectContact(fbid: String) {
+    dataSource.selectedContacts =
+        dataSource.selectedContacts.filter { (contact) in
+          return !(contact == fbid)
+        }
+  }
+
+  fileprivate func isSelected(fbid: String) -> Bool {
+    return dataSource.selectedContacts.contains(fbid)
   }
 }
 

class FriendsDataSource: TableDataSource {
  var cells = [CellInfo]()

  var selectedFriends = [String]()
  var sortedFriends = [String: [String]]()

  func reload(completion: @escaping () -> Void) {
    if cells.isEmpty {

  func tableView(_ tableView: UITableView,
                 didDeselectRowAt indexPath: IndexPath) {
    if let cell = tableView.cellForRow(at: indexPath) {
      guard let contact = self.contact(for: indexPath) else { return }
      unselectContact(fbid: contact)
      cell.accessoryType = .none
    }
  }
