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:
committed by
Baptiste Gelez
parent
f0d6b9d1e8
commit
c7ee779f51
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user