Delete notifications when deleting comments (#499)

* Implement find_for_comment for notifications

* Delete notifications when deleting a comment

This should tackle #463

* Apply rustfmt

* Implement `find_for_mention` and remove order by from `find_for_comment`

There is no need to order the notifications

* Delete notifications for mentions

* Fix notifications for comments and mentions
This commit is contained in:
Valentin Brandl
2019-03-26 12:45:17 +01:00
committed by Baptiste Gelez
parent f0d6b9d1e8
commit c7ee779f51
4 changed files with 58 additions and 23 deletions
+16
View File
@@ -48,6 +48,22 @@ impl Notification {
.map_err(Error::from)
}
pub fn find_for_mention(conn: &Connection, mention: &Mention) -> Result<Vec<Notification>> {
notifications::table
.filter(notifications::kind.eq(notification_kind::MENTION))
.filter(notifications::object_id.eq(mention.id))
.load::<Notification>(conn)
.map_err(Error::from)
}
pub fn find_for_comment(conn: &Connection, comment: &Comment) -> Result<Vec<Notification>> {
notifications::table
.filter(notifications::kind.eq(notification_kind::COMMENT))
.filter(notifications::object_id.eq(comment.id))
.load::<Notification>(conn)
.map_err(Error::from)
}
pub fn count_for_user(conn: &Connection, user: &User) -> Result<i64> {
notifications::table
.filter(notifications::user_id.eq(user.id))