]> Untitled Git - lemmy.git/commitdiff
Blank out extra info for deleted or removed content. Fixes #1679 (#1680)
authorDessalines <dessalines@users.noreply.github.com>
Fri, 30 Jul 2021 18:44:15 +0000 (14:44 -0400)
committerGitHub <noreply@github.com>
Fri, 30 Jul 2021 18:44:15 +0000 (18:44 +0000)
22 files changed:
api_tests/src/comment.spec.ts
api_tests/src/community.spec.ts
api_tests/src/post.spec.ts
api_tests/src/private_message.spec.ts
crates/api/src/site.rs
crates/api_crud/src/comment/delete.rs
crates/api_crud/src/comment/read.rs
crates/api_crud/src/comment/update.rs
crates/api_crud/src/community/delete.rs
crates/api_crud/src/community/read.rs
crates/api_crud/src/community/update.rs
crates/api_crud/src/post/delete.rs
crates/api_crud/src/post/read.rs
crates/api_crud/src/post/update.rs
crates/api_crud/src/private_message/delete.rs
crates/api_crud/src/private_message/read.rs
crates/api_crud/src/private_message/update.rs
crates/db_queries/src/lib.rs
crates/db_queries/src/source/comment.rs
crates/db_queries/src/source/community.rs
crates/db_queries/src/source/post.rs
crates/db_queries/src/source/private_message.rs

