about summary refs log tree commit diff
path: root/kittybox-rs/src/database/mod.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2023-06-22 22:18:24 +0300
committerVika <vika@fireburn.ru>2023-06-22 22:18:24 +0300
commitbf499c9351cdfa88002cc7eaf2f695b0683efa5b (patch)
tree72419f8f201fcb9330c4dce81e075be1e8561ba9 /kittybox-rs/src/database/mod.rs
parent858c0ddd9cc36af0acc72efb1ff1bdc1d8e28b0a (diff)
downloadkittybox-bf499c9351cdfa88002cc7eaf2f695b0683efa5b.tar.zst
database: add add_to_feed and remove_from_feed
Some database backends may have optimized ways of tracking feed
contents. Others might just use the "children" property directly.
Diffstat (limited to 'kittybox-rs/src/database/mod.rs')
-rw-r--r--kittybox-rs/src/database/mod.rs8
1 files changed, 8 insertions, 0 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