<commit_before>(ns hsm.controllers.discussion
  (:require [clojure.tools.logging :as log]
            [clojure.java.io :as io]
            [markdown.core :refer [md-to-html-string]]
            [cheshire.core :refer :all]
            [ring.util.response :as resp]
            [slingshot.slingshot :refer [throw+ try+]]
            [hsm.actions :as actions]
            [hsm.pipe.event :as event-pipe]
            [hsm.views :refer [layout panel panelx render-user]]
            [hsm.ring :refer [json-resp html-resp redirect]]
            [hsm.utils :as utils :refer [body-of host-of whois type-of id-of common-of !!nil? cutoff mapkeyw]]))

(defn load-discussions
  [{:keys [db event-chan redis conf]} request]
  (let [{:keys [host id body json? user pl]} (common-of request)
        top-disc (actions/load-discussions db)]
  (if json?
    (json-resp top-disc)
    (layout host 
      (panelx
        [:div [:a {:href (format "/discussions" pl)} "Discussions"] 
              [:a.pull-right.btn.btn-primary.btn-xs {:href "/discussion/new"} "Start a Discussion"]]
        [:div [:a.btn.btn-primary.btn-xs {:href "/discussion/new"} "Start a Discussion"]]
        ""
        (for [x top-disc]
          [:div.bs-callout
            [:div.row 
              [:div.col-lg-6 
                [:a {:href (str "/discussion/" (:id x))} (:title x) 
                [:p {:style "color:gray" } 
                (cutoff (get-in x [:post :text]) 200)]]]
              [:div.col-lg-3 "Users"]
              [:div.col-lg-1 "Count"]
              [:div.col-lg-2 "Activity"]
              ]]))))))

(defn get-discussion 
  [{:keys [db event-chan redis conf]} request]
  (let [{:keys [host id body json? user]} (common-of request)
        disc-id (BigInteger. id)
        discussion (actions/load-discussion db disc-id)
        posts (actions/load-discussion-posts db disc-id)]
    (log/info "[DISC]Loading " id discussion)
    (if json?
      (json-resp discussion)
      (html-resp
          (layout host 
            ; (panelx
               "" ""
            [:div.row 
              [:div.col-lg-10
              [:div.bs-callout.bs-callout-danger
                [:div.post-head 
                      (render-user (actions/load-user2 db "bcambel") :show-followers false)]
                [:h4 (:title discussion)]
                [:p (md-to-html-string (get-in discussion [:post :text]))]
                [:hr]<commit_msg>display time at discussion list<commit_after>(ns hsm.controllers.discussion
  (:require [clojure.tools.logging :as log]
            [clojure.java.io :as io]
            [markdown.core :refer [md-to-html-string]]
            [cheshire.core :refer :all]
            [ring.util.response :as resp]
            [slingshot.slingshot :refer [throw+ try+]]
            [hsm.actions :as actions]
            [hsm.pipe.event :as event-pipe]
            [hsm.views :refer [layout panel panelx render-user]]
            [hsm.ring :refer [json-resp html-resp redirect]]
            [hsm.utils :as utils :refer [body-of host-of whois type-of id-of common-of !!nil? cutoff mapkeyw]]))

(defn load-discussions
  [{:keys [db event-chan redis conf]} request]
  (let [{:keys [host id body json? user pl]} (common-of request)
        top-disc (actions/load-discussions db)]
  (if json?
    (json-resp top-disc)
    (layout host 
      (panelx
        [:div [:a {:href (format "/discussions" pl)} "Discussions"] 
              [:a.pull-right.btn.btn-primary.btn-xs {:href "/discussion/new"} "Start a Discussion"]]
        [:div [:a.btn.btn-primary.btn-xs {:href "/discussion/new"} "Start a Discussion"]]
        ""
        (for [x top-disc]
          [:div.bs-callout
            [:div.row 
              [:div.col-lg-6 
                [:a {:href (str "/discussion/" (:id x))} (:title x) 
                [:p {:style "color:gray" } 
                (cutoff (get-in x [:post :text]) 200)]]]
              [:div.col-lg-3 "Users"]
              [:div.col-lg-1 "Count"]
              [:div.col-lg-2 (:published_at x)]
              ]]))))))

(defn get-discussion 
  [{:keys [db event-chan redis conf]} request]
  (let [{:keys [host id body json? user]} (common-of request)
        disc-id (BigInteger. id)
        discussion (actions/load-discussion db disc-id)
        posts (actions/load-discussion-posts db disc-id)]
    (log/info "[DISC]Loading " id discussion)
    (if json?
      (json-resp discussion)
      (html-resp
          (layout host 
            ; (panelx
               "" ""
            [:div.row 
              [:div.col-lg-10
              [:div.bs-callout.bs-callout-danger
                [:div.post-head 
                      (render-user (actions/load-user2 db "bcambel") :show-followers false)]
                [:h4 (:title discussion)]
                [:p (md-to-html-string (get-in discussion [:post :text]))]
                [:hr]
{'fraction_non_alphanumeric': 0.15583075335397317, 'fraction_numerical': 0.004540763673890609, 'mean_word_length': 1.8043981481481481, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4539777', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1518, 'n_words': 382}