<commit_before>(ns braid.client.subs
  (:require [reagent.ratom :include-macros true :refer-macros [reaction]]
            [re-frame.core :refer [subscribe reg-sub reg-sub-raw]])
  (:import goog.Uri))

(reg-sub
  :open-group-id
  (fn [state _]
    (get-in state [:open-group-id])))

(reg-sub-raw
  :active-group
  (fn [state _]
    (let [group-id (reaction (:open-group-id @state))]
      (reaction (get-in @state [:groups @group-id])))))

(reg-sub
  :groups
  (fn [state _]
    (vals (:groups state))))

(reg-sub
  :group
  (fn [state [_ q-group-id] [d-group-id]]
    (get-in state [:groups (or d-group-id q-group-id)])))

(defn order-groups
  "Helper function to impose an order on groups.
  This is a seperate function (instead of inline in :ordered-groups because the
  index route needs to be able to call this to find the first group"
  [groups group-order]
  (if (nil? group-order)
    groups
    (let [ordered? (comp boolean (set group-order) :id)
          {ord true unord false} (group-by ordered? groups)
          by-id (group-by :id groups)]
      (concat
        (map (comp first by-id) group-order)
        unord))))

(reg-sub
  :ordered-groups
  :<- [:groups]
  :<- [:user-preference :groups-order]
  (fn [[groups group-order] _]
    (order-groups groups group-order)))

(reg-sub
  :group-bots
  (fn [state _ [group-id]]
    (get-in state [:groups group-id :bots])))

(reg-sub
  :user
  (fn [state [_ q-user-id] [d-user-id]]
    (let [user-id (or d-user-id q-user-id)]
      (if-let [u (get-in state [:users user-id])]
        u
        (let [g-id (state :open-group-id)
              group-bots (get-in state [:groups g-id :bots])]
          (-> group-bots
              (->> (filter (fn [b] (= (b :user-id) user-id))))
              first
              (assoc :bot? true)))))))

(reg-sub<commit_msg>Ensure user sub returns nil if no such user<commit_after>(ns braid.client.subs
  (:require [reagent.ratom :include-macros true :refer-macros [reaction]]
            [re-frame.core :refer [subscribe reg-sub reg-sub-raw]])
  (:import goog.Uri))

(reg-sub
  :open-group-id
  (fn [state _]
    (get-in state [:open-group-id])))

(reg-sub-raw
  :active-group
  (fn [state _]
    (let [group-id (reaction (:open-group-id @state))]
      (reaction (get-in @state [:groups @group-id])))))

(reg-sub
  :groups
  (fn [state _]
    (vals (:groups state))))

(reg-sub
  :group
  (fn [state [_ q-group-id] [d-group-id]]
    (get-in state [:groups (or d-group-id q-group-id)])))

(defn order-groups
  "Helper function to impose an order on groups.
  This is a seperate function (instead of inline in :ordered-groups because the
  index route needs to be able to call this to find the first group"
  [groups group-order]
  (if (nil? group-order)
    groups
    (let [ordered? (comp boolean (set group-order) :id)
          {ord true unord false} (group-by ordered? groups)
          by-id (group-by :id groups)]
      (concat
        (map (comp first by-id) group-order)
        unord))))

(reg-sub
  :ordered-groups
  :<- [:groups]
  :<- [:user-preference :groups-order]
  (fn [[groups group-order] _]
    (order-groups groups group-order)))

(reg-sub
  :group-bots
  (fn [state _ [group-id]]
    (get-in state [:groups group-id :bots])))

(reg-sub
  :user
  (fn [state [_ q-user-id] [d-user-id]]
    (let [user-id (or d-user-id q-user-id)]
      (if-let [u (get-in state [:users user-id])]
        u
        (let [g-id (state :open-group-id)
              group-bots (get-in state [:groups g-id :bots])]
          (some-> group-bots
                  (->> (filter (fn [b] (= (b :user-id) user-id))))
                  first
                  (assoc :bot? true)))))))

(reg-sub
{'fraction_non_alphanumeric': 0.1701086956521739, 'fraction_numerical': 0.0, 'mean_word_length': 2.4759206798866855, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5079349', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1349, 'n_words': 374}