Skip to content

Commit

Permalink
delete notification on user deletion
Browse files Browse the repository at this point in the history
fix #651
  • Loading branch information
trinity-1686a committed Aug 27, 2019
1 parent 935d331 commit 4b640ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plume-models/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ impl Notification {
.map_err(Error::from)
}

pub fn find_followed_by(conn: &Connection, user: &User) -> Result<Vec<Notification>> {
notifications::table
.filter(notifications::kind.eq(notification_kind::FOLLOW))
.filter(notifications::object_id.eq(user.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))
Expand All @@ -72,6 +80,7 @@ impl Notification {
.map_err(Error::from)
}


pub fn page_for_user(
conn: &Connection,
user: &User,
Expand Down
5 changes: 5 additions & 0 deletions plume-models/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use db_conn::DbConn;
use follows::Follow;
use instance::*;
use medias::Media;
use notifications::Notification;
use post_authors::PostAuthor;
use posts::Post;
use safe_string::SafeString;
Expand Down Expand Up @@ -178,6 +179,10 @@ impl User {
}
}

for notif in Notification::find_followed_by(conn, self)? {
notif.delete(conn)?
}

diesel::delete(self)
.execute(conn)
.map(|_| ())
Expand Down

0 comments on commit 4b640ee

Please sign in to comment.