Improve notification management (#561)

* Don't notify for comment when mentioned

fix #505

* Don't save notification for remote users

fix #472
This commit is contained in:
fdb-hiroshima 2019-05-04 17:15:41 +02:00 committed by GitHub
parent 918bda14ec
commit c9070930d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 46 deletions

View File

@ -15,7 +15,7 @@ use medias::Media;
use mentions::Mention; use mentions::Mention;
use notifications::*; use notifications::*;
use plume_common::activity_pub::{ use plume_common::activity_pub::{
inbox::{AsObject, FromId}, inbox::{AsActor, AsObject, FromId},
Id, IntoId, PUBLIC_VISIBILITY, Id, IntoId, PUBLIC_VISIBILITY,
}; };
use plume_common::utils; use plume_common::utils;
@ -157,6 +157,11 @@ impl Comment {
pub fn notify(&self, conn: &Connection) -> Result<()> { pub fn notify(&self, conn: &Connection) -> Result<()> {
for author in self.get_post(conn)?.get_authors(conn)? { for author in self.get_post(conn)?.get_authors(conn)? {
if Mention::list_for_comment(conn, self.id)?
.iter()
.all(|m| m.get_mentioned(conn).map(|u| u != author).unwrap_or(true))
&& author.is_local()
{
Notification::insert( Notification::insert(
conn, conn,
NewNotification { NewNotification {
@ -166,6 +171,7 @@ impl Comment {
}, },
)?; )?;
} }
}
Ok(()) Ok(())
} }

View File

@ -67,7 +67,8 @@ impl Follow {
Ok(act) Ok(act)
} }
pub fn notify(&self, conn: &Connection) -> Result<Notification> { pub fn notify(&self, conn: &Connection) -> Result<()> {
if User::get(conn, self.following_id)?.is_local() {
Notification::insert( Notification::insert(
conn, conn,
NewNotification { NewNotification {
@ -75,7 +76,9 @@ impl Follow {
object_id: self.id, object_id: self.id,
user_id: self.following_id, user_id: self.following_id,
}, },
) )?;
}
Ok(())
} }
/// from -> The one sending the follow request /// from -> The one sending the follow request

View File

@ -4,7 +4,7 @@ use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use notifications::*; use notifications::*;
use plume_common::activity_pub::{ use plume_common::activity_pub::{
inbox::{AsObject, FromId}, inbox::{AsActor, AsObject, FromId},
Id, IntoId, PUBLIC_VISIBILITY, Id, IntoId, PUBLIC_VISIBILITY,
}; };
use posts::Post; use posts::Post;
@ -54,6 +54,7 @@ impl Like {
pub fn notify(&self, conn: &Connection) -> Result<()> { pub fn notify(&self, conn: &Connection) -> Result<()> {
let post = Post::get(conn, self.post_id)?; let post = Post::get(conn, self.post_id)?;
for author in post.get_authors(conn)? { for author in post.get_authors(conn)? {
if author.is_local() {
Notification::insert( Notification::insert(
conn, conn,
NewNotification { NewNotification {
@ -63,6 +64,7 @@ impl Like {
}, },
)?; )?;
} }
}
Ok(()) Ok(())
} }

View File

@ -3,6 +3,7 @@ use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use comments::Comment; use comments::Comment;
use notifications::*; use notifications::*;
use plume_common::activity_pub::inbox::AsActor;
use posts::Post; use posts::Post;
use schema::mentions; use schema::mentions;
use users::User; use users::User;
@ -129,6 +130,7 @@ impl Mention {
fn notify(&self, conn: &Connection) -> Result<()> { fn notify(&self, conn: &Connection) -> Result<()> {
let m = self.get_mentioned(conn)?; let m = self.get_mentioned(conn)?;
if m.is_local() {
Notification::insert( Notification::insert(
conn, conn,
NewNotification { NewNotification {
@ -138,5 +140,8 @@ impl Mention {
}, },
) )
.map(|_| ()) .map(|_| ())
} else {
Ok(())
}
} }
} }

View File

@ -4,7 +4,7 @@ use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
use notifications::*; use notifications::*;
use plume_common::activity_pub::{ use plume_common::activity_pub::{
inbox::{AsObject, FromId}, inbox::{AsActor, AsObject, FromId},
Id, IntoId, PUBLIC_VISIBILITY, Id, IntoId, PUBLIC_VISIBILITY,
}; };
use posts::Post; use posts::Post;
@ -79,6 +79,7 @@ impl Reshare {
pub fn notify(&self, conn: &Connection) -> Result<()> { pub fn notify(&self, conn: &Connection) -> Result<()> {
let post = self.get_post(conn)?; let post = self.get_post(conn)?;
for author in post.get_authors(conn)? { for author in post.get_authors(conn)? {
if author.is_local() {
Notification::insert( Notification::insert(
conn, conn,
NewNotification { NewNotification {
@ -88,6 +89,7 @@ impl Reshare {
}, },
)?; )?;
} }
}
Ok(()) Ok(())
} }

View File

@ -62,7 +62,6 @@ pub fn create(
}, },
) )
.expect("comments::create: insert error"); .expect("comments::create: insert error");
comm.notify(&*conn).expect("comments::create: notify error");
let new_comment = comm let new_comment = comm
.create_activity(&rockets) .create_activity(&rockets)
.expect("comments::create: activity error"); .expect("comments::create: activity error");
@ -80,6 +79,8 @@ pub fn create(
.expect("comments::create: mention save error"); .expect("comments::create: mention save error");
} }
comm.notify(&*conn).expect("comments::create: notify error");
// federate // federate
let dest = User::one_by_instance(&*conn).expect("comments::create: dest error"); let dest = User::one_by_instance(&*conn).expect("comments::create: dest error");
let user_clone = user.clone(); let user_clone = user.clone();