Fixing bug where comment replies wouldn't be sent to blocked instances. (#4595)
* Fixing bug where comment replies wouldn't be sent to blocked instances. - Instance blocks should only affect communities, not comments. - Fixes #4590 * Revert "Fixing bug where comment replies wouldn't be sent to blocked instances." This reverts commit 1349aa351a195fdf0d179c27a8057257ca37e255. * Only block replies from the community's instance id. - Also refactor send_local_notifs slightly, since it has to fetch the community now. - Fixes #4590 --------- Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
This commit is contained in:
parent
a14ebefd24
commit
8e54a4a6cc
7 changed files with 23 additions and 38 deletions
|
@ -19,7 +19,6 @@ use lemmy_db_schema::{
|
|||
comment_reply::{CommentReply, CommentReplyInsertForm},
|
||||
person::Person,
|
||||
person_mention::{PersonMention, PersonMentionInsertForm},
|
||||
post::Post,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
|
@ -91,16 +90,19 @@ pub async fn build_post_response(
|
|||
#[tracing::instrument(skip_all)]
|
||||
pub async fn send_local_notifs(
|
||||
mentions: Vec<MentionData>,
|
||||
comment: &Comment,
|
||||
comment_id: CommentId,
|
||||
person: &Person,
|
||||
post: &Post,
|
||||
do_send_email: bool,
|
||||
context: &LemmyContext,
|
||||
) -> Result<Vec<LocalUserId>, LemmyError> {
|
||||
let mut recipient_ids = Vec::new();
|
||||
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
||||
|
||||
let community_id = post.community_id;
|
||||
// Read the comment view to get extra info
|
||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||
let comment = comment_view.comment;
|
||||
let post = comment_view.post;
|
||||
let community = comment_view.community;
|
||||
|
||||
// Send the local mentions
|
||||
for mention in mentions
|
||||
|
@ -117,7 +119,7 @@ pub async fn send_local_notifs(
|
|||
|
||||
let user_mention_form = PersonMentionInsertForm {
|
||||
recipient_id: mention_user_view.person.id,
|
||||
comment_id: comment.id,
|
||||
comment_id,
|
||||
read: None,
|
||||
};
|
||||
|
||||
|
@ -152,8 +154,9 @@ pub async fn send_local_notifs(
|
|||
let check_blocks = check_person_instance_community_block(
|
||||
person.id,
|
||||
parent_creator_id,
|
||||
person.instance_id,
|
||||
community_id,
|
||||
// Only block from the community's instance_id
|
||||
community.instance_id,
|
||||
community.id,
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await
|
||||
|
@ -194,11 +197,13 @@ pub async fn send_local_notifs(
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// Use the post creator to check blocks
|
||||
let check_blocks = check_person_instance_community_block(
|
||||
person.id,
|
||||
post.creator_id,
|
||||
person.instance_id,
|
||||
community_id,
|
||||
// Only block from the community's instance_id
|
||||
community.instance_id,
|
||||
community.id,
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -295,12 +295,12 @@ async fn check_instance_block(
|
|||
pub async fn check_person_instance_community_block(
|
||||
my_id: PersonId,
|
||||
potential_blocker_id: PersonId,
|
||||
instance_id: InstanceId,
|
||||
community_instance_id: InstanceId,
|
||||
community_id: CommunityId,
|
||||
pool: &mut DbPool<'_>,
|
||||
) -> Result<(), LemmyError> {
|
||||
check_person_block(my_id, potential_blocker_id, pool).await?;
|
||||
check_instance_block(instance_id, potential_blocker_id, pool).await?;
|
||||
check_instance_block(community_instance_id, potential_blocker_id, pool).await?;
|
||||
check_community_block(community_id, potential_blocker_id, pool).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -138,9 +138,8 @@ pub async fn create_comment(
|
|||
let mentions = scrape_text_for_mentions(&content);
|
||||
let recipient_ids = send_local_notifs(
|
||||
mentions,
|
||||
&updated_comment,
|
||||
inserted_comment_id,
|
||||
&local_user_view.person,
|
||||
&post,
|
||||
true,
|
||||
&context,
|
||||
)
|
||||
|
|
|
@ -8,10 +8,7 @@ use lemmy_api_common::{
|
|||
utils::check_community_user_action,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
comment::{Comment, CommentUpdateForm},
|
||||
post::Post,
|
||||
},
|
||||
source::comment::{Comment, CommentUpdateForm},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
||||
|
@ -56,17 +53,8 @@ pub async fn delete_comment(
|
|||
.await
|
||||
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
||||
|
||||
let post_id = updated_comment.post_id;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let recipient_ids = send_local_notifs(
|
||||
vec![],
|
||||
&updated_comment,
|
||||
&local_user_view.person,
|
||||
&post,
|
||||
false,
|
||||
&context,
|
||||
)
|
||||
.await?;
|
||||
let recipient_ids =
|
||||
send_local_notifs(vec![], comment_id, &local_user_view.person, false, &context).await?;
|
||||
let updated_comment_id = updated_comment.id;
|
||||
|
||||
ActivityChannel::submit_activity(
|
||||
|
|
|
@ -12,7 +12,6 @@ use lemmy_db_schema::{
|
|||
comment::{Comment, CommentUpdateForm},
|
||||
comment_report::CommentReport,
|
||||
moderator::{ModRemoveComment, ModRemoveCommentForm},
|
||||
post::Post,
|
||||
},
|
||||
traits::{Crud, Reportable},
|
||||
};
|
||||
|
@ -61,13 +60,10 @@ pub async fn remove_comment(
|
|||
};
|
||||
ModRemoveComment::create(&mut context.pool(), &form).await?;
|
||||
|
||||
let post_id = updated_comment.post_id;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let recipient_ids = send_local_notifs(
|
||||
vec![],
|
||||
&updated_comment,
|
||||
comment_id,
|
||||
&local_user_view.person.clone(),
|
||||
&post,
|
||||
false,
|
||||
&context,
|
||||
)
|
||||
|
|
|
@ -79,9 +79,8 @@ pub async fn update_comment(
|
|||
let mentions = scrape_text_for_mentions(&updated_comment_content);
|
||||
let recipient_ids = send_local_notifs(
|
||||
mentions,
|
||||
&updated_comment,
|
||||
comment_id,
|
||||
&local_user_view.person,
|
||||
&orig_comment.post,
|
||||
false,
|
||||
&context,
|
||||
)
|
||||
|
|
|
@ -159,8 +159,6 @@ impl ActivityHandler for CreateOrUpdateNote {
|
|||
CommentAggregates::update_hot_rank(&mut context.pool(), comment.id).await?;
|
||||
|
||||
let do_send_email = self.kind == CreateOrUpdateType::Create;
|
||||
let post_id = comment.post_id;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let actor = self.actor.dereference(context).await?;
|
||||
|
||||
// Note:
|
||||
|
@ -169,7 +167,7 @@ impl ActivityHandler for CreateOrUpdateNote {
|
|||
// anyway.
|
||||
// TODO: for compatibility with other projects, it would be much better to read this from cc or tags
|
||||
let mentions = scrape_text_for_mentions(&comment.content);
|
||||
send_local_notifs(mentions, &comment.0, &actor, &post, do_send_email, context).await?;
|
||||
send_local_notifs(mentions, comment.id, &actor, do_send_email, context).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue