Only notify for mention if it is not in a comment
To avoid two similar notifications
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user