From 4a1ceeac01d3dff09bf5e8984c56ff26e5ead883 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 2 Dec 2021 11:36:14 -0500 Subject: [PATCH] Allow comment replies from blocked users. Fixes #1793 --- crates/api_crud/src/comment/create.rs | 5 ----- crates/websocket/src/send.rs | 22 ++++++++++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index 09163aef4..025e12c82 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -4,7 +4,6 @@ use lemmy_api_common::{ blocking, check_community_ban, check_community_deleted_or_removed, - check_person_block, check_post_deleted_or_removed, comment::*, get_local_user_view_from_jwt, @@ -66,8 +65,6 @@ impl PerformCrud for CreateComment { check_community_deleted_or_removed(community_id, context.pool()).await?; check_post_deleted_or_removed(&post)?; - check_person_block(local_user_view.person.id, post.creator_id, context.pool()).await?; - // Check if post is locked, no new comments if post.locked { return Err(ApiError::err_plain("locked").into()); @@ -80,8 +77,6 @@ impl PerformCrud for CreateComment { .await? .map_err(|e| ApiError::err("couldnt_create_comment", e))?; - check_person_block(local_user_view.person.id, parent.creator_id, context.pool()).await?; - // Strange issue where sometimes the post ID is incorrect if parent.post_id != post_id { return Err(ApiError::err_plain("couldnt_create_comment").into()); diff --git a/crates/websocket/src/send.rs b/crates/websocket/src/send.rs index ccb29879e..7a2cc01bf 100644 --- a/crates/websocket/src/send.rs +++ b/crates/websocket/src/send.rs @@ -5,6 +5,7 @@ use crate::{ }; use lemmy_api_common::{ blocking, + check_person_block, comment::CommentResponse, community::CommunityResponse, person::PrivateMessageResponse, @@ -233,11 +234,18 @@ pub async fn send_local_notifs( let parent_comment = blocking(context.pool(), move |conn| Comment::read(conn, parent_id)).await?; if let Ok(parent_comment) = parent_comment { + // Get the parent commenter local_user + let parent_creator_id = parent_comment.creator_id; + // Don't send a notif to yourself - if parent_comment.creator_id != person.id { - // Get the parent commenter local_user + if parent_comment.creator_id != person.id + // And only add to recipients if that person isn't blocked + && check_person_block(person.id, parent_creator_id, context.pool()) + .await + .is_ok() + { let user_view = blocking(context.pool(), move |conn| { - LocalUserView::read_person(conn, parent_comment.creator_id) + LocalUserView::read_person(conn, parent_creator_id) }) .await?; if let Ok(parent_user_view) = user_view { @@ -258,7 +266,13 @@ pub async fn send_local_notifs( } // Its a post None => { - if post.creator_id != person.id { + // Don't send a notif to yourself + if post.creator_id != person.id + // And only add to recipients if that person isn't blocked + && check_person_block(person.id, post.creator_id, context.pool()) + .await + .is_ok() + { let creator_id = post.creator_id; let parent_user = blocking(context.pool(), move |conn| { LocalUserView::read_person(conn, creator_id)