summaryrefslogtreecommitdiff
path: root/src/weepinbell
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-03-05 17:20:43 +0800
committereltrac <hi@eltr.ac>2026-03-05 17:20:43 +0800
commit565a2aee3cd557909d171ddea27a97b96e72c8fe (patch)
treed325873137f04ded9b5a13c80da72a588f92ba1f /src/weepinbell
parentc64931cf361bf02fa00792ef7d82cf0e79add7a1 (diff)
feat: UNFINISHED handle Webmention editing, deleting and appending
the storage part was unfinished and unserviceable.
Diffstat (limited to 'src/weepinbell')
-rw-r--r--src/weepinbell/processor.clj20
-rw-r--r--src/weepinbell/storage.clj34
2 files changed, 41 insertions, 13 deletions
diff --git a/src/weepinbell/processor.clj b/src/weepinbell/processor.clj
index 33d3900..c8a4f73 100644
--- a/src/weepinbell/processor.clj
+++ b/src/weepinbell/processor.clj
@@ -32,7 +32,7 @@
:wm-target target
:wm-id nil})
-(defn process-verified-webmention
+(defn process-new-webmention
"If a webmention is verified, fetch microformats data and store it."
[source target]
;; log
@@ -43,6 +43,14 @@
(let [data (wrap-webmention source target)]
(storage/append data)))
+(defn process-existing-webmention
+ "Update existing Webmention when verified, delete it otherwise."
+ [verified? source target]
+ (if verified?
+ (storage/update-wm source target
+ (wrap-webmention source target))
+ (storage/delete-wm source target)))
+
(defn process-webmention
"Retrieve webmention from queue and process it."
[wmc]
@@ -50,10 +58,12 @@
(go-loop []
(when-let [wm (<! wmc)]
(println "Webmention found in queue.")
- (let [{:keys [s t]} wm]
- (if (verify-mention s t)
- (process-verified-webmention s t)
- (println "Invalid mention")))
+ (let [{:keys [s t]} wm
+ verified? (verify-mention s t)]
+ ;; handle existing webmention and new webmention differently
+ (if (storage/get-wm s t)
+ (process-existing-webmention verified? s t)
+ (when verified? (process-new-webmention s t))))
(println "Idling"))
(recur)))
diff --git a/src/weepinbell/storage.clj b/src/weepinbell/storage.clj
index b96da34..ee8b6f5 100644
--- a/src/weepinbell/storage.clj
+++ b/src/weepinbell/storage.clj
@@ -14,19 +14,37 @@
[data]
(spit data-file (pr-str data)))
+(defn get-wm
+ "Get an existing Webmention by source and target."
+ [source target]
+ (let [data (load-data)
+ pred #(and (= source (:wm-source %))
+ (= target (:wm-target %)))]
+ (first (filter pred data))))
+
+(defn with-this-wm
+ "Do something with this Webmention (identified by source and target)."
+ [source target do-something-with]
+ (when-let [this-wm (get-wm source target)]
+ (do-something-with this-wm)))
+
(defn append
"Append an accepted webmention to .edn data file."
[data]
(spit data-file (pr-str data) :append true))
-(defn delete
+(defn update-wm
+ "Update an existing webmention"
+ [source target new-data]
+ #_(todo))
+
+(defn delete-wm
"Delete a Webmention entry by source and target."
[source target]
- (let [data (load-data)
- pred #(and (= source (:wm-source %))
- (= target (:wm-target %)))]
- (->> data
- (remove pred)
- vec
- unload-data)))
+ (with-this-wm source target
+ (fn [this-wm]
+ (->> (load-data)
+ (remove #(= this-wm %))
+ vec
+ unload-data))))