Save mentions
This commit is contained in:
@@ -33,6 +33,7 @@ impl Mention {
|
||||
get!(mentions);
|
||||
find_by!(mentions, find_by_ap_url, ap_url as String);
|
||||
list_by!(mentions, list_for_user, mentioned_id as i32);
|
||||
list_by!(mentions, list_for_post, post_id as i32);
|
||||
|
||||
pub fn get_mentioned(&self, conn: &PgConnection) -> Option<User> {
|
||||
User::get(conn, self.mentioned_id)
|
||||
@@ -46,6 +47,14 @@ impl Mention {
|
||||
self.post_id.and_then(|id| Comment::get(conn, id))
|
||||
}
|
||||
|
||||
pub fn build_activity(conn: &PgConnection, ment: String) -> link::Mention {
|
||||
let user = User::find_by_fqn(conn, ment.clone());
|
||||
let mut mention = link::Mention::default();
|
||||
mention.link_props.set_href_string(user.clone().map(|u| u.ap_url).unwrap_or(String::new())).expect("Error setting mention's href");
|
||||
mention.link_props.set_name_string(format!("@{}", ment)).expect("Error setting mention's name");
|
||||
mention
|
||||
}
|
||||
|
||||
pub fn to_activity(&self, conn: &PgConnection) -> link::Mention {
|
||||
let user = self.get_mentioned(conn);
|
||||
let mut mention = link::Mention::default();
|
||||
|
||||
+4
-2
@@ -145,6 +145,8 @@ impl Post {
|
||||
let mut to = self.get_receivers_urls(conn);
|
||||
to.push(PUBLIC_VISIBILTY.to_string());
|
||||
|
||||
let mentions = Mention::list_for_post(conn, self.id).into_iter().map(|m| m.to_activity(conn)).collect::<Vec<link::Mention>>();
|
||||
|
||||
let mut article = Article::default();
|
||||
article.object_props = ObjectProperties {
|
||||
name: Some(serde_json::to_value(self.title.clone()).unwrap()),
|
||||
@@ -152,11 +154,11 @@ impl Post {
|
||||
attributed_to: Some(serde_json::to_value(self.get_authors(conn).into_iter().map(|x| x.ap_url).collect::<Vec<String>>()).unwrap()),
|
||||
content: Some(serde_json::to_value(self.content.clone()).unwrap()),
|
||||
published: Some(serde_json::to_value(self.creation_date).unwrap()),
|
||||
tag: Some(serde_json::to_value(Vec::<serde_json::Value>::new()).unwrap()),
|
||||
tag: Some(serde_json::to_value(mentions).unwrap()),
|
||||
url: Some(serde_json::to_value(self.compute_id(conn)).unwrap()),
|
||||
to: Some(serde_json::to_value(to).unwrap()),
|
||||
cc: Some(serde_json::to_value(Vec::<serde_json::Value>::new()).unwrap()),
|
||||
..ObjectProperties::default()
|
||||
..ObjectProperties::default()
|
||||
};
|
||||
article
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user