'perform-replacements' after 'resolve-urls'

This simplifies things overall, and avoids resolve-urls replacing mentions like
'@foo@bar.org' with links to the 'about' page of the instance.

Unfortunately this wasn't easy to add a test for.
This commit is contained in:
Arnout Engelen 2020-05-06 10:20:55 +02:00
parent 56e79a1e8c
commit a3b51d1e5c
No known key found for this signature in database
GPG key ID: 061107B0F74A6DAA

View file

@ -92,6 +92,9 @@
(:nitter-urls? mastodon-config)
(string/replace #"https://twitter.com" "https://nitter.net")))
(defn perform-replacements [text]
(reduce-kv string/replace text (:replacements mastodon-config)))
(defn set-signature [text]
(if-let [signature (:signature mastodon-config )]
(str text "\n" signature)
@ -103,7 +106,7 @@
([status-text media-ids]
(let [{:keys [sensitive? signature visibility]} mastodon-config]
(.post mastodon-client "statuses"
(clj->js (merge {:status (-> status-text resolve-urls set-signature)}
(clj->js (merge {:status (-> status-text resolve-urls perform-replacements set-signature)}
(when media-ids {:media_ids media-ids})
(when sensitive? {:sensitive sensitive?})
(when visibility {:visibility visibility})))))))
@ -131,15 +134,10 @@
(exit-with-error error)
(callback response)))))
(defn perform-replacements [post]
(assoc post :text (reduce-kv string/replace (:text post) (:replacements mastodon-config)))
)
(defn post-items [last-post-time items]
(doseq [{:keys [text media-links]} (->> items
(remove #(blocked-content? (:text %)))
(filter #(> (:created-at %) last-post-time))
(map perform-replacements))]
(filter #(> (:created-at %) last-post-time)))]
(if media-links
(post-status-with-images text media-links)
(when-not (:media-only? mastodon-config)