   (let [ids-to-send-to (disj
                          (intersection
                            (set (:any @connected-uids))
-                           (into #{} (map :id)
-                                 (db/with-conn (db/fetch-users-for-user user-id))))
+                           (into
+                             #{} (map :id)
+                             (db/with-conn (db/fetch-users-for-user user-id))))
                          user-id)]
     (doseq [uid ids-to-send-to]
       (chsk-send! uid info))))

                               (db/with-conn (db/get-users-in-group group-id))))]
    (doseq [uid ids-to-send-to]
      (chsk-send! uid info))))

(defmethod event-msg-handler :chsk/uidport-open
  [{:as ev-msg :keys [event id ring-req]}]
  (when-let [user-id (get-in ring-req [:session :user-id])]
    (broadcast-user-change user-id [:user/connected user-id])))

(defmethod event-msg-handler :chsk/uidport-close
  [{:as ev-msg :keys [event id ring-req]}]
  (when-let [user-id (get-in ring-req [:session :user-id])]
    (broadcast-user-change user-id [:user/disconnected user-id])))

(defn user-can-message? [user-id ?data]
  (db/with-conn

    (when ?reply-fn
      (?reply-fn {:umatched-event-as-echoed-from-from-server event}))))

;; Handler helpers

(defn broadcast-thread
  "broadcasts thread to all subscribed users, except those in ids-to-skip"
  [thread-id ids-to-skip]
  (db/with-conn
    (let [subscribed-user-ids (db/get-users-subscribed-to-thread thread-id)
          user-ids-to-send-to (-> (difference
                                    (intersection
                                      (set subscribed-user-ids)
                                      (set (:any @connected-uids)))
                                    (set ids-to-skip)))
          thread (db/get-thread thread-id)]
      (doseq [uid user-ids-to-send-to]
        (let [user-tags (db/get-user-visible-tag-ids uid)
              filtered-thread (update-in thread [:tag-ids]
                                         (partial into #{} (filter user-tags)))
              thread-with-last-opens (db/thread-add-last-open-at
                                       filtered-thread uid)]
          (chsk-send! uid [:chat/thread thread-with-last-opens]))))))

(defn broadcast-user-change
  "Broadcast user info change to clients that can see this user"
