|
|
|
@ -1,7 +1,17 @@
|
|
|
|
|
use crate::{
|
|
|
|
|
ap_url, blogs::Blog, instance::Instance, medias::Media, mentions::Mention, post_authors::*,
|
|
|
|
|
safe_string::SafeString, schema::posts, search::Searcher, search::UpdateDocument, tags::*,
|
|
|
|
|
timeline::*, users::User, Connection, Error, PlumeRocket, Result, CONFIG,
|
|
|
|
|
ap_url,
|
|
|
|
|
blogs::Blog,
|
|
|
|
|
instance::Instance,
|
|
|
|
|
medias::Media,
|
|
|
|
|
mentions::Mention,
|
|
|
|
|
post_authors::*,
|
|
|
|
|
safe_string::SafeString,
|
|
|
|
|
schema::posts,
|
|
|
|
|
search::{AddDocument, Searcher, UpdateDocument, PostEvent::*},
|
|
|
|
|
tags::*,
|
|
|
|
|
timeline::*,
|
|
|
|
|
users::User,
|
|
|
|
|
Connection, Error, PlumeRocket, Result, ACTORS, CONFIG,
|
|
|
|
|
};
|
|
|
|
|
use activitypub::{
|
|
|
|
|
activity::{Create, Delete, Update},
|
|
|
|
@ -65,7 +75,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<Self> {
|
|
|
|
|
pub fn insert(conn: &Connection, new: NewPost) -> Result<Self> {
|
|
|
|
|
diesel::insert_into(posts::table)
|
|
|
|
|
.values(new)
|
|
|
|
|
.execute(conn)?;
|
|
|
|
@ -80,13 +90,22 @@ impl Post {
|
|
|
|
|
let _: Post = post.save_changes(conn)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searcher.add_document(&post)?;
|
|
|
|
|
if post.published {
|
|
|
|
|
let searcher_actor = ACTORS.get().unwrap().clone().select("/plume/user/searcher-actor").unwrap();
|
|
|
|
|
searcher_actor.try_tell(AddDocument(post.clone()), None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(post)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update(&self, conn: &Connection) -> Result<Self> {
|
|
|
|
|
diesel::update(self).set(self).execute(conn)?;
|
|
|
|
|
let post = Self::get(conn, self.id)?;
|
|
|
|
|
|
|
|
|
|
if post.published {
|
|
|
|
|
crate::POST_CHAN.get().unwrap().tell(Publish { msg: PostUpdated(post.clone()), topic: "post.updated".into() }, None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(post)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -561,7 +580,6 @@ impl FromId<PlumeRocket> for Post {
|
|
|
|
|
|
|
|
|
|
fn from_activity(c: &PlumeRocket, article: LicensedArticle) -> Result<Self> {
|
|
|
|
|
let conn = &*c.conn;
|
|
|
|
|
let searcher = &c.searcher;
|
|
|
|
|
let license = article.custom_props.license_string().unwrap_or_default();
|
|
|
|
|
let article = article.object;
|
|
|
|
|
|
|
|
|
@ -606,7 +624,6 @@ impl FromId<PlumeRocket> for Post {
|
|
|
|
|
source: article.ap_object_props.source_object::<Source>()?.content,
|
|
|
|
|
cover_id: cover,
|
|
|
|
|
},
|
|
|
|
|
searcher,
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
for author in authors {
|
|
|
|
@ -648,6 +665,9 @@ impl FromId<PlumeRocket> for Post {
|
|
|
|
|
|
|
|
|
|
Timeline::add_to_all_timelines(c, &post, Kind::Original)?;
|
|
|
|
|
|
|
|
|
|
let searcher_actor = ACTORS.get().unwrap().clone().select("/plume/user/searcher-actor").unwrap();
|
|
|
|
|
searcher_actor.try_tell(AddDocument(post.clone()), None);
|
|
|
|
|
|
|
|
|
|
Ok(post)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -729,7 +749,7 @@ impl AsObject<User, Update, &PlumeRocket> for PostUpdate {
|
|
|
|
|
|
|
|
|
|
fn activity(self, c: &PlumeRocket, actor: User, _id: &str) -> Result<()> {
|
|
|
|
|
let conn = &*c.conn;
|
|
|
|
|
let searcher_actor = &c.actors.select("searcher-actor").unwrap();
|
|
|
|
|
let searcher_actor = ACTORS.get().unwrap().clone().select("/plume/user/searcher-actor").unwrap();
|
|
|
|
|
let mut post = Post::from_id(c, &self.ap_url, None).map_err(|(_, e)| e)?;
|
|
|
|
|
|
|
|
|
|
if !post.is_author(conn, actor.id)? {
|
|
|
|
@ -835,7 +855,6 @@ mod tests {
|
|
|
|
|
source: "Hello".into(),
|
|
|
|
|
cover_id: None,
|
|
|
|
|
},
|
|
|
|
|
&r.searcher,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
PostAuthor::insert(
|
|
|
|
|