'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.
master
Arnout Engelen 4 years ago
parent 56e79a1e8c
commit a3b51d1e5c
No known key found for this signature in database
GPG Key ID: 061107B0F74A6DAA

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