diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index d421553f..fbaf3c1a 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -91,7 +91,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest { } } -pub fn broadcast(sender: &S, act: A, to: Vec) { +pub fn broadcast(sender: &S, act: A, to: Vec) { let boxes = to.into_iter() .filter(|u| !u.is_local()) .map(|u| u.get_shared_inbox_url().unwrap_or(u.get_inbox_url())) diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 4e096ef8..4d239694 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -100,6 +100,12 @@ impl User { find_by!(users, find_by_name, username as String, instance_id as i32); find_by!(users, find_by_ap_url, ap_url as String); + pub fn one_by_instance(&self, conn: &PgConnection) -> Vec { + users::table.distinct_on(users::instance_id) + .get_results::(conn) + .expect("Error in User::on_by_instance") + } + pub fn delete(&self, conn: &PgConnection) { diesel::delete(self).execute(conn).expect("Couldn't remove user from DB"); } diff --git a/src/routes/comments.rs b/src/routes/comments.rs index f896e703..65cfb741 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -43,9 +43,9 @@ fn create(blog_name: String, slug: String, data: LenientForm, us let instance = Instance::get_local(&*conn).unwrap(); instance.received(&*conn, serde_json::to_value(new_comment.clone()).expect("JSON serialization error")) .expect("We are not compatible with ourselve: local broadcast failed (new comment)"); - let followers = user.get_followers(&*conn); + let dest = User::one_by_instance(&*conn); let user_clone = user.clone(); - worker.execute(Thunk::of(move || broadcast(&user_clone, new_comment, followers))); + worker.execute(Thunk::of(move || broadcast(&user_clone, new_comment, dest))); Redirect::to(format!(uri!(super::posts::details: blog_name = blog_name, slug = slug)) }) diff --git a/src/routes/likes.rs b/src/routes/likes.rs index 8ba59171..699ac7f4 100644 --- a/src/routes/likes.rs +++ b/src/routes/likes.rs @@ -25,14 +25,14 @@ fn create(blog: String, slug: String, user: User, conn: DbConn, worker: State, user: User, conn: D } let act = post.create_activity(&*conn); - let followers = user.get_followers(&*conn); - worker.execute(Thunk::of(move || broadcast(&user, act, followers))); + let dest = User::one_by_instance(&*conn); + worker.execute(Thunk::of(move || broadcast(&user, act, dest))); Ok(Redirect::to(uri!(details: blog = blog_name, slug = slug))) } @@ -320,9 +320,9 @@ fn delete(blog_name: String, slug: String, conn: DbConn, user: User, worker: Sta if !post.get_authors(&*conn).into_iter().any(|a| a.id == user.id) { Redirect::to(uri!(details: blog = blog_name.clone(), slug = slug.clone())) } else { - let audience = user.get_followers(&*conn); + let dest = User::one_by_instance(&*conn); let delete_activity = post.delete(&*conn); - worker.execute(Thunk::of(move || broadcast(&user, delete_activity, audience))); + worker.execute(Thunk::of(move || broadcast(&user, delete_activity, dest))); Redirect::to(uri!(super::blogs::details: name = blog_name)) } diff --git a/src/routes/reshares.rs b/src/routes/reshares.rs index d449502f..9d259aff 100644 --- a/src/routes/reshares.rs +++ b/src/routes/reshares.rs @@ -25,14 +25,14 @@ fn create(blog: String, slug: String, user: User, conn: DbConn, worker: State