From c9f29955a0efc2add075a60e4895c8e3d014225d Mon Sep 17 00:00:00 2001 From: Bat Date: Wed, 20 Jun 2018 20:42:16 +0100 Subject: [PATCH] Save incoming mentions --- src/models/comments.rs | 12 ++++++++++++ src/models/mentions.rs | 1 - src/models/posts.rs | 12 +++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/models/comments.rs b/src/models/comments.rs index 5926170a..988ce3af 100644 --- a/src/models/comments.rs +++ b/src/models/comments.rs @@ -1,5 +1,6 @@ use activitypub::{ activity::Create, + link, object::{Note, properties::ObjectProperties} }; use chrono; @@ -13,6 +14,7 @@ use activity_pub::{ }; use models::{ instance::Instance, + mentions::Mention, notifications::*, posts::Post, users::User @@ -114,6 +116,16 @@ impl FromActivity for Comment { fn from_activity(conn: &PgConnection, note: Note, actor: Id) -> Comment { let previous_url = note.object_props.in_reply_to.clone().unwrap().as_str().unwrap().to_string(); let previous_comment = Comment::find_by_ap_url(conn, previous_url.clone()); + + // save mentions + if let Some(serde_json::Value::Array(tags)) = note.object_props.tag.clone() { + for tag in tags.into_iter() { + serde_json::from_value::(tag) + .map(|m| Mention::from_activity(conn, m, Id::new(note.clone().object_props.clone().url_string().unwrap_or(String::from(""))))) + .ok(); + } + } + let comm = Comment::insert(conn, NewComment { content: SafeString::new(¬e.object_props.content_string().unwrap()), spoiler_text: note.object_props.summary_string().unwrap_or(String::from("")), diff --git a/src/models/mentions.rs b/src/models/mentions.rs index 934618fa..f43a76f4 100644 --- a/src/models/mentions.rs +++ b/src/models/mentions.rs @@ -72,4 +72,3 @@ impl Mention { } } } - diff --git a/src/models/posts.rs b/src/models/posts.rs index b0915a63..f4a6408f 100644 --- a/src/models/posts.rs +++ b/src/models/posts.rs @@ -1,5 +1,6 @@ use activitypub::{ activity::Create, + link, object::{Article, properties::ObjectProperties} }; use chrono::NaiveDateTime; @@ -9,13 +10,13 @@ use serde_json; use BASE_URL; use activity_pub::{ PUBLIC_VISIBILTY, ap_url, Id, IntoId, - actor::Actor, inbox::FromActivity }; use models::{ blogs::Blog, instance::Instance, likes::Like, + mentions::Mention, post_authors::PostAuthor, reshares::Reshare, users::User @@ -184,6 +185,15 @@ impl Post { impl FromActivity
for Post { fn from_activity(conn: &PgConnection, article: Article, _actor: Id) -> Post { + // save mentions + if let Some(serde_json::Value::Array(tags)) = article.object_props.tag.clone() { + for tag in tags.into_iter() { + serde_json::from_value::(tag) + .map(|m| Mention::from_activity(conn, m, Id::new(article.clone().object_props.clone().url_string().unwrap_or(String::from(""))))) + .ok(); + } + } + Post::insert(conn, NewPost { blog_id: 0, // TODO slug: String::from(""), // TODO