<commit_before>(ns langnostic.comments
  (:require [codax.core :as db]

            [langnostic.conf :as conf]))

(def DB (db/open-database! conf/DB-PATH))

(defn now! []
  (quot (System/currentTimeMillis) 1000))

(defn get-comments-for [post-id]
  (db/get-at! DB [:posts post-id :comments]))

(defn post-comment!
  ([user post-id content]
   (db/with-write-transaction [DB tx]
     (let [path [(count (db/get-at tx [:posts post-id :comments]))]]
       (db/update-at
        tx [:posts post-id :comments]
        #(assoc % (first path) {:user user :path path :content content :replies []})))))
  ([user post-id comment-path content]
   (db/with-write-transaction [DB tx]
     (let [target (conj comment-path :replies)
           new-ix (count (db/get-at tx (concat [:posts post-id :comments] target)))
           path (conj target new-ix)]
       (-> tx
           (db/update-at
            (concat [:posts post-id :comments] target)
            #(conj % {:user user :path path :content content :replies []})))))))

(defn edit-comment!
  [user comment-path new-content]
   nil)<commit_msg>Working basic deep comment thing<commit_after>(ns langnostic.comments
  (:require [codax.core :as db]

            [langnostic.conf :as conf]))

(def DB (db/open-database! conf/DB-PATH))

(defn now! []
  (quot (System/currentTimeMillis) 1000))

(defn get-comments-for [post-id]
  (db/get-at! DB [:posts post-id :comments]))

(defn post-comment!
  ([user post-id content]
   (db/with-write-transaction [DB tx]
     (let [path [(count (db/get-at tx [:posts post-id :comments]))]]
       (db/update-at
        tx [:posts post-id :comments]
        #(assoc % (first path) {:user user :path path :content content :replies []})))))
  ([user post-id comment-path content]
   (db/with-write-transaction [DB tx]
     (let [target (conj comment-path :replies)
           new-ix (count (db/get-at tx (concat [:posts post-id :comments] target)))
           path (conj target new-ix)]
       (db/update-at
        tx [:posts post-id :comments]
        (fn [comments]
          (update-in comments target #(conj % {:user user :path path :content content :replies []}))))))))

(defn edit-comment!
  [user comment-path new-content]
   nil)
{'fraction_non_alphanumeric': 0.1649344780840488, 'fraction_numerical': 0.0036150022593764122, 'mean_word_length': 2.870629370629371, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5296004', 'n_tokens_mistral': 773, 'n_tokens_neox': 756, 'n_words': 212}