Only notify for mention if it is not in a comment

To avoid two similar notifications
This commit is contained in:
Bat 2018-09-08 12:52:27 +01:00
parent b53a078b49
commit 0f5f9101b6
4 changed files with 15 additions and 8 deletions

View File

@ -109,8 +109,11 @@ impl FromActivity<Note, PgConnection> for Comment {
if let Some(serde_json::Value::Array(tags)) = note.object_props.tag.clone() { if let Some(serde_json::Value::Array(tags)) = note.object_props.tag.clone() {
for tag in tags.into_iter() { for tag in tags.into_iter() {
serde_json::from_value::<link::Mention>(tag) serde_json::from_value::<link::Mention>(tag)
.map(|m| Mention::from_activity(conn, m, comm.id, false)) .map(|m| {
.ok(); let author = &Post::get(conn, comm.post_id).unwrap().get_authors(conn)[0];
let not_author = m.link_props.href_string().expect("Comment mention: no href") != author.ap_url.clone();
Mention::from_activity(conn, m, comm.id, false, not_author)
}).ok();
} }
} }

View File

@ -69,7 +69,7 @@ impl Mention {
mention mention
} }
pub fn from_activity(conn: &PgConnection, ment: link::Mention, inside: i32, in_post: bool) -> Option<Self> { pub fn from_activity(conn: &PgConnection, ment: link::Mention, inside: i32, in_post: bool, notify: bool) -> Option<Self> {
let ap_url = ment.link_props.href_string().ok()?; let ap_url = ment.link_props.href_string().ok()?;
let mentioned = User::find_by_ap_url(conn, ap_url)?; let mentioned = User::find_by_ap_url(conn, ap_url)?;
@ -81,7 +81,9 @@ impl Mention {
comment_id: None, comment_id: None,
ap_url: ment.link_props.href_string().unwrap_or(String::new()) ap_url: ment.link_props.href_string().unwrap_or(String::new())
}); });
res.notify(conn); if notify {
res.notify(conn);
}
res res
}) })
} else { } else {
@ -92,7 +94,9 @@ impl Mention {
comment_id: Some(comment.id), comment_id: Some(comment.id),
ap_url: ment.link_props.href_string().unwrap_or(String::new()) ap_url: ment.link_props.href_string().unwrap_or(String::new())
}); });
res.notify(conn); if notify {
res.notify(conn);
}
res res
}) })
} }

View File

@ -372,7 +372,7 @@ impl FromActivity<Article, PgConnection> for Post {
if let Some(serde_json::Value::Array(tags)) = article.object_props.tag.clone() { if let Some(serde_json::Value::Array(tags)) = article.object_props.tag.clone() {
for tag in tags.into_iter() { for tag in tags.into_iter() {
serde_json::from_value::<link::Mention>(tag.clone()) serde_json::from_value::<link::Mention>(tag.clone())
.map(|m| Mention::from_activity(conn, m, post.id, true)) .map(|m| Mention::from_activity(conn, m, post.id, true, true))
.ok(); .ok();
serde_json::from_value::<Hashtag>(tag.clone()) serde_json::from_value::<Hashtag>(tag.clone())

View File

@ -179,7 +179,7 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor
let post = post.update_ap_url(&*conn); let post = post.update_ap_url(&*conn);
for m in mentions.into_iter() { for m in mentions.into_iter() {
Mention::from_activity(&*conn, Mention::build_activity(&*conn, m), post.id, true); Mention::from_activity(&*conn, Mention::build_activity(&*conn, m), post.id, true, true);
} }
let old_tags = Tag::for_post(&*conn, post.id).into_iter().map(|t| t.tag).collect::<Vec<_>>(); let old_tags = Tag::for_post(&*conn, post.id).into_iter().map(|t| t.tag).collect::<Vec<_>>();
@ -278,7 +278,7 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
}); });
for m in mentions.into_iter() { for m in mentions.into_iter() {
Mention::from_activity(&*conn, Mention::build_activity(&*conn, m), post.id, true); Mention::from_activity(&*conn, Mention::build_activity(&*conn, m), post.id, true, true);
} }
let tags = form.tags.split(",").map(|t| t.trim().to_camel_case()).filter(|t| t.len() > 0); let tags = form.tags.split(",").map(|t| t.trim().to_camel_case()).filter(|t| t.len() > 0);