refactored code into reply and account mode

This commit is contained in:
bom 2022-03-10 10:18:37 +01:00
parent 44177d5c0b
commit 160eacf313
2 changed files with 37 additions and 19 deletions

View file

@ -10,7 +10,9 @@
<div id="masto-embed" <div id="masto-embed"
account_name="team" account_name="team"
coment_in_account_id="2" coment_in_account_id="2"
host_url="https://social.meissa-gmbh.de"> host_url="https://social.meissa-gmbh.de"
replies_to="107779492679907372"
filter_favorited=true>
Here the timeline will appear. Here the timeline will appear.
</div> </div>
</div> </div>

View file

@ -39,6 +39,12 @@
(defn account-id-from-document [] (defn account-id-from-document []
(element-from-document-by-name "account_id")) (element-from-document-by-name "account_id"))
(defn replies-to-from-document []
(element-from-document-by-name "replies_to"))
(defn filter-favorited-from-document []
(element-from-document-by-name "filter_favorited"))
(defn render-to-document (defn render-to-document
[input] [input]
(-> js/document (-> js/document
@ -83,32 +89,42 @@
(conj result (<! (favorited-replies? host-url account-name (first loc-replies))))))))) (conj result (<! (favorited-replies? host-url account-name (first loc-replies)))))))))
out)) out))
(defn account-mode [host-url account-name]
(defn init []
(go (go
(let [host-url (host-url-from-document) (let [account-id (or
account-name (account-name-from-document)
account-id (or
(account-id-from-document) (account-id-from-document)
(<! (find-account-id host-url account-name))) (<! (find-account-id host-url account-name)))
statuus (-> statuus (->
(<p! (api/get-account-statuses host-url account-id)) (<p! (api/get-account-statuses host-url account-id))
api/mastojs->edn)]
(->> statuus
(take 4)
(rb/masto->html)
(render-html)
(render-to-document)))))
(defn replies-mode [host-url account-name post-id filter-favorited]
(go
(let [test-status (->
(<p! (api/get-replies host-url post-id))
api/mastojs->edn) api/mastojs->edn)
test-status (-> favorited (<! (favorited? host-url account-name (map :id (:descendants test-status))))
(<p! (api/get-replies host-url "107779492679907372"))
api/mastojs->edn)
favorited (<! (favorited? host-url "bastian@digitalcourage.social" (map :id (:descendants test-status))))
combined (map (fn [s f] {:status s :favorited f}) (:descendants test-status) favorited) combined (map (fn [s f] {:status s :favorited f}) (:descendants test-status) favorited)
filtered (map :status (filter :favorited combined)) filtered (map :status (filter :favorited combined))
] statuus (if filter-favorited filtered test-status)]
;(->> statuus (->> statuus
; (take 4)
; (rb/masto->html)
; (render-html)
; (render-to-document))
(->> filtered
(infra/debug) (infra/debug)
(rb/masto->html) (rb/masto->html)
(render-html) (render-html)
(render-to-document)) (render-to-document)))))
)))
(defn init []
(let [host-url (host-url-from-document)
account-name (account-name-from-document)
replies-to (replies-to-from-document)
filter-favorited (filter-favorited-from-document)
]
(if (nil? replies-to)
(account-mode host-url account-name)
(replies-mode host-url account-name replies-to filter-favorited))
))