|
|
|
@ -1,6 +1,11 @@
|
|
|
|
|
use chrono;
|
|
|
|
|
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
|
|
|
|
|
use serde_json;
|
|
|
|
|
|
|
|
|
|
use activity_pub::{ap_url, PUBLIC_VISIBILTY};
|
|
|
|
|
use activity_pub::actor::Actor;
|
|
|
|
|
use activity_pub::object::Object;
|
|
|
|
|
use models::posts::Post;
|
|
|
|
|
use models::users::User;
|
|
|
|
|
use schema::comments;
|
|
|
|
|
|
|
|
|
@ -62,4 +67,36 @@ impl Comment {
|
|
|
|
|
pub fn get_author(&self, conn: &PgConnection) -> User {
|
|
|
|
|
User::get(conn, self.author_id).unwrap()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_post(&self, conn: &PgConnection) -> Post {
|
|
|
|
|
Post::get(conn, self.post_id).unwrap()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Object for Comment {
|
|
|
|
|
fn serialize(&self, conn: &PgConnection) -> serde_json::Value {
|
|
|
|
|
let mut to = self.get_author(conn).get_followers(conn).into_iter().map(|f| f.ap_url).collect::<Vec<String>>();
|
|
|
|
|
to.append(&mut self.get_post(conn).get_receivers_urls(conn));
|
|
|
|
|
to.push(PUBLIC_VISIBILTY.to_string());
|
|
|
|
|
|
|
|
|
|
json!({
|
|
|
|
|
"id": self.compute_id(conn),
|
|
|
|
|
"type": "Note",
|
|
|
|
|
"summary": self.spoiler_text,
|
|
|
|
|
"content": self.content,
|
|
|
|
|
"inReplyTo": self.in_response_to_id.map_or_else(|| self.get_post(conn).ap_url, |id| {
|
|
|
|
|
let comm = Comment::get(conn, id).unwrap();
|
|
|
|
|
comm.ap_url.clone().unwrap_or(comm.compute_id(conn))
|
|
|
|
|
}),
|
|
|
|
|
"published": self.creation_date,
|
|
|
|
|
"attributedTo": self.get_author(conn).compute_id(conn),
|
|
|
|
|
"to": to,
|
|
|
|
|
"cc": [],
|
|
|
|
|
"sensitive": self.sensitive,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn compute_id(&self, conn: &PgConnection) -> String {
|
|
|
|
|
ap_url(format!("{}#comment-{}", self.get_post(conn).compute_id(conn), self.id))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|