Send event to channel when post deleted

This commit is contained in:
Kitaiti Makoto 2021-01-07 22:41:48 +09:00
parent 82524c9dca
commit 2a8cc5f3ba

View File

@ -93,12 +93,12 @@ impl Post {
Ok(post) Ok(post)
} }
pub fn delete(&self, conn: &Connection, searcher: &Searcher) -> Result<()> { pub fn delete(&self, conn: &Connection, _searcher: &Searcher) -> Result<()> {
for m in Mention::list_for_post(&conn, self.id)? { for m in Mention::list_for_post(&conn, self.id)? {
m.delete(conn)?; m.delete(conn)?;
} }
diesel::delete(self).execute(conn)?; diesel::delete(self).execute(conn)?;
searcher.delete_document(self); self.publish_deleted();
Ok(()) Ok(())
} }
@ -570,6 +570,16 @@ impl Post {
None, None,
) )
} }
fn publish_deleted(&self) {
POST_CHAN.tell(
Publish {
msg: PostDeleted(self.clone()),
topic: "post.deleted".into(),
},
None,
)
}
} }
impl FromId<PlumeRocket> for Post { impl FromId<PlumeRocket> for Post {