Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete notification on user deletion #658

Merged
merged 5 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 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))
elegaanz marked this conversation as resolved.
Show resolved Hide resolved
.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 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