diff --git a/crates/api/src/community.rs b/crates/api/src/community.rs index ac39751c8..1378029df 100644 --- a/crates/api/src/community.rs +++ b/crates/api/src/community.rs @@ -22,6 +22,7 @@ use lemmy_apub::{ objects::{community::ApubCommunity, person::ApubPerson}, }; use lemmy_db_schema::{ + impls::community::CommunityModerator_, source::{ comment::Comment, community::{ diff --git a/crates/api/src/site.rs b/crates/api/src/site.rs index 105412b0e..4103549e5 100644 --- a/crates/api/src/site.rs +++ b/crates/api/src/site.rs @@ -347,20 +347,6 @@ impl Perform for Search { 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(), diff --git a/crates/api_crud/src/community/read.rs b/crates/api_crud/src/community/read.rs index d18ef99f6..310d33180 100644 --- a/crates/api_crud/src/community/read.rs +++ b/crates/api_crud/src/community/read.rs @@ -7,12 +7,7 @@ use lemmy_apub::{ objects::community::ApubCommunity, EndpointType, }; -use lemmy_db_schema::{ - from_opt_str_to_opt_enum, - traits::DeleteableOrRemoveable, - ListingType, - SortType, -}; +use lemmy_db_schema::{from_opt_str_to_opt_enum, ListingType, SortType}; use lemmy_db_views_actor::{ community_moderator_view::CommunityModeratorView, community_view::{CommunityQueryBuilder, CommunityView}, @@ -49,17 +44,12 @@ impl PerformCrud for GetCommunity { } }; - let mut community_view = blocking(context.pool(), move |conn| { + let community_view = blocking(context.pool(), move |conn| { CommunityView::read(conn, community_id, person_id) }) .await? .map_err(|e| ApiError::err("couldnt_find_community", e))?; - // 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 = blocking(context.pool(), move |conn| { CommunityModeratorView::for_community(conn, community_id) }) @@ -109,7 +99,7 @@ impl PerformCrud for ListCommunities { let page = data.page; let limit = data.limit; - let mut communities = blocking(context.pool(), move |conn| { + let communities = blocking(context.pool(), move |conn| { CommunityQueryBuilder::create(conn) .listing_type(listing_type) .sort(sort) @@ -121,14 +111,6 @@ 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 }) } diff --git a/crates/api_crud/src/post/read.rs b/crates/api_crud/src/post/read.rs index ee05b7231..fcd40b240 100644 --- a/crates/api_crud/src/post/read.rs +++ b/crates/api_crud/src/post/read.rs @@ -38,17 +38,12 @@ impl PerformCrud for GetPost { let person_id = local_user_view.map(|u| u.person.id); let id = data.id; - let mut post_view = blocking(context.pool(), move |conn| { + let post_view = blocking(context.pool(), move |conn| { PostView::read(conn, id, person_id) }) .await? .map_err(|e| ApiError::err("couldnt_find_post", e))?; - // 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?; @@ -80,17 +75,12 @@ impl PerformCrud for GetPost { .await??; // Necessary for the sidebar - let mut community_view = blocking(context.pool(), move |conn| { + let community_view = blocking(context.pool(), move |conn| { CommunityView::read(conn, community_id, person_id) }) .await? .map_err(|e| ApiError::err("couldnt_find_community", e))?; - // 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 }) @@ -144,7 +134,7 @@ impl PerformCrud for GetPosts { .unwrap_or(None); let saved_only = data.saved_only; - let mut posts = blocking(context.pool(), move |conn| { + let posts = blocking(context.pool(), move |conn| { PostQueryBuilder::create(conn) .listing_type(listing_type) .sort(sort) @@ -162,14 +152,6 @@ impl PerformCrud for GetPosts { .await? .map_err(|e| ApiError::err("couldnt_get_posts", e))?; - // 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 }) } } diff --git a/crates/apub/src/activities/community/add_mod.rs b/crates/apub/src/activities/community/add_mod.rs index e1cf03e0d..52923036d 100644 --- a/crates/apub/src/activities/community/add_mod.rs +++ b/crates/apub/src/activities/community/add_mod.rs @@ -25,6 +25,7 @@ use lemmy_apub_lib::{ values::PublicUrl, }; use lemmy_db_schema::{ + impls::community::CommunityModerator_, source::community::{CommunityModerator, CommunityModeratorForm}, traits::Joinable, }; diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index b2ebb3a0a..bd45ae316 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -204,8 +204,19 @@ impl DeleteableOrRemoveable for Community { } } -impl CommunityModerator { - pub fn delete_for_community( +pub trait CommunityModerator_ { + fn delete_for_community( + conn: &PgConnection, + for_community_id: CommunityId, + ) -> Result; + fn get_person_moderated_communities( + conn: &PgConnection, + for_person_id: PersonId, + ) -> Result, Error>; +} + +impl CommunityModerator_ for CommunityModerator { + fn delete_for_community( conn: &PgConnection, for_community_id: CommunityId, ) -> Result { @@ -213,7 +224,7 @@ impl CommunityModerator { diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn) } - pub fn get_person_moderated_communities( + fn get_person_moderated_communities( conn: &PgConnection, for_person_id: PersonId, ) -> Result, Error> { diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index c1f0fcbf2..57671fda9 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -11,7 +11,7 @@ use crate::{ PostSaved, PostSavedForm, }, - traits::{Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable}, + traits::{Crud, Likeable, Readable, Saveable}, }; use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl}; use url::Url; @@ -242,20 +242,6 @@ impl Readable 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::{ diff --git a/crates/websocket/src/send.rs b/crates/websocket/src/send.rs index 95780c329..85f24f12e 100644 --- a/crates/websocket/src/send.rs +++ b/crates/websocket/src/send.rs @@ -43,15 +43,11 @@ pub async fn send_post_ws_message person_id: Option, context: &LemmyContext, ) -> Result { - let mut post_view = blocking(context.pool(), move |conn| { + let post_view = blocking(context.pool(), move |conn| { PostView::read(conn, post_id, person_id) }) .await??; - 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 { @@ -118,14 +114,10 @@ pub async fn send_community_ws_message, context: &LemmyContext, ) -> Result { - let mut community_view = blocking(context.pool(), move |conn| { + let community_view = blocking(context.pool(), move |conn| { CommunityView::read(conn, community_id, 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 };