mirror of https://github.com/LemmyNet/lemmy.git
Dont blank out post or community info. Fixes #1813
parent
f4bac6a17f
commit
f09ab9e384
|
@ -22,6 +22,7 @@ use lemmy_apub::{
|
|||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
impls::community::CommunityModerator_,
|
||||
source::{
|
||||
comment::Comment,
|
||||
community::{
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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<CommunityModeratorView> = 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 })
|
||||
}
|
||||
|
|
|
@ -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 })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ use lemmy_apub_lib::{
|
|||
values::PublicUrl,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
impls::community::CommunityModerator_,
|
||||
source::community::{CommunityModerator, CommunityModeratorForm},
|
||||
traits::Joinable,
|
||||
};
|
||||
|
|
|
@ -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<usize, Error>;
|
||||
fn get_person_moderated_communities(
|
||||
conn: &PgConnection,
|
||||
for_person_id: PersonId,
|
||||
) -> Result<Vec<CommunityId>, Error>;
|
||||
}
|
||||
|
||||
impl CommunityModerator_ for CommunityModerator {
|
||||
fn delete_for_community(
|
||||
conn: &PgConnection,
|
||||
for_community_id: CommunityId,
|
||||
) -> Result<usize, Error> {
|
||||
|
@ -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<Vec<CommunityId>, Error> {
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -43,15 +43,11 @@ pub async fn send_post_ws_message<OP: ToString + Send + OperationType + 'static>
|
|||
person_id: Option<PersonId>,
|
||||
context: &LemmyContext,
|
||||
) -> Result<PostResponse, LemmyError> {
|
||||
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<OP: ToString + Send + OperationType + 'st
|
|||
person_id: Option<PersonId>,
|
||||
context: &LemmyContext,
|
||||
) -> Result<CommunityResponse, LemmyError> {
|
||||
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 };
|
||||
|
||||
|
|
Loading…
Reference in New Issue