index b0ca55d0d648fa8d0d8795248ff9fda6a31a816f..68dbcf7c1995b165f09de16ae26e482081c41642 100644 (file)
@@ -115,6 +115,7 @@ test('Delete a comment', async () => {
     commentRes.comment_view.comment.id
   );
   expect(deleteCommentRes.comment_view.comment.deleted).toBe(true);
+  expect(deleteCommentRes.comment_view.comment.content).toBe("");
 
   // Make sure that comment is undefined on beta
   let searchBeta = await searchComment(beta, commentRes.comment_view.comment);
@@ -149,6 +150,7 @@ test('Remove a comment from admin and community on the same instance', async ()
   // The beta admin removes it (the community lives on beta)
   let removeCommentRes = await removeComment(beta, true, betaCommentId);
   expect(removeCommentRes.comment_view.comment.removed).toBe(true);
+  expect(removeCommentRes.comment_view.comment.content).toBe("");
 
   // Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it)
   let refetchedPost = await getPost(alpha, postRes.post_view.post.id);
index a86c1259af2594fa5913a9db442ae91e38d5f996..3d4a3a350d079ad7ca77949adb3f36ee0528f7ea 100644 (file)
@@ -77,6 +77,7 @@ test('Delete community', async () => {
     communityRes.community_view.community.id
   );
   expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
+  expect(deleteCommunityRes.community_view.community.title).toBe("");
 
   // Make sure it got deleted on A
   let communityOnAlphaDeleted = await getCommunity(
@@ -128,6 +129,7 @@ test('Remove community', async () => {
     communityRes.community_view.community.id
   );
   expect(removeCommunityRes.community_view.community.removed).toBe(true);
+  expect(removeCommunityRes.community_view.community.title).toBe("");
 
   // Make sure it got Removed on A
   let communityOnAlphaRemoved = await getCommunity(
index 36e5ac3faed483879a101dd7d7466f79aa5f97d6..c5630f3367394400931ec8c7e7c0c043572e19f4 100644 (file)
@@ -210,6 +210,7 @@ test('Delete a post', async () => {
 
   let deletedPost = await deletePost(alpha, true, postRes.post_view.post);
   expect(deletedPost.post_view.post.deleted).toBe(true);
+  expect(deletedPost.post_view.post.name).toBe("");
 
   // Make sure lemmy beta sees post is deleted
   let searchBeta = await searchPost(beta, postRes.post_view.post);
@@ -237,6 +238,7 @@ test('Remove a post from admin and community on different instance', async () =>
 
   let removedPost = await removePost(alpha, true, postRes.post_view.post);
   expect(removedPost.post_view.post.removed).toBe(true);
+  expect(removedPost.post_view.post.name).toBe("");
 
   // Make sure lemmy beta sees post is NOT removed
   let searchBeta = await searchPost(beta, postRes.post_view.post);
index 11b41cb17139244339fc3e47b5d8100f3fa251f8..0051f2c772c31941fade73b7f5fedcda0eb49814 100644 (file)
@@ -64,6 +64,7 @@ test('Delete a private message', async () => {
     pmRes.private_message_view.private_message.id
   );
   expect(deletedPmRes.private_message_view.private_message.deleted).toBe(true);
+  expect(deletedPmRes.private_message_view.private_message.content).toBe("");
 
   // The GetPrivateMessages filters out deleted,
   // even though they are in the actual database.
index f9d7962be8d35bcef0622048bda5a4e9fe5a49be..d67c118150690a95596eb7f5f6972749bf5ae97e 100644 (file)
@@ -15,6 +15,7 @@ use lemmy_db_queries::{
   from_opt_str_to_opt_enum,
   source::site::Site_,
   Crud,
+  DeleteableOrRemoveable,
   ListingType,
   SearchType,
   SortType,
@@ -332,6 +333,28 @@ impl Perform for Search {
       }
     };
 
+    // Blank out deleted or removed info
+    for cv in comments
+      .iter_mut()
+      .filter(|cv| cv.comment.deleted || cv.comment.removed)
+    {
+      cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
+    }
+
+    for cv in communities
+      .iter_mut()
+      .filter(|cv| cv.community.deleted || cv.community.removed)
+    {
+      cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
+    }
+
+    for pv in posts
+      .iter_mut()
+      .filter(|p| p.post.deleted || p.post.removed)
+    {
+      pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
+    }
+
     // Return the jwt
     Ok(SearchResponse {
       type_: search_type.to_string(),
index f58f3b0e41659b26c2a656b699efcdbb8d91b70b..e2ec3080ea87e5900dd1a675716383e8bc946b71 100644 (file)
@@ -9,7 +9,7 @@ use lemmy_api_common::{
   send_local_notifs,
 };
 use lemmy_apub::ApubObjectType;
-use lemmy_db_queries::{source::comment::Comment_, Crud};
+use lemmy_db_queries::{source::comment::Comment_, Crud, DeleteableOrRemoveable};
 use lemmy_db_schema::source::{comment::*, moderator::*};
 use lemmy_db_views::comment_view::CommentView;
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
@@ -47,7 +47,7 @@ impl PerformCrud for DeleteComment {
 
     // Do the delete
     let deleted = data.deleted;
-    let updated_comment = blocking(context.pool(), move |conn| {
+    let mut updated_comment = blocking(context.pool(), move |conn| {
       Comment::update_deleted(conn, comment_id, deleted)
     })
     .await?
@@ -55,6 +55,7 @@ impl PerformCrud for DeleteComment {
 
     // Send the apub message
     if deleted {
+      updated_comment = updated_comment.blank_out_deleted_or_removed_info();
       updated_comment
         .send_delete(&local_user_view.person, context)
         .await?;
@@ -67,11 +68,16 @@ impl PerformCrud for DeleteComment {
     // Refetch it
     let comment_id = data.comment_id;
     let person_id = local_user_view.person.id;
-    let comment_view = blocking(context.pool(), move |conn| {
+    let mut comment_view = blocking(context.pool(), move |conn| {
       CommentView::read(conn, comment_id, Some(person_id))
     })
     .await??;
 
+    // Blank out deleted or removed info
+    if deleted {
+      comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
+    }
+
     // Build the recipients
     let comment_view_2 = comment_view.clone();
     let mentions = vec![];
@@ -136,7 +142,7 @@ impl PerformCrud for RemoveComment {
 
     // Do the remove
     let removed = data.removed;
-    let updated_comment = blocking(context.pool(), move |conn| {
+    let mut updated_comment = blocking(context.pool(), move |conn| {
       Comment::update_removed(conn, comment_id, removed)
     })
     .await?
@@ -156,6 +162,7 @@ impl PerformCrud for RemoveComment {
 
     // Send the apub message
     if removed {
+      updated_comment = updated_comment.blank_out_deleted_or_removed_info();
       updated_comment
         .send_remove(&local_user_view.person, context)
         .await?;
@@ -168,11 +175,16 @@ impl PerformCrud for RemoveComment {
     // Refetch it
     let comment_id = data.comment_id;
     let person_id = local_user_view.person.id;
-    let comment_view = blocking(context.pool(), move |conn| {
+    let mut comment_view = blocking(context.pool(), move |conn| {
       CommentView::read(conn, comment_id, Some(person_id))
     })
     .await??;
 
+    // Blank out deleted or removed info
+    if removed {
+      comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
+    }
+
     // Build the recipients
     let comment_view_2 = comment_view.clone();
 
index 47394402c35eef043690d3eaa31dae58ccce528a..fc4bd1e35119233c09362648d246a8713f787239 100644 (file)
@@ -2,7 +2,7 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, comment::*, get_local_user_view_from_jwt_opt};
 use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
-use lemmy_db_queries::{from_opt_str_to_opt_enum, ListingType, SortType};
+use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
 use lemmy_db_views::comment_view::CommentQueryBuilder;
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::LemmyContext;
@@ -36,7 +36,7 @@ impl PerformCrud for GetComments {
     let saved_only = data.saved_only;
     let page = data.page;
     let limit = data.limit;
-    let comments = blocking(context.pool(), move |conn| {
+    let mut comments = blocking(context.pool(), move |conn| {
       CommentQueryBuilder::create(conn)
         .listing_type(listing_type)
         .sort(sort)
@@ -52,6 +52,14 @@ impl PerformCrud for GetComments {
     .await?
     .map_err(|_| ApiError::err("couldnt_get_comments"))?;
 
+    // Blank out deleted or removed info
+    for cv in comments
+      .iter_mut()
+      .filter(|cv| cv.comment.deleted || cv.comment.removed)
+    {
+      cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
+    }
+
     Ok(GetCommentsResponse { comments })
   }
 }
index e6ed6ab59c80be69be81e810d7c2ee7ea16a79c9..dbdb1a6de76fac34a4ebf4f043eb1a6fa2c3493a 100644 (file)
@@ -8,7 +8,7 @@ use lemmy_api_common::{
   send_local_notifs,
 };
 use lemmy_apub::ApubObjectType;
-use lemmy_db_queries::source::comment::Comment_;
+use lemmy_db_queries::{source::comment::Comment_, DeleteableOrRemoveable};
 use lemmy_db_schema::source::comment::*;
 use lemmy_db_views::comment_view::CommentView;
 use lemmy_utils::{
@@ -78,11 +78,16 @@ impl PerformCrud for EditComment {
 
     let comment_id = data.comment_id;
     let person_id = local_user_view.person.id;
-    let comment_view = blocking(context.pool(), move |conn| {
+    let mut comment_view = blocking(context.pool(), move |conn| {
       CommentView::read(conn, comment_id, Some(person_id))
     })
     .await??;
 
+    // Blank out deleted or removed info
+    if comment_view.comment.deleted || comment_view.comment.removed {
+      comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
+    }
+
     let res = CommentResponse {
       comment_view,
       recipient_ids,
index 2208a348b752b80cf141f89c1298aa339122ea5d..62fb0f38fa2224f4a4d3a71c03b5861a3115571d 100644 (file)
@@ -2,7 +2,7 @@ use crate::{community::send_community_websocket, PerformCrud};
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin};
 use lemmy_apub::CommunityType;
-use lemmy_db_queries::{source::community::Community_, Crud};
+use lemmy_db_queries::{source::community::Community_, Crud, DeleteableOrRemoveable};
 use lemmy_db_schema::source::{
   community::*,
   moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
@@ -50,6 +50,7 @@ impl PerformCrud for DeleteCommunity {
     // Send apub messages
     if deleted {
       updated_community
+        .blank_out_deleted_or_removed_info()
         .send_delete(local_user_view.person.to_owned(), context)
         .await?;
     } else {
@@ -60,11 +61,16 @@ impl PerformCrud for DeleteCommunity {
 
     let community_id = data.community_id;
     let person_id = local_user_view.person.id;
-    let community_view = blocking(context.pool(), move |conn| {
+    let mut community_view = blocking(context.pool(), move |conn| {
       CommunityView::read(conn, community_id, Some(person_id))
     })
     .await??;
 
+    // Blank out deleted or removed info
+    if deleted {
+      community_view.community = community_view.community.blank_out_deleted_or_removed_info();
+    }
+
     let res = CommunityResponse { community_view };
 
     send_community_websocket(
@@ -118,18 +124,26 @@ impl PerformCrud for RemoveCommunity {
 
     // Apub messages
     if removed {
-      updated_community.send_remove(context).await?;
+      updated_community
+        .blank_out_deleted_or_removed_info()
+        .send_remove(context)
+        .await?;
     } else {
       updated_community.send_undo_remove(context).await?;
     }
 
     let community_id = data.community_id;
     let person_id = local_user_view.person.id;
-    let community_view = blocking(context.pool(), move |conn| {
+    let mut community_view = blocking(context.pool(), move |conn| {
       CommunityView::read(conn, community_id, Some(person_id))
     })
     .await??;
 
+    // Blank out deleted or removed info
+    if removed {
+      community_view.community = community_view.community.blank_out_deleted_or_removed_info();
+    }
+
     let res = CommunityResponse { community_view };
 
     send_community_websocket(
index 0cca08df85a24e716e1ba04c37f8468a7a35f96d..94e4ce7f4bc54ac97c1868f6344514741d02331d 100644 (file)
@@ -2,7 +2,13 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt};
 use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
-use lemmy_db_queries::{from_opt_str_to_opt_enum, ApubObject, ListingType, SortType};
+use lemmy_db_queries::{
+  from_opt_str_to_opt_enum,
+  ApubObject,
+  DeleteableOrRemoveable,
+  ListingType,
+  SortType,
+};
 use lemmy_db_schema::source::community::*;
 use lemmy_db_views_actor::{
   community_moderator_view::CommunityModeratorView,
@@ -39,12 +45,17 @@ impl PerformCrud for GetCommunity {
       }
     };
 
-    let community_view = blocking(context.pool(), move |conn| {
+    let mut community_view = blocking(context.pool(), move |conn| {
       CommunityView::read(conn, community_id, person_id)
     })
     .await?
     .map_err(|_| ApiError::err("couldnt_find_community"))?;
 
+    // Blank out deleted or removed info
+    if community_view.community.deleted || community_view.community.removed {
+      community_view.community = community_view.community.blank_out_deleted_or_removed_info();
+    }
+
     let moderators: Vec<CommunityModeratorView> = blocking(context.pool(), move |conn| {
       CommunityModeratorView::for_community(conn, community_id)
     })
@@ -93,7 +104,7 @@ impl PerformCrud for ListCommunities {
 
     let page = data.page;
     let limit = data.limit;
-    let communities = blocking(context.pool(), move |conn| {
+    let mut communities = blocking(context.pool(), move |conn| {
       CommunityQueryBuilder::create(conn)
         .listing_type(listing_type)
         .sort(sort)
@@ -105,6 +116,14 @@ impl PerformCrud for ListCommunities {
     })
     .await??;
 
+    // Blank out deleted or removed info
+    for cv in communities
+      .iter_mut()
+      .filter(|cv| cv.community.deleted || cv.community.removed)
+    {
+      cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
+    }
+
     // Return the jwt
     Ok(ListCommunitiesResponse { communities })
   }
index b17a223ee4b47ee250c98cb03ddb787c4fb4e330..49de1cfd744246eb2c22a708944c93645d9ae410 100644 (file)
@@ -6,7 +6,7 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
 };
 use lemmy_apub::CommunityType;
-use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud};
+use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud, DeleteableOrRemoveable};
 use lemmy_db_schema::{
   naive_now,
   source::community::{Community, CommunityForm},
@@ -78,11 +78,16 @@ impl PerformCrud for EditCommunity {
 
     let community_id = data.community_id;
     let person_id = local_user_view.person.id;
-    let community_view = blocking(context.pool(), move |conn| {
+    let mut community_view = blocking(context.pool(), move |conn| {
       CommunityView::read(conn, community_id, Some(person_id))
     })
     .await??;
 
+    // Blank out deleted or removed info
+    if community_view.community.deleted || community_view.community.removed {
+      community_view.community = community_view.community.blank_out_deleted_or_removed_info();
+    }
+
     let res = CommunityResponse { community_view };
 
     send_community_websocket(
index e7fcb2fd679f9dbcf20aeb807cb2e69c1ed171b7..cf48757d3f6105c8747728760ec5f584c184a130 100644 (file)
@@ -8,7 +8,7 @@ use lemmy_api_common::{
   post::*,
 };
 use lemmy_apub::ApubObjectType;
-use lemmy_db_queries::{source::post::Post_, Crud};
+use lemmy_db_queries::{source::post::Post_, Crud, DeleteableOrRemoveable};
 use lemmy_db_schema::source::{moderator::*, post::*};
 use lemmy_db_views::post_view::PostView;
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
@@ -52,6 +52,7 @@ impl PerformCrud for DeletePost {
     // apub updates
     if deleted {
       updated_post
+        .blank_out_deleted_or_removed_info()
         .send_delete(&local_user_view.person, context)
         .await?;
     } else {
@@ -62,11 +63,15 @@ impl PerformCrud for DeletePost {
 
     // Refetch the post
     let post_id = data.post_id;
-    let post_view = blocking(context.pool(), move |conn| {
+    let mut post_view = blocking(context.pool(), move |conn| {
       PostView::read(conn, post_id, Some(local_user_view.person.id))
     })
     .await??;
 
+    if deleted {
+      post_view.post = post_view.post.blank_out_deleted_or_removed_info();
+    }
+
     let res = PostResponse { post_view };
 
     context.chat_server().do_send(SendPost {
@@ -132,6 +137,7 @@ impl PerformCrud for RemovePost {
     // apub updates
     if removed {
       updated_post
+        .blank_out_deleted_or_removed_info()
         .send_remove(&local_user_view.person, context)
         .await?;
     } else {
@@ -143,11 +149,16 @@ impl PerformCrud for RemovePost {
     // Refetch the post
     let post_id = data.post_id;
     let person_id = local_user_view.person.id;
-    let post_view = blocking(context.pool(), move |conn| {
+    let mut post_view = blocking(context.pool(), move |conn| {
       PostView::read(conn, post_id, Some(person_id))
     })
     .await??;
 
+    // Blank out deleted or removed info
+    if removed {
+      post_view.post = post_view.post.blank_out_deleted_or_removed_info();
+    }
+
     let res = PostResponse { post_view };
 
     context.chat_server().do_send(SendPost {
index 77e7a2163d648e81914b1d006c99e3167e1ac231..d651a057708cd3e50b8bbc6e5e40c3d4b6a18e5f 100644 (file)
@@ -2,7 +2,7 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, mark_post_as_read, post::*};
 use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
-use lemmy_db_queries::{from_opt_str_to_opt_enum, ListingType, SortType};
+use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
 use lemmy_db_views::{
   comment_view::CommentQueryBuilder,
   post_view::{PostQueryBuilder, PostView},
@@ -32,19 +32,24 @@ impl PerformCrud for GetPost {
     let person_id = local_user_view.map(|u| u.person.id);
 
     let id = data.id;
-    let post_view = blocking(context.pool(), move |conn| {
+    let mut post_view = blocking(context.pool(), move |conn| {
       PostView::read(conn, id, person_id)
     })
     .await?
     .map_err(|_| ApiError::err("couldnt_find_post"))?;
 
+    // Blank out deleted info
+    if post_view.post.deleted || post_view.post.removed {
+      post_view.post = post_view.post.blank_out_deleted_or_removed_info();
+    }
+
     // Mark the post as read
     if let Some(person_id) = person_id {
       mark_post_as_read(person_id, id, context.pool()).await?;
     }
 
     let id = data.id;
-    let comments = blocking(context.pool(), move |conn| {
+    let mut comments = blocking(context.pool(), move |conn| {
       CommentQueryBuilder::create(conn)
         .my_person_id(person_id)
         .show_bot_accounts(show_bot_accounts)
@@ -54,6 +59,14 @@ impl PerformCrud for GetPost {
     })
     .await??;
 
+    // Blank out deleted or removed info
+    for cv in comments
+      .iter_mut()
+      .filter(|cv| cv.comment.deleted || cv.comment.removed)
+    {
+      cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
+    }
+
     let community_id = post_view.community.id;
     let moderators = blocking(context.pool(), move |conn| {
       CommunityModeratorView::for_community(conn, community_id)
@@ -61,12 +74,17 @@ impl PerformCrud for GetPost {
     .await??;
 
     // Necessary for the sidebar
-    let community_view = blocking(context.pool(), move |conn| {
+    let mut community_view = blocking(context.pool(), move |conn| {
       CommunityView::read(conn, community_id, person_id)
     })
     .await?
     .map_err(|_| ApiError::err("couldnt_find_community"))?;
 
+    // Blank out deleted or removed info
+    if community_view.community.deleted || community_view.community.removed {
+      community_view.community = community_view.community.blank_out_deleted_or_removed_info();
+    }
+
     let online = context
       .chat_server()
       .send(GetPostUsersOnline { post_id: data.id })
@@ -119,7 +137,7 @@ impl PerformCrud for GetPosts {
       .unwrap_or(None);
     let saved_only = data.saved_only;
 
-    let posts = blocking(context.pool(), move |conn| {
+    let mut posts = blocking(context.pool(), move |conn| {
       PostQueryBuilder::create(conn)
         .listing_type(listing_type)
         .sort(sort)
@@ -137,6 +155,14 @@ impl PerformCrud for GetPosts {
     .await?
     .map_err(|_| ApiError::err("couldnt_get_posts"))?;
 
+    // Blank out deleted or removed info
+    for pv in posts
+      .iter_mut()
+      .filter(|p| p.post.deleted || p.post.removed)
+    {
+      pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
+    }
+
     Ok(GetPostsResponse { posts })
   }
 }
index f215da7d03dacc3780a8e2aa69b2774b74d2fc39..5166f21278d34a4710f7a7451a3439afa61a02e4 100644 (file)
@@ -2,7 +2,7 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{blocking, check_community_ban, get_local_user_view_from_jwt, post::*};
 use lemmy_apub::ApubObjectType;
-use lemmy_db_queries::{source::post::Post_, Crud};
+use lemmy_db_queries::{source::post::Post_, Crud, DeleteableOrRemoveable};
 use lemmy_db_schema::{naive_now, source::post::*};
 use lemmy_db_views::post_view::PostView;
 use lemmy_utils::{
@@ -94,11 +94,16 @@ impl PerformCrud for EditPost {
       .await?;
 
     let post_id = data.post_id;
-    let post_view = blocking(context.pool(), move |conn| {
+    let mut post_view = blocking(context.pool(), move |conn| {
       PostView::read(conn, post_id, Some(local_user_view.person.id))
     })
     .await??;
 
+    // Blank out deleted info
+    if post_view.post.deleted || post_view.post.removed {
+      post_view.post = post_view.post.blank_out_deleted_or_removed_info();
+    }
+
     let res = PostResponse { post_view };
 
     context.chat_server().do_send(SendPost {
index 6befb75da8e9e29d7a5b5c0182c2555c75b02edf..757596cd1d629393d803f7fe48a076d4eec9b0b9 100644 (file)
@@ -6,7 +6,7 @@ use lemmy_api_common::{
   person::{DeletePrivateMessage, PrivateMessageResponse},
 };
 use lemmy_apub::ApubObjectType;
-use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
+use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DeleteableOrRemoveable};
 use lemmy_db_schema::source::private_message::PrivateMessage;
 use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView};
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
@@ -46,6 +46,7 @@ impl PerformCrud for DeletePrivateMessage {
     // Send the apub update
     if data.deleted {
       updated_private_message
+        .blank_out_deleted_or_removed_info()
         .send_delete(&local_user_view.person, context)
         .await?;
     } else {
@@ -55,11 +56,18 @@ impl PerformCrud for DeletePrivateMessage {
     }
 
     let private_message_id = data.private_message_id;
-    let private_message_view = blocking(context.pool(), move |conn| {
+    let mut private_message_view = blocking(context.pool(), move |conn| {
       PrivateMessageView::read(conn, private_message_id)
     })
     .await??;
 
+    // Blank out deleted or removed info
+    if deleted {
+      private_message_view.private_message = private_message_view
+        .private_message
+        .blank_out_deleted_or_removed_info();
+    }
+
     let res = PrivateMessageResponse {
       private_message_view,
     };
index 6706bf419b9c53df0808f9c6e1aed761a668c82d..3acbaa39200b8a0cfe6ae4c565ee5bbcd8c71c55 100644 (file)
@@ -5,6 +5,7 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
   person::{GetPrivateMessages, PrivateMessagesResponse},
 };
+use lemmy_db_queries::DeleteableOrRemoveable;
 use lemmy_db_views::private_message_view::PrivateMessageQueryBuilder;
 use lemmy_utils::{ConnectionId, LemmyError};
 use lemmy_websocket::LemmyContext;
@@ -25,7 +26,7 @@ impl PerformCrud for GetPrivateMessages {
     let page = data.page;
     let limit = data.limit;
     let unread_only = data.unread_only;
-    let messages = blocking(context.pool(), move |conn| {
+    let mut messages = blocking(context.pool(), move |conn| {
       PrivateMessageQueryBuilder::create(conn, person_id)
         .page(page)
         .limit(limit)
@@ -34,6 +35,17 @@ impl PerformCrud for GetPrivateMessages {
     })
     .await??;
 
+    // Blank out deleted or removed info
+    for pmv in messages
+      .iter_mut()
+      .filter(|pmv| pmv.private_message.deleted)
+    {
+      pmv.private_message = pmv
+        .to_owned()
+        .private_message
+        .blank_out_deleted_or_removed_info();
+    }
+
     Ok(PrivateMessagesResponse {
       private_messages: messages,
     })
index 35a9806a8fdb643d50651d6b3a18c670346c3cff..33c29d00d1c65d230c70c4dff9a46c0867561eb6 100644 (file)
@@ -6,7 +6,7 @@ use lemmy_api_common::{
   person::{EditPrivateMessage, PrivateMessageResponse},
 };
 use lemmy_apub::ApubObjectType;
-use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
+use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DeleteableOrRemoveable};
 use lemmy_db_schema::source::private_message::PrivateMessage;
 use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView};
 use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError};
@@ -49,11 +49,18 @@ impl PerformCrud for EditPrivateMessage {
       .await?;
 
     let private_message_id = data.private_message_id;
-    let private_message_view = blocking(context.pool(), move |conn| {
+    let mut private_message_view = blocking(context.pool(), move |conn| {
       PrivateMessageView::read(conn, private_message_id)
     })
     .await??;
 
+    // Blank out deleted or removed info
+    if private_message_view.private_message.deleted {
+      private_message_view.private_message = private_message_view
+        .private_message
+        .blank_out_deleted_or_removed_info();
+    }
+
     let res = PrivateMessageResponse {
       private_message_view,
     };
index fbd508c150a6c261568ee278fc5ec46469f6eaca..adc0717acd8ae65395e888c94890a2ae4b08ab01 100644 (file)
@@ -117,6 +117,10 @@ pub trait Reportable<Form> {
     Self: Sized;
 }
 
+pub trait DeleteableOrRemoveable {
+  fn blank_out_deleted_or_removed_info(self) -> Self;
+}
+
 pub trait ApubObject<Form> {
   fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error>
   where
index 1eec0c987115f1611d1fd1d35092bc859bf9fbb2..d0171cb8ddfa80b1f7dbba889a8427ae12107556 100644 (file)
@@ -1,4 +1,4 @@
-use crate::{ApubObject, Crud, Likeable, Saveable};
+use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Saveable};
 use diesel::{dsl::*, result::Error, *};
 use lemmy_db_schema::{
   naive_now,
@@ -228,6 +228,13 @@ impl Saveable<CommentSavedForm> for CommentSaved {
   }
 }
 
+impl DeleteableOrRemoveable for Comment {
+  fn blank_out_deleted_or_removed_info(mut self) -> Self {
+    self.content = "".into();
+    self
+  }
+}
+
 #[cfg(test)]
 mod tests {
   use crate::{establish_unpooled_connection, Crud, Likeable, Saveable};
index 3f1f047673e2024baabeb61ed4de68d56725492f..2a62193397d607cc840f6a0156a17ceecb90e73d 100644 (file)
@@ -1,4 +1,4 @@
-use crate::{ApubObject, Bannable, Crud, Followable, Joinable};
+use crate::{ApubObject, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable};
 use diesel::{dsl::*, result::Error, *};
 use lemmy_db_schema::{
   naive_now,
@@ -11,6 +11,7 @@ use lemmy_db_schema::{
     CommunityModeratorForm,
     CommunityPersonBan,
     CommunityPersonBanForm,
+    CommunitySafe,
   },
   CommunityId,
   DbUrl,
@@ -199,6 +200,26 @@ impl Joinable<CommunityModeratorForm> for CommunityModerator {
   }
 }
 
+impl DeleteableOrRemoveable for CommunitySafe {
+  fn blank_out_deleted_or_removed_info(mut self) -> Self {
+    self.title = "".into();
+    self.description = None;
+    self.icon = None;
+    self.banner = None;
+    self
+  }
+}
+
+impl DeleteableOrRemoveable for Community {
+  fn blank_out_deleted_or_removed_info(mut self) -> Self {
+    self.title = "".into();
+    self.description = None;
+    self.icon = None;
+    self.banner = None;
+    self
+  }
+}
+
 pub trait CommunityModerator_ {
   fn delete_for_community(
     conn: &PgConnection,
index 9f2d2f9b396c162dbf239bcf02c1e74f2fc613ff..f0cf109357ec949a98eff698be2f473a2b8fddce 100644 (file)
@@ -1,4 +1,4 @@
-use crate::{ApubObject, Crud, Likeable, Readable, Saveable};
+use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable};
 use diesel::{dsl::*, result::Error, *};
 use lemmy_db_schema::{
   naive_now,
@@ -260,6 +260,20 @@ impl Readable<PostReadForm> for PostRead {
   }
 }
 
+impl DeleteableOrRemoveable for Post {
+  fn blank_out_deleted_or_removed_info(mut self) -> Self {
+    self.name = "".into();
+    self.url = None;
+    self.body = None;
+    self.embed_title = None;
+    self.embed_description = None;
+    self.embed_html = None;
+    self.thumbnail_url = None;
+
+    self
+  }
+}
+
 #[cfg(test)]
 mod tests {
   use crate::{establish_unpooled_connection, source::post::*};
index 98c8e08ce4c644a13232b9889d3160f9afbd2b8b..da1c5abd5989c5651b58594cf7dcc0468043a1c5 100644 (file)
@@ -1,4 +1,4 @@
-use crate::{ApubObject, Crud};
+use crate::{ApubObject, Crud, DeleteableOrRemoveable};
 use diesel::{dsl::*, result::Error, *};
 use lemmy_db_schema::{naive_now, source::private_message::*, DbUrl, PersonId, PrivateMessageId};
 
@@ -137,6 +137,13 @@ impl PrivateMessage_ for PrivateMessage {
   }
 }
 
+impl DeleteableOrRemoveable for PrivateMessage {
+  fn blank_out_deleted_or_removed_info(mut self) -> Self {
+    self.content = "".into();
+    self
+  }
+}
+
 #[cfg(test)]
 mod tests {
   use crate::{establish_unpooled_connection, source::private_message::PrivateMessage_, Crud};