Save incoming mentions

This commit is contained in:
Bat 2018-06-20 20:42:16 +01:00
parent 215b577573
commit c9f29955a0
3 changed files with 23 additions and 2 deletions

View File

@ -1,5 +1,6 @@
use activitypub::{ use activitypub::{
activity::Create, activity::Create,
link,
object::{Note, properties::ObjectProperties} object::{Note, properties::ObjectProperties}
}; };
use chrono; use chrono;
@ -13,6 +14,7 @@ use activity_pub::{
}; };
use models::{ use models::{
instance::Instance, instance::Instance,
mentions::Mention,
notifications::*, notifications::*,
posts::Post, posts::Post,
users::User users::User
@ -114,6 +116,16 @@ impl FromActivity<Note> for Comment {
fn from_activity(conn: &PgConnection, note: Note, actor: Id) -> 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_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()); 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::<link::Mention>(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 { let comm = Comment::insert(conn, NewComment {
content: SafeString::new(&note.object_props.content_string().unwrap()), content: SafeString::new(&note.object_props.content_string().unwrap()),
spoiler_text: note.object_props.summary_string().unwrap_or(String::from("")), spoiler_text: note.object_props.summary_string().unwrap_or(String::from("")),

View File

@ -72,4 +72,3 @@ impl Mention {
} }
} }
} }

View File

@ -1,5 +1,6 @@
use activitypub::{ use activitypub::{
activity::Create, activity::Create,
link,
object::{Article, properties::ObjectProperties} object::{Article, properties::ObjectProperties}
}; };
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
@ -9,13 +10,13 @@ use serde_json;
use BASE_URL; use BASE_URL;
use activity_pub::{ use activity_pub::{
PUBLIC_VISIBILTY, ap_url, Id, IntoId, PUBLIC_VISIBILTY, ap_url, Id, IntoId,
actor::Actor,
inbox::FromActivity inbox::FromActivity
}; };
use models::{ use models::{
blogs::Blog, blogs::Blog,
instance::Instance, instance::Instance,
likes::Like, likes::Like,
mentions::Mention,
post_authors::PostAuthor, post_authors::PostAuthor,
reshares::Reshare, reshares::Reshare,
users::User users::User
@ -184,6 +185,15 @@ impl Post {
impl FromActivity<Article> for Post { impl FromActivity<Article> for Post {
fn from_activity(conn: &PgConnection, article: Article, _actor: Id) -> 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::<link::Mention>(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 { Post::insert(conn, NewPost {
blog_id: 0, // TODO blog_id: 0, // TODO
slug: String::from(""), // TODO slug: String::from(""), // TODO