about summary refs log tree commit diff
path: root/kittybox-rs
diff options
context:
space:
mode:
Diffstat (limited to 'kittybox-rs')
-rw-r--r--kittybox-rs/src/database/mod.rs8
-rw-r--r--kittybox-rs/src/micropub/mod.rs3
2 files changed, 9 insertions, 2 deletions
diff --git a/kittybox-rs/src/database/mod.rs b/kittybox-rs/src/database/mod.rs
index aa675d3..cb4c0b9 100644
--- a/kittybox-rs/src/database/mod.rs
+++ b/kittybox-rs/src/database/mod.rs
@@ -293,6 +293,14 @@ pub trait Storage: std::fmt::Debug + Clone + Send + Sync {
     /// Note that the `post` object MUST have `post["properties"]["uid"][0]` defined.
     async fn put_post(&self, post: &'_ serde_json::Value, user: &'_ str) -> Result<()>;
 
+    /// Add post to feed. Some database implementations might have optimized ways to do this.
+    async fn add_to_feed(&self, feed: &'_ str, post: &'_ str) -> Result<()> {
+        self.update_post(feed, serde_json::json!({"add": {"children": [post]}})).await
+    }
+    async fn remove_from_feed(&self, feed: &'_ str, post: &'_ str) -> Result<()> {
+        self.update_post(feed, serde_json::json!({"delete": {"children": [post]}})).await
+    }
+
     /// Modify a post using an update object as defined in the Micropub spec.
     ///
     /// Note to implementors: the update operation MUST be atomic and
diff --git a/kittybox-rs/src/micropub/mod.rs b/kittybox-rs/src/micropub/mod.rs
index 5c297f9..da9c6a5 100644
--- a/kittybox-rs/src/micropub/mod.rs
+++ b/kittybox-rs/src/micropub/mod.rs
@@ -294,8 +294,7 @@ pub(crate) async fn _post<D: 'static + Storage>(
 
     for chan in &mut channels {
         if db.post_exists(chan).await? {
-            db.update_post(chan, json!({"add": {"children": [uid]}}))
-                .await?;
+            db.add_to_feed(chan, &uid).await?;
         } else if default_channels.iter().any(|i| chan == i) {
             util::create_feed(&db, &uid, chan, user).await?;
         } else {