no show_removed/show_deleted
This commit is contained in:
parent
a32f901264
commit
15f3449e6d
7 changed files with 64 additions and 45 deletions
|
|
@ -53,7 +53,6 @@ impl PerformApub for GetComments {
|
|||
|
||||
let parent_path_cloned = parent_path.clone();
|
||||
let post_id = data.post_id;
|
||||
let local_user = local_user_view.map(|l| l.local_user);
|
||||
let comments = CommentQuery::builder()
|
||||
.pool(context.pool())
|
||||
.listing_type(Some(listing_type))
|
||||
|
|
@ -63,7 +62,7 @@ impl PerformApub for GetComments {
|
|||
.community_id(community_id)
|
||||
.parent_path(parent_path_cloned)
|
||||
.post_id(post_id)
|
||||
.local_user(local_user.as_ref())
|
||||
.local_user(local_user_view.as_ref())
|
||||
.page(page)
|
||||
.limit(limit)
|
||||
.build()
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ impl PerformApub for GetPosts {
|
|||
|
||||
let posts = PostQuery::builder()
|
||||
.pool(context.pool())
|
||||
.local_user(local_user_view.map(|l| l.local_user).as_ref())
|
||||
.local_user(local_user_view.as_ref())
|
||||
.listing_type(Some(listing_type))
|
||||
.sort(sort)
|
||||
.community_id(community_id)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use activitypub_federation::config::Data;
|
|||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::{GetPersonDetails, GetPersonDetailsResponse},
|
||||
utils::{check_private_instance, is_admin, local_user_view_from_jwt_opt},
|
||||
utils::{check_private_instance, local_user_view_from_jwt_opt},
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{local_site::LocalSite, person::Person},
|
||||
|
|
@ -31,7 +31,6 @@ impl PerformApub for GetPersonDetails {
|
|||
|
||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
||||
|
||||
check_private_instance(&local_user_view, &local_site)?;
|
||||
|
||||
|
|
@ -60,18 +59,14 @@ impl PerformApub for GetPersonDetails {
|
|||
let limit = data.limit;
|
||||
let saved_only = data.saved_only;
|
||||
let community_id = data.community_id;
|
||||
let local_user = local_user_view.as_ref().map(|l| l.local_user.clone());
|
||||
let local_user_clone = local_user.clone();
|
||||
let is_own_profile = Some(Some(person_details_id) == local_user_view.map(|l| l.person.id));
|
||||
|
||||
let posts_query = PostQuery::builder()
|
||||
.pool(context.pool())
|
||||
.sort(sort)
|
||||
.saved_only(saved_only)
|
||||
.local_user(local_user.as_ref())
|
||||
.local_user(local_user_view.as_ref())
|
||||
.community_id(community_id)
|
||||
.show_removed(is_admin)
|
||||
.show_deleted(is_own_profile)
|
||||
.is_profile_view(Some(true))
|
||||
.page(page)
|
||||
.limit(limit);
|
||||
|
||||
|
|
@ -89,11 +84,10 @@ impl PerformApub for GetPersonDetails {
|
|||
|
||||
let comments_query = CommentQuery::builder()
|
||||
.pool(context.pool())
|
||||
.local_user(local_user_clone.as_ref())
|
||||
.local_user(local_user_view.as_ref())
|
||||
.sort(sort.map(post_to_comment_sort_type))
|
||||
.saved_only(saved_only)
|
||||
.show_removed(is_admin)
|
||||
.show_deleted(is_own_profile)
|
||||
.is_profile_view(Some(true))
|
||||
.community_id(community_id)
|
||||
.page(page)
|
||||
.limit(limit);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl PerformApub for Search {
|
|||
data.community_id
|
||||
};
|
||||
let creator_id = data.creator_id;
|
||||
let local_user = local_user_view.map(|l| l.local_user);
|
||||
let local_user = local_user_view.as_ref().map(|l| l.local_user.clone());
|
||||
match search_type {
|
||||
SearchType::Posts => {
|
||||
posts = PostQuery::builder()
|
||||
|
|
@ -64,7 +64,7 @@ impl PerformApub for Search {
|
|||
.listing_type(listing_type)
|
||||
.community_id(community_id)
|
||||
.creator_id(creator_id)
|
||||
.local_user(local_user.as_ref())
|
||||
.local_user(local_user_view.as_ref())
|
||||
.search_term(Some(q))
|
||||
.page(page)
|
||||
.limit(limit)
|
||||
|
|
@ -80,7 +80,7 @@ impl PerformApub for Search {
|
|||
.search_term(Some(q))
|
||||
.community_id(community_id)
|
||||
.creator_id(creator_id)
|
||||
.local_user(local_user.as_ref())
|
||||
.local_user(local_user_view.as_ref())
|
||||
.page(page)
|
||||
.limit(limit)
|
||||
.build()
|
||||
|
|
@ -117,14 +117,13 @@ impl PerformApub for Search {
|
|||
let community_or_creator_included =
|
||||
data.community_id.is_some() || data.community_name.is_some() || data.creator_id.is_some();
|
||||
|
||||
let local_user_ = local_user.clone();
|
||||
posts = PostQuery::builder()
|
||||
.pool(context.pool())
|
||||
.sort(sort)
|
||||
.listing_type(listing_type)
|
||||
.community_id(community_id)
|
||||
.creator_id(creator_id)
|
||||
.local_user(local_user_.as_ref())
|
||||
.local_user(local_user_view.as_ref())
|
||||
.search_term(Some(q))
|
||||
.page(page)
|
||||
.limit(limit)
|
||||
|
|
@ -134,7 +133,6 @@ impl PerformApub for Search {
|
|||
|
||||
let q = data.q.clone();
|
||||
|
||||
let local_user_ = local_user.clone();
|
||||
comments = CommentQuery::builder()
|
||||
.pool(context.pool())
|
||||
.sort(sort.map(post_to_comment_sort_type))
|
||||
|
|
@ -142,7 +140,7 @@ impl PerformApub for Search {
|
|||
.search_term(Some(q))
|
||||
.community_id(community_id)
|
||||
.creator_id(creator_id)
|
||||
.local_user(local_user_.as_ref())
|
||||
.local_user(local_user_view.as_ref())
|
||||
.page(page)
|
||||
.limit(limit)
|
||||
.build()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::structs::CommentView;
|
||||
use crate::structs::{CommentView, LocalUserView};
|
||||
use diesel::{
|
||||
result::Error,
|
||||
BoolExpressionMethods,
|
||||
|
|
@ -30,7 +30,6 @@ use lemmy_db_schema::{
|
|||
source::{
|
||||
comment::{Comment, CommentSaved},
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
local_user::LocalUser,
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
post::Post,
|
||||
|
|
@ -167,11 +166,10 @@ pub struct CommentQuery<'a> {
|
|||
post_id: Option<PostId>,
|
||||
parent_path: Option<Ltree>,
|
||||
creator_id: Option<PersonId>,
|
||||
local_user: Option<&'a LocalUser>,
|
||||
local_user: Option<&'a LocalUserView>,
|
||||
search_term: Option<String>,
|
||||
saved_only: Option<bool>,
|
||||
show_deleted: Option<bool>,
|
||||
show_removed: Option<bool>,
|
||||
is_profile_view: Option<bool>,
|
||||
page: Option<i64>,
|
||||
limit: Option<i64>,
|
||||
max_depth: Option<i32>,
|
||||
|
|
@ -182,8 +180,11 @@ impl<'a> CommentQuery<'a> {
|
|||
let conn = &mut get_conn(self.pool).await?;
|
||||
|
||||
// The left join below will return None in this case
|
||||
let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
|
||||
let local_user_id_join = self.local_user.map(|l| l.id).unwrap_or(LocalUserId(-1));
|
||||
let person_id_join = self.local_user.map(|l| l.person.id).unwrap_or(PersonId(-1));
|
||||
let local_user_id_join = self
|
||||
.local_user
|
||||
.map(|l| l.local_user.id)
|
||||
.unwrap_or(LocalUserId(-1));
|
||||
|
||||
let mut query = comment::table
|
||||
.inner_join(person::table)
|
||||
|
|
@ -299,15 +300,24 @@ impl<'a> CommentQuery<'a> {
|
|||
query = query.filter(comment_saved::comment_id.is_not_null());
|
||||
}
|
||||
|
||||
if !self.show_deleted.unwrap_or(false) {
|
||||
let is_profile_view = self.is_profile_view.unwrap_or(false);
|
||||
let is_creator = self.creator_id == self.local_user.map(|l| l.person.id);
|
||||
// only show deleted posts to creator when viewing own profile
|
||||
if !is_profile_view || !is_creator {
|
||||
query = query.filter(comment::deleted.eq(false));
|
||||
}
|
||||
|
||||
if !self.show_removed.unwrap_or(false) {
|
||||
let is_admin = self.local_user.map(|l| l.person.admin).unwrap_or(false);
|
||||
// only show removed posts to admin when viewing user profile
|
||||
if !is_profile_view || !is_admin {
|
||||
query = query.filter(comment::removed.eq(false));
|
||||
}
|
||||
|
||||
if !self.local_user.map(|l| l.show_bot_accounts).unwrap_or(true) {
|
||||
if !self
|
||||
.local_user
|
||||
.map(|l| l.local_user.show_bot_accounts)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
query = query.filter(person::bot_account.eq(false));
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::structs::PostView;
|
||||
use crate::structs::{LocalUserView, PostView};
|
||||
use diesel::{
|
||||
debug_query,
|
||||
dsl::{now, IntervalDsl},
|
||||
|
|
@ -34,7 +34,6 @@ use lemmy_db_schema::{
|
|||
},
|
||||
source::{
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
local_user::LocalUser,
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
post::{Post, PostRead, PostSaved},
|
||||
|
|
@ -202,12 +201,11 @@ pub struct PostQuery<'a> {
|
|||
sort: Option<SortType>,
|
||||
creator_id: Option<PersonId>,
|
||||
community_id: Option<CommunityId>,
|
||||
local_user: Option<&'a LocalUser>,
|
||||
local_user: Option<&'a LocalUserView>,
|
||||
search_term: Option<String>,
|
||||
url_search: Option<String>,
|
||||
saved_only: Option<bool>,
|
||||
show_removed: Option<bool>,
|
||||
show_deleted: Option<bool>,
|
||||
is_profile_view: Option<bool>,
|
||||
page: Option<i64>,
|
||||
limit: Option<i64>,
|
||||
}
|
||||
|
|
@ -217,8 +215,11 @@ impl<'a> PostQuery<'a> {
|
|||
let conn = &mut get_conn(self.pool).await?;
|
||||
|
||||
// The left join below will return None in this case
|
||||
let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
|
||||
let local_user_id_join = self.local_user.map(|l| l.id).unwrap_or(LocalUserId(-1));
|
||||
let person_id_join = self.local_user.map(|l| l.person.id).unwrap_or(PersonId(-1));
|
||||
let local_user_id_join = self
|
||||
.local_user
|
||||
.map(|l| l.local_user.id)
|
||||
.unwrap_or(LocalUserId(-1));
|
||||
|
||||
let mut query = post::table
|
||||
.inner_join(person::table)
|
||||
|
|
@ -305,13 +306,18 @@ impl<'a> PostQuery<'a> {
|
|||
))
|
||||
.into_boxed();
|
||||
|
||||
if !self.show_deleted.unwrap_or(false) {
|
||||
let is_profile_view = self.is_profile_view.unwrap_or(false);
|
||||
let is_creator = self.creator_id == self.local_user.map(|l| l.person.id);
|
||||
// only show deleted posts to creator when viewing own profile
|
||||
if !is_profile_view || !is_creator {
|
||||
query = query
|
||||
.filter(community::deleted.eq(false))
|
||||
.filter(post::deleted.eq(false));
|
||||
}
|
||||
|
||||
if !self.show_removed.unwrap_or(false) {
|
||||
let is_admin = self.local_user.map(|l| l.person.admin).unwrap_or(false);
|
||||
// only show removed posts to admin when viewing user profile
|
||||
if !is_profile_view || !is_admin {
|
||||
query = query
|
||||
.filter(community::removed.eq(false))
|
||||
.filter(post::removed.eq(false));
|
||||
|
|
@ -364,13 +370,21 @@ impl<'a> PostQuery<'a> {
|
|||
);
|
||||
}
|
||||
|
||||
if !self.local_user.map(|l| l.show_nsfw).unwrap_or(false) {
|
||||
if !self
|
||||
.local_user
|
||||
.map(|l| l.local_user.show_nsfw)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
query = query
|
||||
.filter(post::nsfw.eq(false))
|
||||
.filter(community::nsfw.eq(false));
|
||||
};
|
||||
|
||||
if !self.local_user.map(|l| l.show_bot_accounts).unwrap_or(true) {
|
||||
if !self
|
||||
.local_user
|
||||
.map(|l| l.local_user.show_bot_accounts)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
query = query.filter(person::bot_account.eq(false));
|
||||
};
|
||||
|
||||
|
|
@ -379,7 +393,11 @@ impl<'a> PostQuery<'a> {
|
|||
}
|
||||
// Only hide the read posts, if the saved_only is false. Otherwise ppl with the hide_read
|
||||
// setting wont be able to see saved posts.
|
||||
else if !self.local_user.map(|l| l.show_read_posts).unwrap_or(true) {
|
||||
else if !self
|
||||
.local_user
|
||||
.map(|l| l.local_user.show_read_posts)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
query = query.filter(post_read::post_id.is_null());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use lemmy_db_schema::{
|
|||
};
|
||||
use lemmy_db_views::{
|
||||
post_view::PostQuery,
|
||||
structs::{PostView, SiteView},
|
||||
structs::{LocalUserView, PostView, SiteView},
|
||||
};
|
||||
use lemmy_db_views_actor::{
|
||||
comment_reply_view::CommentReplyQuery,
|
||||
|
|
@ -310,7 +310,7 @@ async fn get_feed_front(
|
|||
) -> Result<ChannelBuilder, LemmyError> {
|
||||
let site_view = SiteView::read_local(pool).await?;
|
||||
let local_user_id = LocalUserId(Claims::decode(jwt, jwt_secret)?.claims.sub);
|
||||
let local_user = LocalUser::read(pool, local_user_id).await?;
|
||||
let local_user = LocalUserView::read(pool, local_user_id).await?;
|
||||
|
||||
let posts = PostQuery::builder()
|
||||
.pool(pool)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue