Merge pull request #41 from raboof/replace-after-resolving-urls

'perform-replacements' after 'resolve-urls'
This commit is contained in:
Dmitri Sotnikov 2020-05-06 13:42:21 -04:00 committed by GitHub
commit 3a4d7b49c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)