   #_(put! target text)
   false)
 
-(defn check-for-enter [e owner {:keys [text sender-ch]}]
+(defn send-message-click [sender-ch text owner app]
+  (do
+    (post-message sender-ch text)
+    (clear-text owner)))
+
+(defn login-click [sender-ch text owner app]
+  (post-message sender-ch text)
+  (om/update! app :user-name text)
+  (clear-text owner))
+
+(defn check-for-enter [e owner {:keys [text sender-ch]} app click-fn]
   (when (or (= 13 (.-keyCode e))
             (= 13 (.-which e)))
-    (do
-      (post-message sender-ch text)
-      clear-text owner)))
+    (click-fn sender-ch text owner app)))
 
 (defn text-entry [e owner {:keys [text]}]
   (om/set-state! owner :text (.. e -target -value)))

  (reify
    om/IInitState
    (init-state [_]
      (let [listener-ch (chan)
            sender-ch (chan)]
        (make-socket listener-ch sender-ch)
        {:listener-ch listener-ch
         :sender-ch sender-ch
         :text ""}))
    om/IWillMount
    (will-mount [_]
      (let [listener-ch (om/get-state owner :listener-ch)
            sender-ch (om/get-state owner :sender-ch)]
        (go (loop []
              (let [msg (<! listener-ch)]
                ;; do something cool with the message
                (recur))))))
    om/IRenderState
    (render-state [this {:keys [sender-ch text] :as state}]
      (dom/div #js {:className "container"}
               (dom/h3 nil "Enter Chat stuff")
               (dom/div #js {:className "form-horizontal"}
                         (dom/div nil
                                  (dom/div nil
                                           (om/build users-view (:users app)))
                                  (dom/div nil
                                           (om/build chat-view (:original app)))
                                  (dom/div nil
                                           (om/build chat-view (:translated app))))
                         (dom/div #js {:className "form-group"}
                                  (dom/input #js {:className "form-control" :type "text"
                                                  :value text
                                                  :onKeyPress (fn [e] (check-for-enter e owner state))
                                                  :onChange #(text-entry % owner state)}))
                         (dom/div #js {:className "col-xs-offset-2 col-xs-10"}
                                  (dom/button #js {:type "button" :className "button"
                                                   :onClick (fn [e] (do
                                                                     (post-message sender-ch text)
                                                                     (clear-text owner))
                                                              )}
                                              "click me")))))))

(om/root
 master-view
 app-state
 {:target (. js/document (getElementById "app"))})


(def app-state (atom {:original [sample-source]
                      :translated [sample-translation]
                      :users sample-users
                      :user-name nil
                      :listener-ch (chan)
                      :sender-ch (chan)}))

(defn handle-incoming [listener-ch server-ch]
  (go
