Prevent duplication of mention on post update
and delete mentions and notifications of user no longer mentioned
This commit is contained in:
parent
1689813df4
commit
2523f3b523
@ -102,6 +102,12 @@ impl Mention {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete(&self, conn: &Connection) {
|
||||
//find related notifications and delete them
|
||||
Notification::find(conn, notification_kind::MENTION, self.id).map(|n| n.delete(conn));
|
||||
diesel::delete(self).execute(conn).expect("Mention::delete: mention deletion error");
|
||||
}
|
||||
}
|
||||
|
||||
impl Notify<Connection> for Mention {
|
||||
|
@ -106,4 +106,8 @@ impl Notification {
|
||||
});
|
||||
json
|
||||
}
|
||||
|
||||
pub fn delete(&self, conn: &Connection) {
|
||||
diesel::delete(self).execute(conn).expect("Notification::delete: notification deletion error");
|
||||
}
|
||||
}
|
||||
|
@ -210,8 +210,15 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor
|
||||
let post = post.update_ap_url(&*conn);
|
||||
|
||||
if post.published {
|
||||
for m in mentions.into_iter() {
|
||||
Mention::from_activity(&*conn, Mention::build_activity(&*conn, m), post.id, true, true);
|
||||
let old_mentions = Mention::list_for_post(&conn, post.id);
|
||||
let old_user_mentioned = old_mentions.iter()
|
||||
.filter_map(|m| User::get(&conn, m.mentioned_id).map(|u| u.get_fqn(&conn)))
|
||||
.collect::<HashSet<_>>();
|
||||
for m in mentions.difference(&old_user_mentioned).into_iter() {
|
||||
Mention::from_activity(&*conn, Mention::build_activity(&*conn, m.clone()), post.id, true, true);
|
||||
}
|
||||
for m in old_mentions.iter().filter(|m| !User::get(&conn, m.mentioned_id).map(|u| mentions.contains(&u.get_fqn(&conn))).unwrap_or(false)) {
|
||||
m.delete(&conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user