]> code.bitgloo.com Git - clyne/lemmold.git/commitdiff
show post body master
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 15 Jul 2023 15:52:33 +0000 (11:52 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 15 Jul 2023 15:52:33 +0000 (11:52 -0400)
src/lemmold/core.clj

index fb34fdd819c5993d479bdb548994756b9b974a34..1f771357242cea5cfe4b63691f2e94e397d1c46a 100644 (file)
       \P (recur (dec offset) comments)
       (do (println "Unknown command.") (recur offset comments)))))
 
       \P (recur (dec offset) comments)
       (do (println "Unknown command.") (recur offset comments)))))
 
+(defn view-post-body
+  "Shows the body of the post if available; in that case, ask about viewing comments."
+  [post]
+  (let [body (get-in post ["post" "body"])]
+    (or (empty? body)
+        (do
+          (println)
+          (println "Post contents:")
+          (println)
+          (println body)
+          (println)
+          (print "BC> ")
+          (flush)
+          (= \C (first (read-line)))))))
+
 (defn view-nth-post
   "Views the index-th post from the current post list."
   [state posts index]
 (defn view-nth-post
   "Views the index-th post from the current post list."
   [state posts index]
-  (view-post
-    (:instance state)
-    (nth posts (cond-> (+ 5 index) (:top state) (- 5))))
+  (let [post (nth posts (cond-> (+ 5 index) (:top state) (- 5)))]
+    (when (view-post-body post)
+      (view-post (:instance state) post)))
   state)
 
 (defn get-post-list
   state)
 
 (defn get-post-list