bring back comment content; some refactoring

master
Clyne 1 year ago
parent 174d96bd2c
commit 5523960bef
Signed by: clyne
GPG Key ID: 1B74EE6C49C96795

@ -22,18 +22,21 @@
(defn comments-list [post]
(-> (make-api-url INSTANCE COMMENTS)
(api-call {:post_id (str (get-in post ["post" "id"]))})
(api-call {:limit "50" :post_id (str (get-in post ["post" "id"]))})
(get "comments")))
(defn show-post-item [post]
(println (get-in post ["creator" "name"]) "on" (get-in post ["community" "name"]))
(println (get-in post ["post" "name"]))
(println "at" (get-in post ["post" "published"]) "(" (get-in post ["counts" "comments"]) "comments)")
(println)
)
(let [items [["creator" "name"]
["community" "name"]
["post" "name"]
["post" "published"]
["counts" "comments"]]
data (mapv (partial get-in post) items)]
(apply (partial printf "%s on %s\n%s\nat %s (%d comments)\n\n") data)))
(defn show-comment-item [commnt]
(println (get-in commnt ["creator" "name"]) "says:")
(println (get-in commnt ["comment" "content"]))
(println)
)
@ -56,31 +59,31 @@
(first (read-line)))
(defn view-post [post]
(println "Viewing post id:" (get-in post ["post" "id"]))
(loop [offset 0 comments (comments-list post)]
(println (count comments) offset)
(show-comments (if (pos? offset) (drop (* 5 offset) comments) comments))
(flush)
(case (show-comments-prompt)
\B (println)
\N (recur (inc offset) comments)
\P (recur (dec offset) comments)
(do (println "Unknown command.") (recur offset comments)))))
(defn -main [& args]
(defn view-page []
(loop [top true page 1 posts (post-list page)]
(show-posts (if top posts (drop 5 posts)))
(flush)
(case (show-posts-prompt)
\N (if top (recur false page posts)
(recur true (inc page) (post-list (inc page))))
\P (if top (recur false (dec page) (post-list (dec page)))
(recur true page posts))
\Q (println "Goodbye.")
\1 (do (view-post (nth posts 0)) (recur top page posts))
\2 (do (view-post (nth posts 1)) (recur top page posts))
\3 (do (view-post (nth posts 2)) (recur top page posts))
\4 (do (view-post (nth posts 3)) (recur top page posts))
\5 (do (view-post (nth posts 4)) (recur top page posts))
\Q (do)
\1 (do (view-post (nth posts (cond-> 5 top (- 5)))) (recur top page posts))
\2 (do (view-post (nth posts (cond-> 6 top (- 5)))) (recur top page posts))
\3 (do (view-post (nth posts (cond-> 7 top (- 5)))) (recur top page posts))
\4 (do (view-post (nth posts (cond-> 8 top (- 5)))) (recur top page posts))
\5 (do (view-post (nth posts (cond-> 9 top (- 5)))) (recur top page posts))
(do (println "Unknown command.") (recur top page posts)))))
(defn -main [& args]
(view-page)
(println "Goodbye."))

Loading…
Cancel
Save