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);
// 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);
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(
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(
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);
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);
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.
from_opt_str_to_opt_enum,
source::site::Site_,
Crud,
+ DeleteableOrRemoveable,
ListingType,
SearchType,
SortType,
}
};
+ // 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(),
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};
// 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?
// 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?;
// 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![];
// 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?
// 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?;
// 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();
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;
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)
.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 })
}
}
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::{
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,
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},
// Send apub messages
if deleted {
updated_community
+ .blank_out_deleted_or_removed_info()
.send_delete(local_user_view.person.to_owned(), context)
.await?;
} else {
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(
// 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(
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,
}
};
- 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)
})
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)
})
.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 })
}
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},
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(
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};
// apub updates
if deleted {
updated_post
+ .blank_out_deleted_or_removed_info()
.send_delete(&local_user_view.person, context)
.await?;
} else {
// 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 {
// apub updates
if removed {
updated_post
+ .blank_out_deleted_or_removed_info()
.send_remove(&local_user_view.person, context)
.await?;
} else {
// 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 {
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},
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)
})
.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)
.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 })
.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)
.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 })
}
}
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::{
.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 {
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};
// 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 {
}
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,
};
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;
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)
})
.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,
})
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};
.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,
};
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
-use crate::{ApubObject, Crud, Likeable, Saveable};
+use crate::{ApubObject, Crud, DeleteableOrRemoveable, Likeable, Saveable};
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{
naive_now,
}
}
+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};
-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,
CommunityModeratorForm,
CommunityPersonBan,
CommunityPersonBanForm,
+ CommunitySafe,
},
CommunityId,
DbUrl,
}
}
+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,
-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,
}
}
+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::*};
-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};
}
}
+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};