delete notification on user deletion (#658)
* delete notification on user deletion fix #651 * use the correct id for deletion * add regression test * push helpers too * revert CI changes
This commit is contained in:
parent
d4a1bd6de7
commit
12c80f9981
|
@ -1,5 +1,5 @@
|
|||
use chrono::NaiveDateTime;
|
||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
use diesel::{self, ExpressionMethods, JoinOnDsl, QueryDsl, RunQueryDsl};
|
||||
|
||||
use comments::Comment;
|
||||
use follows::Follow;
|
||||
|
@ -7,7 +7,7 @@ use likes::Like;
|
|||
use mentions::Mention;
|
||||
use posts::Post;
|
||||
use reshares::Reshare;
|
||||
use schema::notifications;
|
||||
use schema::{follows, notifications};
|
||||
use users::User;
|
||||
use {Connection, Error, Result};
|
||||
|
||||
|
@ -64,6 +64,16 @@ impl Notification {
|
|||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
pub fn find_followed_by(conn: &Connection, user: &User) -> Result<Vec<Notification>> {
|
||||
notifications::table
|
||||
.inner_join(follows::table.on(notifications::object_id.eq(follows::id)))
|
||||
.filter(notifications::kind.eq(notification_kind::FOLLOW))
|
||||
.filter(follows::follower_id.eq(user.id))
|
||||
.select(notifications::all_columns)
|
||||
.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))
|
||||
|
|
|
@ -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;
|
||||
|
@ -147,6 +148,10 @@ impl User {
|
|||
}
|
||||
}
|
||||
|
||||
for notif in Notification::find_followed_by(conn, self)? {
|
||||
notif.delete(conn)?
|
||||
}
|
||||
|
||||
diesel::delete(self)
|
||||
.execute(conn)
|
||||
.map(|_| ())
|
||||
|
|
Loading…
Reference in New Issue