 						[ring.middleware.json :as middleware]
             [clojure.pprint :refer [pprint]]
 						[cheshire.core :refer [generate-string parse-string]]
-            [somnium.congomongo :as mongo]))
+            [somnium.congomongo :refer :all]))
 
 (def listeners (atom {}))
 (def clients (atom {}))
+
+(def last-status (atom nil))
+(defn save-last-status!
+  [status]
+  (reset! last-status status))
+
 
 (defn tell!
   [who what]

                            (when on-receive-fn
                              (on-receive-fn (parse-string data))))))))

(def mongo-conn (mongo/make-connection "i-approve-test"))

(defroutes my-routes
  (GET "/i-approve" []
    (web-socket-handler clients (fn [data]
                                  (tell! listeners data)
                                  (println :action data)
                                  (mongo/with-mongo mongo-conn
                                    (mongo/insert! :actions data)))))
  (GET "/who-approves" []
    (web-socket-handler listeners (partial tell! clients)))
  (GET "/" []
  	(clojure.java.io/resource "public/index.html"))
  (route/resources "/")

           (generate-string what)
           false)))

(defn web-socket-handler [client-container on-connect-fn on-receive-fn]
  (fn [request]
    (with-channel request channel
      (println "connected:" channel)
      (swap! client-container assoc channel true)
      (when on-connect-fn
        (on-connect-fn))
      (on-close   channel (fn [status]
                            (swap! client-container dissoc channel)
                            (println "disconnected:" channel "status:" status)))
