From 6a2ba2260d638777ccf201d89624f0766021735d Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 7 Jan 2021 22:16:51 +0900 Subject: [PATCH] Send event to channel when post published --- plume-models/src/posts.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 2a5c97f2..6c1b37b8 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -1,7 +1,7 @@ use crate::{ ap_url, blogs::Blog, instance::Instance, medias::Media, mentions::Mention, post_authors::*, safe_string::SafeString, schema::posts, search::Searcher, tags::*, timeline::*, users::User, - Connection, Error, PlumeRocket, Result, CONFIG, + Connection, Error, PlumeRocket, PostEvent::*, Result, CONFIG, POST_CHAN, }; use activitypub::{ activity::{Create, Delete, Update}, @@ -19,6 +19,7 @@ use plume_common::{ }, utils::md_to_html, }; +use riker::actors::{Publish, Tell}; use std::collections::HashSet; pub type LicensedArticle = CustomObject; @@ -62,7 +63,7 @@ impl Post { find_by!(posts, find_by_ap_url, ap_url as &str); last!(posts); - pub fn insert(conn: &Connection, new: NewPost, searcher: &Searcher) -> Result { + pub fn insert(conn: &Connection, new: NewPost, _searcher: &Searcher) -> Result { diesel::insert_into(posts::table) .values(new) .execute(conn)?; @@ -77,7 +78,10 @@ impl Post { let _: Post = post.save_changes(conn)?; } - searcher.add_document(conn, &post)?; + if post.published { + post.publish_published(); + } + Ok(post) } @@ -545,6 +549,16 @@ impl Post { .set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY)])?; Ok(act) } + + fn publish_published(&self) { + POST_CHAN.tell( + Publish { + msg: PostPublished(self.clone()), + topic: "post.published".into(), + }, + None, + ) + } } impl FromId for Post {