-
-
Notifications
You must be signed in to change notification settings - Fork 941
Remove Children #6319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Remove Children #6319
Changes from all commits
c2c82aa
96b7ab3
b32a15e
5e44bb0
f868e10
faff627
7e6039f
59b8074
403da65
cbf596a
69d0109
7d41e9f
663205b
e5d009a
af39563
ab47f8f
f69c449
9d282b1
ba65452
7474a00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,36 +55,83 @@ pub async fn remove_comment( | |
| ) | ||
| .await?; | ||
|
|
||
| // Don't allow removing or restoring comment which was deleted by user, as it would reveal | ||
| // the comment text in mod log. | ||
| if orig_comment.comment.deleted { | ||
| return Err(LemmyErrorType::CouldntUpdate.into()); | ||
| } | ||
|
|
||
| // Do the remove | ||
| let removed = data.removed; | ||
| let updated_comment = Comment::update( | ||
| &mut context.pool(), | ||
| comment_id, | ||
| &CommentUpdateForm { | ||
| removed: Some(removed), | ||
| ..Default::default() | ||
| }, | ||
| ) | ||
| .await?; | ||
| let updated_comment = if let Some(remove_children) = data.remove_children { | ||
| let updated_comments: Vec<Comment> = Comment::update_removed_for_comment_and_children( | ||
| &mut context.pool(), | ||
| &orig_comment.comment.path, | ||
| remove_children, | ||
| ) | ||
| .await?; | ||
|
|
||
| let updated_comment = updated_comments | ||
| .iter() | ||
| .find(|c| c.id == comment_id) | ||
| .ok_or(LemmyErrorType::CouldntUpdate)? | ||
| .clone(); | ||
|
|
||
| let forms: Vec<_> = updated_comments | ||
| .iter() | ||
| // Filter out deleted comments here so their content doesn't show up in the modlog. | ||
| .filter(|c| !c.deleted) | ||
| .map(|comment| { | ||
| ModlogInsertForm::mod_remove_comment( | ||
| local_user_view.person.id, | ||
| comment, | ||
| remove_children, | ||
| &data.reason, | ||
| ) | ||
| }) | ||
| .collect(); | ||
|
|
||
| let actions = Modlog::create(&mut context.pool(), &forms).await?; | ||
| notify_mod_action(actions, &context); | ||
|
|
||
| CommentReport::resolve_all_for_object(&mut context.pool(), comment_id, local_user_view.person.id) | ||
| CommentReport::resolve_all_for_thread( | ||
| &mut context.pool(), | ||
| &orig_comment.comment.path, | ||
| local_user_view.person.id, | ||
| ) | ||
| .await?; | ||
|
|
||
| // Mod tables | ||
| let form = ModlogInsertForm::mod_remove_comment( | ||
| local_user_view.person.id, | ||
| &orig_comment.comment, | ||
| removed, | ||
| &data.reason, | ||
| ); | ||
| let actions = Modlog::create(&mut context.pool(), &[form]).await?; | ||
| notify_mod_action(actions, context.app_data()); | ||
| updated_comment | ||
| } else { | ||
| // Don't allow removing or restoring comment which was deleted by user, as it would reveal | ||
| // the comment text in mod log. | ||
| if orig_comment.comment.deleted { | ||
| return Err(LemmyErrorType::CouldntUpdate.into()); | ||
| } | ||
|
|
||
| // Do the remove | ||
| let removed = data.removed; | ||
| let updated_comment = Comment::update( | ||
| &mut context.pool(), | ||
| comment_id, | ||
| &CommentUpdateForm { | ||
| removed: Some(removed), | ||
| ..Default::default() | ||
| }, | ||
| ) | ||
| .await?; | ||
|
|
||
| CommentReport::resolve_all_for_object( | ||
| &mut context.pool(), | ||
| comment_id, | ||
| local_user_view.person.id, | ||
| ) | ||
| .await?; | ||
|
|
||
| // Mod tables | ||
| let form = ModlogInsertForm::mod_remove_comment( | ||
| local_user_view.person.id, | ||
| &orig_comment.comment, | ||
| removed, | ||
| &data.reason, | ||
| ); | ||
| let actions = Modlog::create(&mut context.pool(), &[form]).await?; | ||
|
Comment on lines
+124
to
+130
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we aren't creating a bunch of rows for each of these? I notice lock also works like this so its probably fine. I guess that's #6323 |
||
| notify_mod_action(actions, context.app_data()); | ||
|
|
||
| updated_comment | ||
| }; | ||
|
|
||
| let updated_comment_id = updated_comment.id; | ||
|
|
||
|
|
@@ -94,6 +141,7 @@ pub async fn remove_comment( | |
| moderator: local_user_view.person.clone(), | ||
| community: orig_comment.community, | ||
| reason: data.reason.clone(), | ||
| with_replies: data.remove_children.unwrap_or_default(), | ||
| }, | ||
| &context, | ||
| )?; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ use lemmy_api_utils::{ | |
| }; | ||
| use lemmy_db_schema::{ | ||
| source::{ | ||
| comment::Comment, | ||
| comment_report::CommentReport, | ||
| community::Community, | ||
| local_user::LocalUser, | ||
| modlog::{Modlog, ModlogInsertForm}, | ||
|
|
@@ -28,6 +30,7 @@ pub async fn remove_post( | |
| local_user_view: LocalUserView, | ||
| ) -> LemmyResult<Json<PostResponse>> { | ||
| let post_id = data.post_id; | ||
| let removed = data.remove_children.unwrap_or(data.removed); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potentially dangerous, you can remove, see below comment.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // We cannot use PostView to avoid a database read here, as it doesn't return removed items | ||
| // by default. So we would have to pass in `is_mod_or_admin`, but that is impossible without | ||
|
|
@@ -46,8 +49,6 @@ pub async fn remove_post( | |
| .await?; | ||
|
|
||
| // Update the post | ||
| let post_id = data.post_id; | ||
| let removed = data.removed; | ||
| let post = Post::update( | ||
| &mut context.pool(), | ||
| post_id, | ||
|
|
@@ -67,15 +68,41 @@ pub async fn remove_post( | |
| let action = Modlog::create(&mut context.pool(), &[form]).await?; | ||
| notify_mod_action(action, context.app_data()); | ||
|
|
||
| if data.remove_children.is_some() { | ||
| let updated_comments: Vec<Comment> = | ||
| Comment::update_removed_for_post(&mut context.pool(), post_id, removed).await?; | ||
|
|
||
| let forms: Vec<_> = updated_comments | ||
| .iter() | ||
| // Filter out deleted comments here so their content doesn't show up in the modlog. | ||
| .filter(|c| !c.deleted) | ||
| .map(|comment| { | ||
| ModlogInsertForm::mod_remove_comment( | ||
| local_user_view.person.id, | ||
| comment, | ||
| removed, | ||
| &data.reason, | ||
| ) | ||
| }) | ||
| .collect(); | ||
|
|
||
| let actions = Modlog::create(&mut context.pool(), &forms).await?; | ||
| notify_mod_action(actions, &context); | ||
|
|
||
| CommentReport::resolve_all_for_post(&mut context.pool(), post.id, local_user_view.person.id) | ||
| .await?; | ||
| } | ||
|
|
||
| ActivityChannel::submit_activity( | ||
| SendActivityData::RemovePost { | ||
| post, | ||
| moderator: local_user_view.person.clone(), | ||
| reason: data.reason.clone(), | ||
| removed: data.removed, | ||
| removed, | ||
| with_replies: data.remove_children.unwrap_or_default(), | ||
| }, | ||
| &context, | ||
| )?; | ||
|
|
||
| build_post_response(&context, orig_post.community_id, local_user_view, post_id).await | ||
| build_post_response(&context, community.id, local_user_view, post_id).await | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in an else block now? Then you'll be able to reveal the comment text in the modlog as long as delete children is true.
Probably just keep this top level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured it'd be useful to be able to remove the replies to a deleted comment.