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:
parent
918bda14ec
commit
c9070930d2
@ -15,7 +15,7 @@ use medias::Media;
|
||||
use mentions::Mention;
|
||||
use notifications::*;
|
||||
use plume_common::activity_pub::{
|
||||
inbox::{AsObject, FromId},
|
||||
inbox::{AsActor, AsObject, FromId},
|
||||
Id, IntoId, PUBLIC_VISIBILITY,
|
||||
};
|
||||
use plume_common::utils;
|
||||
@ -157,6 +157,11 @@ impl Comment {
|
||||
|
||||
pub fn notify(&self, conn: &Connection) -> Result<()> {
|
||||
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(
|
||||
conn,
|
||||
NewNotification {
|
||||
@ -166,6 +171,7 @@ impl Comment {
|
||||
},
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,8 @@ impl Follow {
|
||||
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(
|
||||
conn,
|
||||
NewNotification {
|
||||
@ -75,7 +76,9 @@ impl Follow {
|
||||
object_id: self.id,
|
||||
user_id: self.following_id,
|
||||
},
|
||||
)
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// from -> The one sending the follow request
|
||||
|
@ -4,7 +4,7 @@ use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
|
||||
use notifications::*;
|
||||
use plume_common::activity_pub::{
|
||||
inbox::{AsObject, FromId},
|
||||
inbox::{AsActor, AsObject, FromId},
|
||||
Id, IntoId, PUBLIC_VISIBILITY,
|
||||
};
|
||||
use posts::Post;
|
||||
@ -54,6 +54,7 @@ impl Like {
|
||||
pub fn notify(&self, conn: &Connection) -> Result<()> {
|
||||
let post = Post::get(conn, self.post_id)?;
|
||||
for author in post.get_authors(conn)? {
|
||||
if author.is_local() {
|
||||
Notification::insert(
|
||||
conn,
|
||||
NewNotification {
|
||||
@ -63,6 +64,7 @@ impl Like {
|
||||
},
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
|
||||
use comments::Comment;
|
||||
use notifications::*;
|
||||
use plume_common::activity_pub::inbox::AsActor;
|
||||
use posts::Post;
|
||||
use schema::mentions;
|
||||
use users::User;
|
||||
@ -129,6 +130,7 @@ impl Mention {
|
||||
|
||||
fn notify(&self, conn: &Connection) -> Result<()> {
|
||||
let m = self.get_mentioned(conn)?;
|
||||
if m.is_local() {
|
||||
Notification::insert(
|
||||
conn,
|
||||
NewNotification {
|
||||
@ -138,5 +140,8 @@ impl Mention {
|
||||
},
|
||||
)
|
||||
.map(|_| ())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
|
||||
use notifications::*;
|
||||
use plume_common::activity_pub::{
|
||||
inbox::{AsObject, FromId},
|
||||
inbox::{AsActor, AsObject, FromId},
|
||||
Id, IntoId, PUBLIC_VISIBILITY,
|
||||
};
|
||||
use posts::Post;
|
||||
@ -79,6 +79,7 @@ impl Reshare {
|
||||
pub fn notify(&self, conn: &Connection) -> Result<()> {
|
||||
let post = self.get_post(conn)?;
|
||||
for author in post.get_authors(conn)? {
|
||||
if author.is_local() {
|
||||
Notification::insert(
|
||||
conn,
|
||||
NewNotification {
|
||||
@ -88,6 +89,7 @@ impl Reshare {
|
||||
},
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,6 @@ pub fn create(
|
||||
},
|
||||
)
|
||||
.expect("comments::create: insert error");
|
||||
comm.notify(&*conn).expect("comments::create: notify error");
|
||||
let new_comment = comm
|
||||
.create_activity(&rockets)
|
||||
.expect("comments::create: activity error");
|
||||
@ -80,6 +79,8 @@ pub fn create(
|
||||
.expect("comments::create: mention save error");
|
||||
}
|
||||
|
||||
comm.notify(&*conn).expect("comments::create: notify error");
|
||||
|
||||
// federate
|
||||
let dest = User::one_by_instance(&*conn).expect("comments::create: dest error");
|
||||
let user_clone = user.clone();
|
||||
|
Loading…
Reference in New Issue
Block a user