             [cljs-http.client :as http]
   ))
 
-;;; helpers
+;;; server operations
 
 (defn- get-sign-url [type]
   (case type
     :sign-in "/user/session"
     :sign-up "/user"))
-
-
-(defn- reply [ch ]
-
-  )
-
-(defn- srv-op []
-
-  )
-
-; (defn mutate-and-put! [op ch state k v]
-;   (op state k v)
-;   (put! ch {k v})
-;   )
-
-;;; server operations
-
-; TODO: fix signatures
 
 (defn- sign [type user pass rsp-ch]
   (go

    (let [{:keys [status body] :as srv-rsp} (<! (http/get (str "/note/" note-id)))]
      (case status
        200 (put! rsp-ch {:ok? true :note body})
        (println "ooops, couldn't get note" note-id)
  ))))

;;; server control

(defn init [ch]
  (go (while true
    (let [data (<! ch)
          {:keys [tag rsp-ch]} data]
      (case tag
        ; TODO: xxx
        :sign-up (println "sign-up" data)
        :sign-in (println "sign-in" data)
        :sign-out (println "sign-out" data)
        :create-note (create-note (:user-id data) (:text data) (:visibility data) rsp-ch)
        :edit-note (println "editing note" data)
        :delete-note (delete-note (:note-id data) rsp-ch)
        :update-note (update-note (:note data) rsp-ch)
        :get-note (get-note (:note-id data) rsp-ch)
        :get-private-notes (get-private-notes (:user-id data) rsp-ch)
        :get-public-notes (println "retrieving public notes" data)
        (do
          (println "oops" data)
          (put! rsp-ch data))


(defn- update-note [{:keys [note-id] :as note} rsp-ch]
  (go
    (let [{:keys [status body]} (<! (http/put (str "/note/" note-id) {:query-params (get-update-note-params note)}))]
      (case status
        200 (put! rsp-ch {:ok? true})
        (put! rsp-ch {:ok? false :error body})
  ))))

(defn- get-note [note-id rsp-ch]
