Pass LocalUser to PostQuery etc, instead of separate params (#2413)

This commit is contained in:
Nutomic 2022-08-19 14:27:39 +00:00 committed by GitHub
parent e4a49b6eab
commit a6dc6804aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 90 additions and 103 deletions

View file

@ -31,14 +31,10 @@ impl Perform for Search {
let local_user_view = let local_user_view =
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.await?; .await?;
check_private_instance(&local_user_view, context.pool()).await?; check_private_instance(&local_user_view, context.pool()).await?;
let show_bot_accounts = local_user_view
.as_ref()
.map(|t| t.local_user.show_bot_accounts);
let person_id = local_user_view.as_ref().map(|u| u.person.id); let person_id = local_user_view.as_ref().map(|u| u.person.id);
let local_user = local_user_view.map(|l| l.local_user);
let mut posts = Vec::new(); let mut posts = Vec::new();
let mut comments = Vec::new(); let mut comments = Vec::new();
@ -73,7 +69,7 @@ impl Perform for Search {
.community_id(community_id) .community_id(community_id)
.community_actor_id(community_actor_id) .community_actor_id(community_actor_id)
.creator_id(creator_id) .creator_id(creator_id)
.my_person_id(person_id) .local_user(local_user.as_ref())
.search_term(Some(q)) .search_term(Some(q))
.page(page) .page(page)
.limit(limit) .limit(limit)
@ -89,11 +85,10 @@ impl Perform for Search {
.sort(sort.map(post_to_comment_sort_type)) .sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type) .listing_type(listing_type)
.search_term(Some(q)) .search_term(Some(q))
.show_bot_accounts(show_bot_accounts)
.community_id(community_id) .community_id(community_id)
.community_actor_id(community_actor_id) .community_actor_id(community_actor_id)
.creator_id(creator_id) .creator_id(creator_id)
.my_person_id(person_id) .local_user(local_user.as_ref())
.page(page) .page(page)
.limit(limit) .limit(limit)
.build() .build()
@ -108,7 +103,7 @@ impl Perform for Search {
.sort(sort) .sort(sort)
.listing_type(listing_type) .listing_type(listing_type)
.search_term(Some(q)) .search_term(Some(q))
.my_person_id(person_id) .local_user(local_user.as_ref())
.page(page) .page(page)
.limit(limit) .limit(limit)
.build() .build()
@ -135,6 +130,7 @@ impl Perform for Search {
data.community_id.is_some() || data.community_name.is_some() || data.creator_id.is_some(); data.community_id.is_some() || data.community_name.is_some() || data.creator_id.is_some();
let community_actor_id_2 = community_actor_id.to_owned(); let community_actor_id_2 = community_actor_id.to_owned();
let local_user_ = local_user.clone();
posts = blocking(context.pool(), move |conn| { posts = blocking(context.pool(), move |conn| {
PostQuery::builder() PostQuery::builder()
.conn(conn) .conn(conn)
@ -143,7 +139,7 @@ impl Perform for Search {
.community_id(community_id) .community_id(community_id)
.community_actor_id(community_actor_id_2) .community_actor_id(community_actor_id_2)
.creator_id(creator_id) .creator_id(creator_id)
.my_person_id(person_id) .local_user(local_user_.as_ref())
.search_term(Some(q)) .search_term(Some(q))
.page(page) .page(page)
.limit(limit) .limit(limit)
@ -155,17 +151,17 @@ impl Perform for Search {
let q = data.q.to_owned(); let q = data.q.to_owned();
let community_actor_id = community_actor_id.to_owned(); let community_actor_id = community_actor_id.to_owned();
let local_user_ = local_user.clone();
comments = blocking(context.pool(), move |conn| { comments = blocking(context.pool(), move |conn| {
CommentQuery::builder() CommentQuery::builder()
.conn(conn) .conn(conn)
.sort(sort.map(post_to_comment_sort_type)) .sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type) .listing_type(listing_type)
.search_term(Some(q)) .search_term(Some(q))
.show_bot_accounts(show_bot_accounts)
.community_id(community_id) .community_id(community_id)
.community_actor_id(community_actor_id) .community_actor_id(community_actor_id)
.creator_id(creator_id) .creator_id(creator_id)
.my_person_id(person_id) .local_user(local_user_.as_ref())
.page(page) .page(page)
.limit(limit) .limit(limit)
.build() .build()
@ -184,7 +180,7 @@ impl Perform for Search {
.sort(sort) .sort(sort)
.listing_type(listing_type) .listing_type(listing_type)
.search_term(Some(q)) .search_term(Some(q))
.my_person_id(person_id) .local_user(local_user.as_ref())
.page(page) .page(page)
.limit(limit) .limit(limit)
.build() .build()

View file

@ -32,14 +32,8 @@ impl PerformCrud for GetComments {
let local_user_view = let local_user_view =
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.await?; .await?;
check_private_instance(&local_user_view, context.pool()).await?; check_private_instance(&local_user_view, context.pool()).await?;
let show_bot_accounts = local_user_view
.as_ref()
.map(|t| t.local_user.show_bot_accounts);
let person_id = local_user_view.map(|u| u.person.id);
let community_id = data.community_id; let community_id = data.community_id;
let listing_type = listing_type_with_site_default(data.type_, context.pool()).await?; let listing_type = listing_type_with_site_default(data.type_, context.pool()).await?;
@ -70,6 +64,7 @@ impl PerformCrud for GetComments {
}; };
let post_id = data.post_id; let post_id = data.post_id;
let local_user = local_user_view.map(|l| l.local_user);
let mut comments = blocking(context.pool(), move |conn| { let mut comments = blocking(context.pool(), move |conn| {
CommentQuery::builder() CommentQuery::builder()
.conn(conn) .conn(conn)
@ -81,8 +76,7 @@ impl PerformCrud for GetComments {
.community_actor_id(community_actor_id) .community_actor_id(community_actor_id)
.parent_path(parent_path) .parent_path(parent_path)
.post_id(post_id) .post_id(post_id)
.my_person_id(person_id) .local_user(local_user.as_ref())
.show_bot_accounts(show_bot_accounts)
.page(page) .page(page)
.limit(limit) .limit(limit)
.build() .build()

View file

@ -28,23 +28,17 @@ impl PerformCrud for ListCommunities {
let person_id = local_user_view.to_owned().map(|l| l.person.id); let person_id = local_user_view.to_owned().map(|l| l.person.id);
// Don't show NSFW by default
let show_nsfw = match &local_user_view {
Some(uv) => uv.local_user.show_nsfw,
None => false,
};
let sort = data.sort; let sort = data.sort;
let listing_type = data.type_; let listing_type = data.type_;
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let local_user = local_user_view.map(|l| l.local_user);
let mut communities = blocking(context.pool(), move |conn| { let mut communities = blocking(context.pool(), move |conn| {
CommunityQuery::builder() CommunityQuery::builder()
.conn(conn) .conn(conn)
.listing_type(listing_type) .listing_type(listing_type)
.sort(sort) .sort(sort)
.show_nsfw(Some(show_nsfw)) .local_user(local_user.as_ref())
.my_person_id(person_id)
.page(page) .page(page)
.limit(limit) .limit(limit)
.build() .build()

View file

@ -31,13 +31,8 @@ impl PerformCrud for GetPersonDetails {
let local_user_view = let local_user_view =
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret()) get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.await?; .await?;
check_private_instance(&local_user_view, context.pool()).await?; check_private_instance(&local_user_view, context.pool()).await?;
let show_bot_accounts = local_user_view
.as_ref()
.map(|t| t.local_user.show_bot_accounts);
let person_details_id = match data.person_id { let person_details_id = match data.person_id {
Some(id) => id, Some(id) => id,
None => { None => {
@ -76,11 +71,10 @@ impl PerformCrud for GetPersonDetails {
.page(page) .page(page)
.limit(limit); .limit(limit);
let person_id = local_user_view.map(|uv| uv.person.id); let local_user = local_user_view.map(|l| l.local_user);
let comments_query = CommentQuery::builder() let comments_query = CommentQuery::builder()
.conn(conn) .conn(conn)
.my_person_id(person_id) .local_user(local_user.as_ref())
.show_bot_accounts(show_bot_accounts)
.sort(sort.map(post_to_comment_sort_type)) .sort(sort.map(post_to_comment_sort_type))
.saved_only(saved_only) .saved_only(saved_only)
.community_id(community_id) .community_id(community_id)

View file

@ -20,6 +20,7 @@ use lemmy_db_schema::{
source::{ source::{
comment::{Comment, CommentSaved}, comment::{Comment, CommentSaved},
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe}, community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
local_user::LocalUser,
person::{Person, PersonSafe}, person::{Person, PersonSafe},
person_block::PersonBlock, person_block::PersonBlock,
post::Post, post::Post,
@ -159,10 +160,9 @@ pub struct CommentQuery<'a> {
post_id: Option<PostId>, post_id: Option<PostId>,
parent_path: Option<Ltree>, parent_path: Option<Ltree>,
creator_id: Option<PersonId>, creator_id: Option<PersonId>,
my_person_id: Option<PersonId>, local_user: Option<&'a LocalUser>,
search_term: Option<String>, search_term: Option<String>,
saved_only: Option<bool>, saved_only: Option<bool>,
show_bot_accounts: Option<bool>,
page: Option<i64>, page: Option<i64>,
limit: Option<i64>, limit: Option<i64>,
max_depth: Option<i32>, max_depth: Option<i32>,
@ -173,7 +173,7 @@ impl<'a> CommentQuery<'a> {
use diesel::dsl::*; use diesel::dsl::*;
// The left join below will return None in this case // The left join below will return None in this case
let person_id_join = self.my_person_id.unwrap_or(PersonId(-1)); let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
let mut query = comment::table let mut query = comment::table
.inner_join(person::table) .inner_join(person::table)
@ -291,12 +291,12 @@ impl<'a> CommentQuery<'a> {
query = query.filter(comment_saved::id.is_not_null()); query = query.filter(comment_saved::id.is_not_null());
} }
if !self.show_bot_accounts.unwrap_or(true) { if !self.local_user.map(|l| l.show_bot_accounts).unwrap_or(true) {
query = query.filter(person::bot_account.eq(false)); query = query.filter(person::bot_account.eq(false));
}; };
// Don't show blocked communities or persons // Don't show blocked communities or persons
if self.my_person_id.is_some() { if self.local_user.is_some() {
query = query.filter(community_block::person_id.is_null()); query = query.filter(community_block::person_id.is_null());
query = query.filter(person_block::person_id.is_null()); query = query.filter(person_block::person_id.is_null());
} }
@ -373,7 +373,14 @@ mod tests {
use crate::comment_view::*; use crate::comment_view::*;
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::CommentAggregates, aggregates::structs::CommentAggregates,
source::{comment::*, community::*, person::*, person_block::PersonBlockForm, post::*}, source::{
comment::*,
community::*,
local_user::LocalUserForm,
person::*,
person_block::PersonBlockForm,
post::*,
},
traits::{Blockable, Crud, Likeable}, traits::{Blockable, Crud, Likeable},
utils::establish_unpooled_connection, utils::establish_unpooled_connection,
SubscribedType, SubscribedType,
@ -390,15 +397,19 @@ mod tests {
public_key: Some("pubkey".to_string()), public_key: Some("pubkey".to_string()),
..PersonForm::default() ..PersonForm::default()
}; };
let inserted_person = Person::create(&conn, &new_person).unwrap(); let inserted_person = Person::create(&conn, &new_person).unwrap();
let local_user_form = LocalUserForm {
person_id: Some(inserted_person.id),
password_encrypted: Some("".to_string()),
..Default::default()
};
let inserted_local_user = LocalUser::create(&conn, &local_user_form).unwrap();
let new_person_2 = PersonForm { let new_person_2 = PersonForm {
name: "sara".into(), name: "sara".into(),
public_key: Some("pubkey".to_string()), public_key: Some("pubkey".to_string()),
..PersonForm::default() ..PersonForm::default()
}; };
let inserted_person_2 = Person::create(&conn, &new_person_2).unwrap(); let inserted_person_2 = Person::create(&conn, &new_person_2).unwrap();
let new_community = CommunityForm { let new_community = CommunityForm {
@ -622,7 +633,7 @@ mod tests {
let read_comment_views_with_person = CommentQuery::builder() let read_comment_views_with_person = CommentQuery::builder()
.conn(&conn) .conn(&conn)
.post_id(Some(inserted_post.id)) .post_id(Some(inserted_post.id))
.my_person_id(Some(inserted_person.id)) .local_user(Some(&inserted_local_user))
.build() .build()
.list() .list()
.unwrap(); .unwrap();

View file

@ -21,6 +21,7 @@ use lemmy_db_schema::{
source::{ source::{
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe}, community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
language::Language, language::Language,
local_user::LocalUser,
person::{Person, PersonSafe}, person::{Person, PersonSafe},
person_block::PersonBlock, person_block::PersonBlock,
post::{Post, PostRead, PostSaved}, post::{Post, PostRead, PostSaved},
@ -169,13 +170,9 @@ pub struct PostQuery<'a> {
creator_id: Option<PersonId>, creator_id: Option<PersonId>,
community_id: Option<CommunityId>, community_id: Option<CommunityId>,
community_actor_id: Option<DbUrl>, community_actor_id: Option<DbUrl>,
my_person_id: Option<PersonId>, local_user: Option<&'a LocalUser>,
my_local_user_id: Option<LocalUserId>,
search_term: Option<String>, search_term: Option<String>,
url_search: Option<String>, url_search: Option<String>,
show_nsfw: Option<bool>,
show_bot_accounts: Option<bool>,
show_read_posts: Option<bool>,
saved_only: Option<bool>, saved_only: Option<bool>,
page: Option<i64>, page: Option<i64>,
limit: Option<i64>, limit: Option<i64>,
@ -186,8 +183,8 @@ impl<'a> PostQuery<'a> {
use diesel::dsl::*; use diesel::dsl::*;
// The left join below will return None in this case // The left join below will return None in this case
let person_id_join = self.my_person_id.unwrap_or(PersonId(-1)); let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
let local_user_id_join = self.my_local_user_id.unwrap_or(LocalUserId(-1)); let local_user_id_join = self.local_user.map(|l| l.id).unwrap_or(LocalUserId(-1));
let mut query = post::table let mut query = post::table
.inner_join(person::table) .inner_join(person::table)
@ -322,13 +319,13 @@ impl<'a> PostQuery<'a> {
query = query.filter(post::creator_id.eq(creator_id)); query = query.filter(post::creator_id.eq(creator_id));
} }
if !self.show_nsfw.unwrap_or(false) { if !self.local_user.map(|l| l.show_nsfw).unwrap_or(false) {
query = query query = query
.filter(post::nsfw.eq(false)) .filter(post::nsfw.eq(false))
.filter(community::nsfw.eq(false)); .filter(community::nsfw.eq(false));
}; };
if !self.show_bot_accounts.unwrap_or(true) { if !self.local_user.map(|l| l.show_bot_accounts).unwrap_or(true) {
query = query.filter(person::bot_account.eq(false)); query = query.filter(person::bot_account.eq(false));
}; };
@ -337,17 +334,15 @@ impl<'a> PostQuery<'a> {
} }
// Only hide the read posts, if the saved_only is false. Otherwise ppl with the hide_read // 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. // setting wont be able to see saved posts.
else if !self.show_read_posts.unwrap_or(true) { else if !self.local_user.map(|l| l.show_read_posts).unwrap_or(true) {
query = query.filter(post_read::id.is_null()); query = query.filter(post_read::id.is_null());
} }
// Filter out the rows with missing languages if self.local_user.is_some() {
if self.my_local_user_id.is_some() { // Filter out the rows with missing languages
query = query.filter(local_user_language::id.is_not_null()); query = query.filter(local_user_language::id.is_not_null());
}
// Don't show blocked communities or persons // Don't show blocked communities or persons
if self.my_person_id.is_some() {
query = query.filter(community_block::person_id.is_null()); query = query.filter(community_block::person_id.is_null());
query = query.filter(person_block::person_id.is_null()); query = query.filter(person_block::person_id.is_null());
} }
@ -458,6 +453,7 @@ mod tests {
struct Data { struct Data {
inserted_person: Person, inserted_person: Person,
inserted_local_user: LocalUser,
inserted_blocked_person: Person, inserted_blocked_person: Person,
inserted_bot: Person, inserted_bot: Person,
inserted_community: Community, inserted_community: Community,
@ -475,6 +471,15 @@ mod tests {
let inserted_person = Person::create(conn, &new_person).unwrap(); let inserted_person = Person::create(conn, &new_person).unwrap();
let local_user_form = LocalUserForm {
person_id: Some(inserted_person.id),
password_encrypted: Some("".to_string()),
..Default::default()
};
let inserted_local_user = LocalUser::create(conn, &local_user_form).unwrap();
// update user languages to all
LocalUserLanguage::update_user_languages(conn, None, inserted_local_user.id).unwrap();
let new_bot = PersonForm { let new_bot = PersonForm {
name: "mybot".to_string(), name: "mybot".to_string(),
bot_account: Some(true), bot_account: Some(true),
@ -542,6 +547,7 @@ mod tests {
Data { Data {
inserted_person, inserted_person,
inserted_local_user,
inserted_blocked_person, inserted_blocked_person,
inserted_bot, inserted_bot,
inserted_community, inserted_community,
@ -658,12 +664,18 @@ mod tests {
let conn = establish_unpooled_connection(); let conn = establish_unpooled_connection();
let data = init_data(&conn); let data = init_data(&conn);
let local_user_form = LocalUserForm {
show_bot_accounts: Some(false),
..Default::default()
};
let inserted_local_user =
LocalUser::update(&conn, data.inserted_local_user.id, &local_user_form).unwrap();
let read_post_listing = PostQuery::builder() let read_post_listing = PostQuery::builder()
.conn(&conn) .conn(&conn)
.sort(Some(SortType::New)) .sort(Some(SortType::New))
.community_id(Some(data.inserted_community.id)) .community_id(Some(data.inserted_community.id))
.show_bot_accounts(Some(false)) .local_user(Some(&inserted_local_user))
.my_person_id(Some(data.inserted_person.id))
.build() .build()
.list() .list()
.unwrap(); .unwrap();
@ -683,12 +695,18 @@ mod tests {
post_listing_single_with_person post_listing_single_with_person
); );
let local_user_form = LocalUserForm {
show_bot_accounts: Some(true),
..Default::default()
};
let inserted_local_user =
LocalUser::update(&conn, data.inserted_local_user.id, &local_user_form).unwrap();
let post_listings_with_bots = PostQuery::builder() let post_listings_with_bots = PostQuery::builder()
.conn(&conn) .conn(&conn)
.sort(Some(SortType::New)) .sort(Some(SortType::New))
.community_id(Some(data.inserted_community.id)) .community_id(Some(data.inserted_community.id))
.show_bot_accounts(Some(true)) .local_user(Some(&inserted_local_user))
.my_person_id(Some(data.inserted_person.id))
.build() .build()
.list() .list()
.unwrap(); .unwrap();
@ -748,8 +766,7 @@ mod tests {
.conn(&conn) .conn(&conn)
.sort(Some(SortType::New)) .sort(Some(SortType::New))
.community_id(Some(data.inserted_community.id)) .community_id(Some(data.inserted_community.id))
.show_bot_accounts(Some(true)) .local_user(Some(&data.inserted_local_user))
.my_person_id(Some(data.inserted_person.id))
.build() .build()
.list() .list()
.unwrap(); .unwrap();
@ -806,44 +823,29 @@ mod tests {
Post::create(&conn, &post_spanish).unwrap(); Post::create(&conn, &post_spanish).unwrap();
let my_person_form = PersonForm {
name: "Reverie Toiba".to_string(),
public_key: Some("pubkey".to_string()),
..PersonForm::default()
};
let my_person = Person::create(&conn, &my_person_form).unwrap();
let local_user_form = LocalUserForm {
person_id: Some(my_person.id),
password_encrypted: Some("".to_string()),
..Default::default()
};
let local_user = LocalUser::create(&conn, &local_user_form).unwrap();
// Update the users languages to all
LocalUserLanguage::update_user_languages(&conn, None, local_user.id).unwrap();
let post_listings_all = PostQuery::builder() let post_listings_all = PostQuery::builder()
.conn(&conn) .conn(&conn)
.sort(Some(SortType::New)) .sort(Some(SortType::New))
.show_bot_accounts(Some(true)) .local_user(Some(&data.inserted_local_user))
.my_person_id(Some(my_person.id))
.my_local_user_id(Some(local_user.id))
.build() .build()
.list() .list()
.unwrap(); .unwrap();
// no language filters specified, all posts should be returned // no language filters specified, all posts should be returned
assert_eq!(4, post_listings_all.len()); assert_eq!(3, post_listings_all.len());
let french_id = Language::read_id_from_code(&conn, "fr").unwrap(); let french_id = Language::read_id_from_code(&conn, "fr").unwrap();
LocalUserLanguage::update_user_languages(&conn, Some(vec![french_id]), local_user.id).unwrap(); LocalUserLanguage::update_user_languages(
&conn,
Some(vec![french_id]),
data.inserted_local_user.id,
)
.unwrap();
let post_listing_french = PostQuery::builder() let post_listing_french = PostQuery::builder()
.conn(&conn) .conn(&conn)
.sort(Some(SortType::New)) .sort(Some(SortType::New))
.show_bot_accounts(Some(true)) .local_user(Some(&data.inserted_local_user))
.my_person_id(Some(my_person.id))
.my_local_user_id(Some(local_user.id))
.build() .build()
.list() .list()
.unwrap(); .unwrap();
@ -856,15 +858,13 @@ mod tests {
LocalUserLanguage::update_user_languages( LocalUserLanguage::update_user_languages(
&conn, &conn,
Some(vec![french_id, undetermined_id]), Some(vec![french_id, undetermined_id]),
local_user.id, data.inserted_local_user.id,
) )
.unwrap(); .unwrap();
let post_listings_french_und = PostQuery::builder() let post_listings_french_und = PostQuery::builder()
.conn(&conn) .conn(&conn)
.sort(Some(SortType::New)) .sort(Some(SortType::New))
.show_bot_accounts(Some(true)) .local_user(Some(&data.inserted_local_user))
.my_person_id(Some(my_person.id))
.my_local_user_id(Some(local_user.id))
.build() .build()
.list() .list()
.unwrap(); .unwrap();

View file

@ -7,6 +7,7 @@ use lemmy_db_schema::{
source::{ source::{
community::{Community, CommunityFollower, CommunitySafe}, community::{Community, CommunityFollower, CommunitySafe},
community_block::CommunityBlock, community_block::CommunityBlock,
local_user::LocalUser,
}, },
traits::{ToSafe, ViewToVec}, traits::{ToSafe, ViewToVec},
utils::{functions::hot_rank, fuzzy_search, limit_and_offset}, utils::{functions::hot_rank, fuzzy_search, limit_and_offset},
@ -99,8 +100,7 @@ pub struct CommunityQuery<'a> {
conn: &'a PgConnection, conn: &'a PgConnection,
listing_type: Option<ListingType>, listing_type: Option<ListingType>,
sort: Option<SortType>, sort: Option<SortType>,
my_person_id: Option<PersonId>, local_user: Option<&'a LocalUser>,
show_nsfw: Option<bool>,
search_term: Option<String>, search_term: Option<String>,
page: Option<i64>, page: Option<i64>,
limit: Option<i64>, limit: Option<i64>,
@ -109,7 +109,7 @@ pub struct CommunityQuery<'a> {
impl<'a> CommunityQuery<'a> { impl<'a> CommunityQuery<'a> {
pub fn list(self) -> Result<Vec<CommunityView>, Error> { pub fn list(self) -> Result<Vec<CommunityView>, Error> {
// The left join below will return None in this case // The left join below will return None in this case
let person_id_join = self.my_person_id.unwrap_or(PersonId(-1)); let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
let mut query = community::table let mut query = community::table
.inner_join(community_aggregates::table) .inner_join(community_aggregates::table)
@ -188,12 +188,12 @@ impl<'a> CommunityQuery<'a> {
} }
// Don't show blocked communities or nsfw communities if not enabled in profile // Don't show blocked communities or nsfw communities if not enabled in profile
if self.my_person_id.is_some() { if self.local_user.is_some() {
query = query.filter(community_block::person_id.is_null()); query = query.filter(community_block::person_id.is_null());
query = query.filter(community::nsfw.eq(false).or(local_user::show_nsfw.eq(true))); query = query.filter(community::nsfw.eq(false).or(local_user::show_nsfw.eq(true)));
} else { } else {
// No person in request, only show nsfw communities if show_nsfw passed into request // No person in request, only show nsfw communities if show_nsfw passed into request
if !self.show_nsfw.unwrap_or(false) { if !self.local_user.map(|l| l.show_nsfw).unwrap_or(false) {
query = query.filter(community::nsfw.eq(false)); query = query.filter(community::nsfw.eq(false));
} }
} }

View file

@ -256,9 +256,7 @@ fn get_feed_front(
let posts = PostQuery::builder() let posts = PostQuery::builder()
.conn(conn) .conn(conn)
.listing_type(Some(ListingType::Subscribed)) .listing_type(Some(ListingType::Subscribed))
.my_person_id(Some(local_user.person_id)) .local_user(Some(&local_user))
.show_bot_accounts(Some(local_user.show_bot_accounts))
.show_read_posts(Some(local_user.show_read_posts))
.sort(Some(*sort_type)) .sort(Some(*sort_type))
.limit(Some(RSS_FETCH_LIMIT)) .limit(Some(RSS_FETCH_LIMIT))
.build() .build()