From aae2073146bf20fdd7de652d5ba0212f501f778e Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 7 Jan 2021 22:34:11 +0900 Subject: [PATCH] Send event to channel when post updated --- plume-models/src/posts.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 576e1a1b..9045839d 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -85,10 +85,11 @@ impl Post { Ok(post) } - pub fn update(&self, conn: &Connection, searcher: &Searcher) -> Result { + pub fn update(&self, conn: &Connection, _searcher: &Searcher) -> Result { diesel::update(self).set(self).execute(conn)?; let post = Self::get(conn, self.id)?; - searcher.update_document(conn, &post)?; + // TODO: Call publish_published() when newly published + self.publish_updated(); Ok(post) } @@ -559,6 +560,16 @@ impl Post { None, ) } + + fn publish_updated(&self) { + POST_CHAN.tell( + Publish { + msg: PostUpdated(self.clone()), + topic: "post.updated".into(), + }, + None, + ) + } } impl FromId for Post {