          db->message)))
 
 (defn group-exists?
-  [group-name]
-  (some? (d/pull (d/db *conn*) '[:group/id] [:group/name group-name])))
+  [conn group-name]
+  (some? (d/pull (d/db conn) '[:group/id] [:group/name group-name])))
 
 (defn create-group!
   [{:keys [name id]}]

                          first))))))

(defn get-thread
  [thread-id]
  (some-> (d/pull (d/db *conn*) thread-pull-pattern [:thread/id thread-id])
          db->thread))

(defn get-threads
  [thread-ids]
  (->> thread-ids
       (map (fn [id] [:thread/id id]))
       (d/pull-many (d/db *conn*) thread-pull-pattern)
       (map db->thread)))

(defn get-subscribed-thread-ids-for-user
  [user-id]
  (d/q '[:find [?thread-id ...]
         :in $ ?user-id
         :where
         [?user :user/id ?user-id]
         [?user :user/subscribed-thread ?thread]
         [?thread :thread/id ?thread-id]]
       (d/db *conn*)
       user-id))

(defn user-hide-thread!
  [user-id thread-id]
  (d/transact
    *conn*
    [[:db/retract [:user/id user-id] :user/open-thread [:thread/id thread-id]]]))

(defn create-tag! [attrs]

      db->user))

(defn nickname-taken?
  [conn nickname]
  (some? (d/entity (d/db conn) [:user/nickname nickname])))

(defn set-nickname!
  "Set the user's nickname"
  [conn user-id nickname]
  (d/transact conn [[:db/add [:user/id user-id] :user/nickname nickname]]))

(defn get-nickname
  [conn user-id]
  (:user/nickname (d/pull (d/db conn) '[:user/nickname] [:user/id user-id])))

(defn authenticate-user
  "returns user-id if email and password are correct"
  [conn email password]
  (->> (let [[user-id password-token]
             (d/q '[:find [?id ?password-token]
                    :in $ ?email
