             return
         }
 
+        let message = text!
+
+        if let editingMessage = editingMessage {
+            sendEditedMessage(editingMessage, message: message)
+        } else {
+            sendNewMessage(message)
+        }
+        
+        textField.text = ""
+    }
+
+    func sendNewMessage(message: String) {
         let app = UIApplication.sharedApplication().delegate as! AppDelegate
-
-        let message = text!
 
         let properties = [
             "type": "message",

        }
    }
    var chatroomDoc: CBLDocument?

    func configureView() {
        if let roomId = self.chatroomId,


                cell.textLabel!.text = values[1]
                cell.detailTextLabel!.text = values[0]

                cell.accessoryType = row.documentID == editingMessage?.documentID ? .Checkmark : .None
        }

        return cell
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if let row = liveQuery?.rows?.rowAtIndex(UInt(indexPath.row)) {
            editingMessage = row.document
            tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
        }
    }

}
