Compare commits

..

No commits in common. "master" and "1.0.1" have entirely different histories.

8 changed files with 44 additions and 41 deletions

View file

@ -1,8 +1,8 @@
# dda-masto-embed
![build](https://gitlab.com/domaindrivenarchitecture/dda-masto-embed/-/commits/master) | [![pipeline status](https://gitlab.com/domaindrivenarchitecture/dda-masto-embed/badges/main/pipeline.svg)](https://gitlab.com/domaindrivenarchitecture/dda-masto-embed/-/commits/master)
![build](https://github.com/DomainDrivenArchitecture/dda-masto-embed/workflows/build-it/badge.svg)
[<img src="https://domaindrivenarchitecture.org/img/delta-chat.svg" width=20 alt="DeltaChat"> chat over e-mail](mailto:buero@meissa-gmbh.de?subject=community-chat) | [<img src="https://meissa.de/images/parts/contact/mastodon36_hue9b2464f10b18e134322af482b9c915e_5501_filter_14705073121015236177.png" width=20 alt="M"> meissa@social.meissa-gmbh.de](https://social.meissa-gmbh.de/@meissa) | [Blog](https://domaindrivenarchitecture.org) | [Website](https://meissa.de)
[<img src="https://meissa-gmbh.de/img/community/Mastodon_Logotype.svg" width=20 alt="team@social.meissa-gmbh.de"> team@social.meissa-gmbh.de](https://social.meissa-gmbh.de/@team) | [Website & Blog](https://domaindrivenarchitecture.org)
## In brief
@ -137,6 +137,6 @@ Mirrors are:
## License
Copyright © 2024 meissa GmbH
Copyright © 2023 meissa GmbH
Licensed under the [Apache License, Version 2.0](LICENSE) (the "License")
Pls. find licenses of our subcomponents [here](doc/SUBCOMPONENT_LICENSE)

View file

@ -9,7 +9,7 @@ name = 'dda-masto-embed'
MODULE = 'not-used'
PROJECT_ROOT_PATH = '.'
version = "1.0.2-dev"
version = "1.0.1"
@init
def initialize(project):

View file

@ -1,7 +1,7 @@
{
"name": "dda-masto-embed",
"author": "meissa GmbH",
"version": "1.0.2-SNAPSHOT",
"version": "1.0.1",
"homepage": "https://github.com/DomainDrivenArchitecture/dda-masto-embed",
"repository": "https://github.com/DomainDrivenArchitecture/dda-masto-embed",
"license": "Apache-2.0",

View file

@ -8,7 +8,7 @@
[hiccups "0.3.0"]
[org.clj-commons/hickory "0.7.4"]
[com.andrewmcveigh/cljs-time "0.5.2"]
[org.domaindrivenarchitecture/c4k-common-cljs "8.0.0"]]
[org.domaindrivenarchitecture/c4k-common-cljs "6.2.3"]]
:dev-http {8080 "public"}
:builds
{:test {:target :node-test

View file

@ -17,6 +17,7 @@
(:require
["mastodon-api" :as Mastodon]
[dda.masto-embed.infra :as infra]
[cljs-time.format :as t]
[clojure.spec.alpha :as s]
[orchestra.core :refer-macros [defn-spec]]))

View file

@ -15,6 +15,8 @@
; limitations under the License.
(ns dda.masto-embed.infra
(:require
[cljs.core.async :refer [go]]
[cljs.core.async.interop :refer-macros [<p!]]
[clojure.pprint :as pprint :refer [pprint]]))
(defn exit-with-error [error]

View file

@ -15,10 +15,12 @@
; limitations under the License.
(ns dda.masto-embed.modes
(:require
[cljs.core.async :refer [go chan <! >!]]
[cljs.core.async :refer [go close! put! take! timeout chan <! >!]]
[cljs.core.async.interop :refer-macros [<p!]]
[hiccups.runtime :refer [render-html]]
[cljs-time.format :as t]
[dda.masto-embed.api :as api]
[dda.masto-embed.infra :as infra]
[dda.masto-embed.browser :as b]
[dda.masto-embed.to-html :as th]
))
@ -34,7 +36,8 @@
(<p! (api/get-favorited-by host-url reply-id))
api/mastojs->edn
(filter #(= account-name (:acct %)))
(seq))))
(empty?)
(not))))
out))
(defn favorited? [host-url account-name replies]
@ -61,7 +64,7 @@
first)))
out))
(defn replies-mode-raw [host-url account-name post-id filter-favorited]
(defn replies-mode [host-url account-name post-id filter-favorited]
(go
(let [replies (->
(<p! (api/get-replies host-url post-id))
@ -71,16 +74,12 @@
(->> combined
(filter #(or (not filter-favorited) (:favorited %)))
(reverse)
(map :status)))))
(map :status)
(th/masto->html "replies-mode")
(render-html)
(b/render-to-document)))))
(defn replies-mode [host-url account-name post-id filter-favorited]
(go
(->> (replies-mode-raw host-url account-name post-id filter-favorited)
(th/masto->html "replies-mode")
(render-html)
(b/render-to-document))))
(defn account-mode-raw [host-url account-name]
(defn account-mode [host-url account-name]
(go
(let [account-id (<! (find-account-id host-url account-name))
status (->
@ -89,11 +88,7 @@
(->> status
(filter #(= nil (:reblog %)))
(filter #(= nil (:in_reply_to_account_id %)))
(take 4)))))
(defn account-mode [host-url account-name]
(go
(->> (account-mode-raw host-url account-name)
(th/masto->html "account-mode")
(render-html)
(b/render-to-document))))
(take 4)
(th/masto->html "account-mode")
(render-html)
(b/render-to-document)))))

View file

@ -15,7 +15,12 @@
; limitations under the License.
(ns dda.masto-embed.to-html
(:require
[cljs.core.async :refer [go chan <! >!]]
[cljs.core.async.interop :refer-macros [<p!]]
[hiccups.runtime :refer [render-html]]
[cljs-time.format :as t]
[dda.masto-embed.api :as api]
[dda.masto-embed.infra :as infra]
[dda.masto-embed.browser :as b]
[dda.c4k-common.common :as cm]
[clojure.walk :refer [postwalk]]))
@ -38,16 +43,16 @@
(let [{:keys [username display_name avatar_static]} account
date (t/parse created_at)]
(-> html
(cm/replace-all-matching "AVATAR_URL" avatar_static)
(cm/replace-all-matching "POST_URL" url)
(cm/replace-all-matching "DISPLAY_NAME" display_name)
(cm/replace-all-matching "ACCOUNT_NAME" (str "@" username))
(cm/replace-all-matching "DATETIME" created_at)
(cm/replace-all-matching "TIME" (t/unparse (t/formatter "EEEE, dd MMMM yyyy") date)))))
(cm/replace-all-matching-values-by-new-value "AVATAR_URL" avatar_static)
(cm/replace-all-matching-values-by-new-value "POST_URL" url)
(cm/replace-all-matching-values-by-new-value "DISPLAY_NAME" display_name)
(cm/replace-all-matching-values-by-new-value "ACCOUNT_NAME" (str "@" username))
(cm/replace-all-matching-values-by-new-value "DATETIME" created_at)
(cm/replace-all-matching-values-by-new-value "TIME" (t/unparse (t/formatter "EEEE, dd MMMM yyyy") date)))))
(defn masto-content->html [html content]
(-> html
(cm/replace-all-matching "POST_TEXT" content)))
(cm/replace-all-matching-values-by-new-value "POST_TEXT" content)))
; Meant to be used in postwalk on hiccup/hickory html-representation
(defn insert-into-content [item insertion-element]
@ -83,20 +88,20 @@
html
(-> html
(insert-link-prev)
(cm/replace-all-matching "LINK_PREVIEW_URL" url)
(cm/replace-all-matching "LINK_PREVIEW_IMG_URL" image)
(cm/replace-all-matching "LINK_PREVIEW_TITLE" (str (truncate title 47) "..."))
(cm/replace-all-matching "LINK_PREVIEW_DESC" description)))))
(cm/replace-all-matching-values-by-new-value "LINK_PREVIEW_URL" url)
(cm/replace-all-matching-values-by-new-value "LINK_PREVIEW_IMG_URL" image)
(cm/replace-all-matching-values-by-new-value "LINK_PREVIEW_TITLE" (str (truncate title 47) "..."))
(cm/replace-all-matching-values-by-new-value "LINK_PREVIEW_DESC" description)))))
(defn masto-footer->html [html replies_count reblogs_count favourites_count]
(-> html
(cm/replace-all-matching "REPLIES_COUNT" replies_count)
(cm/replace-all-matching "REBLOGS_COUNT" reblogs_count)
(cm/replace-all-matching "FAVOURITES_COUNT" favourites_count)))
(cm/replace-all-matching-values-by-new-value "REPLIES_COUNT" replies_count)
(cm/replace-all-matching-values-by-new-value "REBLOGS_COUNT" reblogs_count)
(cm/replace-all-matching-values-by-new-value "FAVOURITES_COUNT" favourites_count)))
(defn insert-mode [html mode]
(-> html
(cm/replace-all-matching "section MODE" (str "section " mode))))
(cm/replace-all-matching-values-by-new-value "section MODE" (str "section " mode))))
(defn masto->html [mode statuses]
(let [html (b/post-html-hiccup)]