fix screen name & add untrimmed option

This commit is contained in:
jem 2020-05-22 10:14:04 +02:00
parent 8ccdbde8ec
commit 0a0e9fb2ae
2 changed files with 17 additions and 10 deletions

View file

@ -8,9 +8,13 @@
(s/def ::created-at any?) (s/def ::created-at any?)
(s/def ::text string?) (s/def ::text string?)
(s/def ::untrimmed-text string?)
(s/def ::media-links string?) (s/def ::media-links string?)
(s/def ::screen_name string?) (s/def ::screen_name string?)
(def element? (s/keys :req-un [::created-at ::text ::media-links ::screen_name])) (def input? (s/keys :req-un [::created-at ::text ::screen_name]
:opt-un [::media-links ::untrimmed-text]))
(def mastodon-output? (s/keys :req-un [::created-at ::text]
:opt-un [::media-links]))
(defn trim-text [text max-post-length] (defn trim-text [text max-post-length]
(cond (cond
@ -29,14 +33,16 @@
:else text)) :else text))
(defn-spec to-mastodon any? (defn-spec to-mastodon mastodon-output?
[mastodon-config masto/mastodon-config? [mastodon-config masto/mastodon-config?
input element?] input input?]
(let [{:keys [created-at text media-links screen_name]} input] (let [{:keys [created-at text media-links screen_name untrimmed-text]} input]
{:created-at created-at {:created-at created-at
:text (trim-text :text (str (trim-text
(str text text
(masto/max-post-length mastodon-config))
(if (some? untrimmed-text)
(str " " untrimmed-text) "")
(if (masto/append-screen-name? mastodon-config) (if (masto/append-screen-name? mastodon-config)
(str "\n - " screen_name) "")) (str "\n - " screen_name) ""))
(masto/max-post-length mastodon-config))
:media-links media-links})) :media-links media-links}))

View file

@ -47,6 +47,7 @@
{:keys [screen_name]} :user :as tweet}] {:keys [screen_name]} :user :as tweet}]
{:created-at (js/Date. created-at) {:created-at (js/Date. created-at)
:text (chop-tail-media-url text media) :text (chop-tail-media-url text media)
:screen_name screen_name
:media-links (keep #(when (= (:type %) "photo") (:media_url_https %)) media)}) :media-links (keep #(when (= (:type %) "photo") (:media_url_https %)) media)})
(defn-spec user-timeline any? (defn-spec user-timeline any?