From 1cb2d824d0d490d7f980c49db451c4dd6a775671 Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 24 Feb 2022 14:08:43 +0100 Subject: [PATCH 1/5] refactor app to use common function --- src/main/dda/masto_embed/app.cljs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/dda/masto_embed/app.cljs b/src/main/dda/masto_embed/app.cljs index d42acae..325ded6 100644 --- a/src/main/dda/masto_embed/app.cljs +++ b/src/main/dda/masto_embed/app.cljs @@ -25,20 +25,19 @@ (def masto-embed "masto-embed") -(defn host-url-from-document [] +(defn element-from-document-by-name [name] (-> js/document (.getElementById masto-embed) - (.getAttribute "host_url"))) + (.getAttribute name))) + +(defn host-url-from-document [] + (element-from-document-by-name "host_url")) (defn account-name-from-document [] - (-> js/document - (.getElementById masto-embed) - (.getAttribute "account_name"))) + (element-from-document-by-name "account_name")) (defn account-id-from-document [] - (-> js/document - (.getElementById masto-embed) - (.getAttribute "account_id"))) + (element-from-document-by-name "account_id")) (defn render-to-document [input] From bc5af89daa3978f5d21158a0817eef23184d4b84 Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 24 Feb 2022 15:56:35 +0100 Subject: [PATCH 2/5] base function to get replies to status --- src/main/dda/masto_embed/api.cljs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/dda/masto_embed/api.cljs b/src/main/dda/masto_embed/api.cljs index a5842bf..97ce77f 100644 --- a/src/main/dda/masto_embed/api.cljs +++ b/src/main/dda/masto_embed/api.cljs @@ -41,6 +41,16 @@ (str "accounts/" account-id "/statuses") #js {})) +; https://mastodon.example/api/v1/statuses/:id/context +; for parent and child statuses +; "descendants" +(defn get-replies + [host-url + status-id] + (.get (mastodon-client host-url) + (str "statuses/" status-id "/context") + #js {})) + (defn-spec get-directory any? [host-url ::host-url] (.get (mastodon-client host-url) From c09524e1a861b96103875858f8e814386227427b Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 24 Feb 2022 15:56:51 +0100 Subject: [PATCH 3/5] updated gitignote --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index fc6713d..2c77f76 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ pom.xml.asc .lein-plugins/ .lein-failures .nrepl-port +package-lock.json +output.calva-repl .cpcache/ .shadow-cljs/ node_modules/ From a1533bd452c4290cc365155fa5ce9d75b12d8ae8 Mon Sep 17 00:00:00 2001 From: bom Date: Wed, 2 Mar 2022 14:40:25 +0100 Subject: [PATCH 4/5] WIP for automatic comments --- src/main/dda/masto_embed/api.cljs | 12 +++++++++++ src/main/dda/masto_embed/app.cljs | 36 +++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main/dda/masto_embed/api.cljs b/src/main/dda/masto_embed/api.cljs index 97ce77f..85354aa 100644 --- a/src/main/dda/masto_embed/api.cljs +++ b/src/main/dda/masto_embed/api.cljs @@ -51,8 +51,20 @@ (str "statuses/" status-id "/context") #js {})) +(defn get-favorited-by + [host-url + status-id] + (.get (mastodon-client host-url) + (str "statuses/" status-id "/favourited_by") + #js {})) + (defn-spec get-directory any? [host-url ::host-url] (.get (mastodon-client host-url) (str "directory?local=true") #js {})) + +; TODO: +; 1. ID of status with reply: 107655615528722482 +; 2. Get replies to status +; 3. Filter by favorited and or tags \ No newline at end of file diff --git a/src/main/dda/masto_embed/app.cljs b/src/main/dda/masto_embed/app.cljs index 325ded6..882cb14 100644 --- a/src/main/dda/masto_embed/app.cljs +++ b/src/main/dda/masto_embed/app.cljs @@ -59,20 +59,44 @@ first))) out)) +(defn favorited-replies? [host-url reply-id account-name] + (let [out (chan)] + (go (>! out + (->> + (edn + (filter #(= account-name (:acct %))) + (empty?) + (not) + (infra/debug)))) + out)) + (defn init [] (go (let [host-url (host-url-from-document) account-name (account-name-from-document) - account-id (or + account-id (or (account-id-from-document) ( (edn) - ] - (->> statuus - (take 4) + test-status (-> + (edn) + filtered (->> + (:descendants test-status) + (filter #(favorited-replies? host-url (:id %) account-name)) + (infra/debug))] + ;(->> statuus + ; (take 4) + ; (rb/masto->html) + ; (render-html) + ; (render-to-document)) + (->> filtered + (infra/debug) (rb/masto->html) (render-html) - (render-to-document)) - ))) + (render-to-document))))) + + From 631a6472551e7802673468a745263c04ae145c04 Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 4 Mar 2022 10:53:19 +0100 Subject: [PATCH 5/5] WIP mob --- src/main/dda/masto_embed/api.cljs | 10 ++++++++++ src/main/dda/masto_embed/app.cljs | 27 ++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/main/dda/masto_embed/api.cljs b/src/main/dda/masto_embed/api.cljs index 85354aa..4de34c9 100644 --- a/src/main/dda/masto_embed/api.cljs +++ b/src/main/dda/masto_embed/api.cljs @@ -51,6 +51,16 @@ (str "statuses/" status-id "/context") #js {})) +(defn get-filtered-replies + [host-url + status-id + account] + (->> (.get (mastodon-client host-url) + (str "statuses/" status-id "/context") + #js {}) + mastojs->edn + (:descendants))) + (defn get-favorited-by [host-url status-id] diff --git a/src/main/dda/masto_embed/app.cljs b/src/main/dda/masto_embed/app.cljs index 882cb14..3c15b9a 100644 --- a/src/main/dda/masto_embed/app.cljs +++ b/src/main/dda/masto_embed/app.cljs @@ -66,9 +66,7 @@ (edn (filter #(= account-name (:acct %))) - (empty?) - (not) - (infra/debug)))) + ))) out)) (defn init [] @@ -82,21 +80,24 @@ (edn) test-status (-> - (edn) - filtered (->> - (:descendants test-status) - (filter #(favorited-replies? host-url (:id %) account-name)) - (infra/debug))] + filtered (filter #(go (> statuus ; (take 4) ; (rb/masto->html) ; (render-html) ; (render-to-document)) - (->> filtered - (infra/debug) - (rb/masto->html) - (render-html) - (render-to-document))))) + ;(go (infra/debug (edn (> filtered + ; (infra/debug) + ; (rb/masto->html) + ; (render-html) + ; (render-to-document)) + )))