                       :message/content
                       {:message/user [:user/id]}
                       :message/created-at]}])
+
+(def user-pull-pattern
+  '[:user/id
+    :user/nickname
+    :user/avatar
+    {:group/_user [:group/id]}])
 
 (defn- db->thread
   [thread]

(defn fetch-users-for-user
  "Get all users visible to given user"
  [user-id]
  (->> (d/q '[:find (pull ?e [:user/id
                              :user/nickname
                              :user/avatar
                              {:group/_user [:group/id]}])
              :in $ ?user-id
              :where
              [?u :user/id ?user-id]
              [?g :group/user ?u]
              [?g :group/user ?e]]
            (d/db *conn*) user-id)
       (map (comp db->user first))
       set))


       set))

(defn get-users-in-group [group-id]
  (->> (d/q '[:find (pull ?u pull-pattern)
              :in $ ?group-id pull-pattern
              :where
              [?g :group/id ?group-id]
              [?g :group/user ?u]]
            (d/db *conn*)
            group-id
            user-pull-pattern)
       (map (comp db->user first))
       set))

