Only notify for mention if it is not in a comment
To avoid two similar notifications
This commit is contained in:
parent
b53a078b49
commit
0f5f9101b6
|
@ -109,8 +109,11 @@ impl FromActivity<Note, PgConnection> for Comment {
|
|||
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, comm.id, false))
|
||||
.ok();
|
||||
.map(|m| {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ impl 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 mentioned = User::find_by_ap_url(conn, ap_url)?;
|
||||
|
||||
|
@ -81,7 +81,9 @@ impl Mention {
|
|||
comment_id: None,
|
||||
ap_url: ment.link_props.href_string().unwrap_or(String::new())
|
||||
});
|
||||
res.notify(conn);
|
||||
if notify {
|
||||
res.notify(conn);
|
||||
}
|
||||
res
|
||||
})
|
||||
} else {
|
||||
|
@ -92,7 +94,9 @@ impl Mention {
|
|||
comment_id: Some(comment.id),
|
||||
ap_url: ment.link_props.href_string().unwrap_or(String::new())
|
||||
});
|
||||
res.notify(conn);
|
||||
if notify {
|
||||
res.notify(conn);
|
||||
}
|
||||
res
|
||||
})
|
||||
}
|
||||
|
|
|
@ -372,7 +372,7 @@ impl FromActivity<Article, PgConnection> for Post {
|
|||
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.clone())
|
||||
.map(|m| Mention::from_activity(conn, m, post.id, true))
|
||||
.map(|m| Mention::from_activity(conn, m, post.id, true, true))
|
||||
.ok();
|
||||
|
||||
serde_json::from_value::<Hashtag>(tag.clone())
|
||||
|
|
|
@ -179,7 +179,7 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor
|
|||
let post = post.update_ap_url(&*conn);
|
||||
|
||||
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<_>>();
|
||||
|
@ -278,7 +278,7 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
|
|||
});
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue