mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 07:36:01 +00:00
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 1349aa351a
.
* 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
|
@ -19,7 +19,6 @@ use lemmy_db_schema::{
|
||||||
comment_reply::{CommentReply, CommentReplyInsertForm},
|
comment_reply::{CommentReply, CommentReplyInsertForm},
|
||||||
person::Person,
|
person::Person,
|
||||||
person_mention::{PersonMention, PersonMentionInsertForm},
|
person_mention::{PersonMention, PersonMentionInsertForm},
|
||||||
post::Post,
|
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
|
@ -91,16 +90,19 @@ pub async fn build_post_response(
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn send_local_notifs(
|
pub async fn send_local_notifs(
|
||||||
mentions: Vec<MentionData>,
|
mentions: Vec<MentionData>,
|
||||||
comment: &Comment,
|
comment_id: CommentId,
|
||||||
person: &Person,
|
person: &Person,
|
||||||
post: &Post,
|
|
||||||
do_send_email: bool,
|
do_send_email: bool,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<Vec<LocalUserId>, LemmyError> {
|
) -> Result<Vec<LocalUserId>, LemmyError> {
|
||||||
let mut recipient_ids = Vec::new();
|
let mut recipient_ids = Vec::new();
|
||||||
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
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
|
// Send the local mentions
|
||||||
for mention in mentions
|
for mention in mentions
|
||||||
|
@ -117,7 +119,7 @@ pub async fn send_local_notifs(
|
||||||
|
|
||||||
let user_mention_form = PersonMentionInsertForm {
|
let user_mention_form = PersonMentionInsertForm {
|
||||||
recipient_id: mention_user_view.person.id,
|
recipient_id: mention_user_view.person.id,
|
||||||
comment_id: comment.id,
|
comment_id,
|
||||||
read: None,
|
read: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -152,8 +154,9 @@ pub async fn send_local_notifs(
|
||||||
let check_blocks = check_person_instance_community_block(
|
let check_blocks = check_person_instance_community_block(
|
||||||
person.id,
|
person.id,
|
||||||
parent_creator_id,
|
parent_creator_id,
|
||||||
person.instance_id,
|
// Only block from the community's instance_id
|
||||||
community_id,
|
community.instance_id,
|
||||||
|
community.id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -194,11 +197,13 @@ pub async fn send_local_notifs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Use the post creator to check blocks
|
||||||
let check_blocks = check_person_instance_community_block(
|
let check_blocks = check_person_instance_community_block(
|
||||||
person.id,
|
person.id,
|
||||||
post.creator_id,
|
post.creator_id,
|
||||||
person.instance_id,
|
// Only block from the community's instance_id
|
||||||
community_id,
|
community.instance_id,
|
||||||
|
community.id,
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -295,12 +295,12 @@ async fn check_instance_block(
|
||||||
pub async fn check_person_instance_community_block(
|
pub async fn check_person_instance_community_block(
|
||||||
my_id: PersonId,
|
my_id: PersonId,
|
||||||
potential_blocker_id: PersonId,
|
potential_blocker_id: PersonId,
|
||||||
instance_id: InstanceId,
|
community_instance_id: InstanceId,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
check_person_block(my_id, potential_blocker_id, pool).await?;
|
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?;
|
check_community_block(community_id, potential_blocker_id, pool).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,9 +138,8 @@ pub async fn create_comment(
|
||||||
let mentions = scrape_text_for_mentions(&content);
|
let mentions = scrape_text_for_mentions(&content);
|
||||||
let recipient_ids = send_local_notifs(
|
let recipient_ids = send_local_notifs(
|
||||||
mentions,
|
mentions,
|
||||||
&updated_comment,
|
inserted_comment_id,
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
&post,
|
|
||||||
true,
|
true,
|
||||||
&context,
|
&context,
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,10 +8,7 @@ use lemmy_api_common::{
|
||||||
utils::check_community_user_action,
|
utils::check_community_user_action,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::comment::{Comment, CommentUpdateForm},
|
||||||
comment::{Comment, CommentUpdateForm},
|
|
||||||
post::Post,
|
|
||||||
},
|
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
||||||
|
@ -56,17 +53,8 @@ pub async fn delete_comment(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
||||||
|
|
||||||
let post_id = updated_comment.post_id;
|
let recipient_ids =
|
||||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
send_local_notifs(vec![], comment_id, &local_user_view.person, false, &context).await?;
|
||||||
let recipient_ids = send_local_notifs(
|
|
||||||
vec![],
|
|
||||||
&updated_comment,
|
|
||||||
&local_user_view.person,
|
|
||||||
&post,
|
|
||||||
false,
|
|
||||||
&context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let updated_comment_id = updated_comment.id;
|
let updated_comment_id = updated_comment.id;
|
||||||
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
|
|
|
@ -12,7 +12,6 @@ use lemmy_db_schema::{
|
||||||
comment::{Comment, CommentUpdateForm},
|
comment::{Comment, CommentUpdateForm},
|
||||||
comment_report::CommentReport,
|
comment_report::CommentReport,
|
||||||
moderator::{ModRemoveComment, ModRemoveCommentForm},
|
moderator::{ModRemoveComment, ModRemoveCommentForm},
|
||||||
post::Post,
|
|
||||||
},
|
},
|
||||||
traits::{Crud, Reportable},
|
traits::{Crud, Reportable},
|
||||||
};
|
};
|
||||||
|
@ -61,13 +60,10 @@ pub async fn remove_comment(
|
||||||
};
|
};
|
||||||
ModRemoveComment::create(&mut context.pool(), &form).await?;
|
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(
|
let recipient_ids = send_local_notifs(
|
||||||
vec![],
|
vec![],
|
||||||
&updated_comment,
|
comment_id,
|
||||||
&local_user_view.person.clone(),
|
&local_user_view.person.clone(),
|
||||||
&post,
|
|
||||||
false,
|
false,
|
||||||
&context,
|
&context,
|
||||||
)
|
)
|
||||||
|
|
|
@ -79,9 +79,8 @@ pub async fn update_comment(
|
||||||
let mentions = scrape_text_for_mentions(&updated_comment_content);
|
let mentions = scrape_text_for_mentions(&updated_comment_content);
|
||||||
let recipient_ids = send_local_notifs(
|
let recipient_ids = send_local_notifs(
|
||||||
mentions,
|
mentions,
|
||||||
&updated_comment,
|
comment_id,
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
&orig_comment.post,
|
|
||||||
false,
|
false,
|
||||||
&context,
|
&context,
|
||||||
)
|
)
|
||||||
|
|
|
@ -159,8 +159,6 @@ impl ActivityHandler for CreateOrUpdateNote {
|
||||||
CommentAggregates::update_hot_rank(&mut context.pool(), comment.id).await?;
|
CommentAggregates::update_hot_rank(&mut context.pool(), comment.id).await?;
|
||||||
|
|
||||||
let do_send_email = self.kind == CreateOrUpdateType::Create;
|
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?;
|
let actor = self.actor.dereference(context).await?;
|
||||||
|
|
||||||
// Note:
|
// Note:
|
||||||
|
@ -169,7 +167,7 @@ impl ActivityHandler for CreateOrUpdateNote {
|
||||||
// anyway.
|
// anyway.
|
||||||
// TODO: for compatibility with other projects, it would be much better to read this from cc or tags
|
// 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);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue