<commit_before>(ns braid.ui.views.thread
  (:require [clojure.string :as string]
            [reagent.core :as r]
            [chat.client.reagent-adapter :refer [reagent->react subscribe]]
            [chat.client.store :as store]
            [chat.client.dispatcher :refer [dispatch!]]
            [chat.client.s3 :as s3]
            [braid.ui.views.pills :refer [user-pill-view tag-pill-view]]
            [braid.ui.views.message :refer [message-view]]
            [braid.ui.views.new-message :refer [new-message-view]])
  (:import [goog.events KeyCodes]))

(def max-file-size (* 10 1024 1024))

(defn thread-tags-view [thread]
  ; Closing over thread-id, but the only time a thread's id changes is the new
  ; thread box, which doesn't have tags anyway
  (let [tags (subscribe [:tags-for-thread (thread :id)])
        mentions (subscribe [:mentions-for-thread (thread :id)])]
    [:div.tags
     (doall
       (for [user @mentions]
         ^{:key (user :id)}
         [user-pill-view (user :id)]))
     (doall
       (for [tag @tags]
         ^{:key (tag :id)}
         [tag-pill-view (tag :id)]))]))

(defn- unseen? [message thread]
  (> (:created-at message)
     (thread :last-open-at)))

(defn- thread-private? [thread]
  (and
    (not (thread :new?))
    (empty? (thread :tag-ids))
    (seq (thread :mentioned-ids))))

(defn- thread-limbo? [thread]
  (and
    (not (thread :new?))
    (empty? (thread :tag-ids))
    (empty? (thread :mentioned-ids))))

(defn messages-view [thread]
  ; Closing over thread-id, but the only time a thread's id changes is the new
  ; thread box, which doesn't have messages anyway
  (let [messages (subscribe [:messages-for-thread (thread :id)])

        scroll-to-bottom!
        (fn [component]
          (when-let [messages (r/dom-node component)]
            (set! (.-scrollTop messages) (.-scrollHeight messages))))]
    (r/create-class
      {:display-name "thread"

       :component-did-mount scroll-to-bottom!

       :component-will-receive-props scroll-to-bottom!

       :component-did-update scroll-to-bottom!

       :reagent-render
       (fn [thread]<commit_msg>if we scroll on did-update, don't also need will-receive-props<commit_after>(ns braid.ui.views.thread
  (:require [clojure.string :as string]
            [reagent.core :as r]
            [chat.client.reagent-adapter :refer [reagent->react subscribe]]
            [chat.client.store :as store]
            [chat.client.dispatcher :refer [dispatch!]]
            [chat.client.s3 :as s3]
            [braid.ui.views.pills :refer [user-pill-view tag-pill-view]]
            [braid.ui.views.message :refer [message-view]]
            [braid.ui.views.new-message :refer [new-message-view]])
  (:import [goog.events KeyCodes]))

(def max-file-size (* 10 1024 1024))

(defn thread-tags-view [thread]
  ; Closing over thread-id, but the only time a thread's id changes is the new
  ; thread box, which doesn't have tags anyway
  (let [tags (subscribe [:tags-for-thread (thread :id)])
        mentions (subscribe [:mentions-for-thread (thread :id)])]
    [:div.tags
     (doall
       (for [user @mentions]
         ^{:key (user :id)}
         [user-pill-view (user :id)]))
     (doall
       (for [tag @tags]
         ^{:key (tag :id)}
         [tag-pill-view (tag :id)]))]))

(defn- unseen? [message thread]
  (> (:created-at message)
     (thread :last-open-at)))

(defn- thread-private? [thread]
  (and
    (not (thread :new?))
    (empty? (thread :tag-ids))
    (seq (thread :mentioned-ids))))

(defn- thread-limbo? [thread]
  (and
    (not (thread :new?))
    (empty? (thread :tag-ids))
    (empty? (thread :mentioned-ids))))

(defn messages-view [thread]
  ; Closing over thread-id, but the only time a thread's id changes is the new
  ; thread box, which doesn't have messages anyway
  (let [messages (subscribe [:messages-for-thread (thread :id)])

        scroll-to-bottom!
        (fn [component]
          (when-let [messages (r/dom-node component)]
            (set! (.-scrollTop messages) (.-scrollHeight messages))))]
    (r/create-class
      {:display-name "thread"

       :component-did-mount scroll-to-bottom!

       :component-did-update scroll-to-bottom!

       :reagent-render
       (fn [thread]
{'fraction_non_alphanumeric': 0.15701111373847246, 'fraction_numerical': 0.005675100496571293, 'mean_word_length': 2.5877862595419847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '100617', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1407, 'n_words': 373}