let local_user_view =
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.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 local_user = local_user_view.map(|l| l.local_user);
let mut posts = Vec::new();
let mut comments = Vec::new();
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
- .my_person_id(person_id)
+ .local_user(local_user.as_ref())
.search_term(Some(q))
.page(page)
.limit(limit)
.sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type)
.search_term(Some(q))
- .show_bot_accounts(show_bot_accounts)
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
- .my_person_id(person_id)
+ .local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
.sort(sort)
.listing_type(listing_type)
.search_term(Some(q))
- .my_person_id(person_id)
+ .local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
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 local_user_ = local_user.clone();
posts = blocking(context.pool(), move |conn| {
PostQuery::builder()
.conn(conn)
.community_id(community_id)
.community_actor_id(community_actor_id_2)
.creator_id(creator_id)
- .my_person_id(person_id)
+ .local_user(local_user_.as_ref())
.search_term(Some(q))
.page(page)
.limit(limit)
let q = data.q.to_owned();
let community_actor_id = community_actor_id.to_owned();
+ let local_user_ = local_user.clone();
comments = blocking(context.pool(), move |conn| {
CommentQuery::builder()
.conn(conn)
.sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type)
.search_term(Some(q))
- .show_bot_accounts(show_bot_accounts)
.community_id(community_id)
.community_actor_id(community_actor_id)
.creator_id(creator_id)
- .my_person_id(person_id)
+ .local_user(local_user_.as_ref())
.page(page)
.limit(limit)
.build()
.sort(sort)
.listing_type(listing_type)
.search_term(Some(q))
- .my_person_id(person_id)
+ .local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
let local_user_view =
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.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 listing_type = listing_type_with_site_default(data.type_, context.pool()).await?;
};
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| {
CommentQuery::builder()
.conn(conn)
.community_actor_id(community_actor_id)
.parent_path(parent_path)
.post_id(post_id)
- .my_person_id(person_id)
- .show_bot_accounts(show_bot_accounts)
+ .local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
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 listing_type = data.type_;
let page = data.page;
let limit = data.limit;
+ let local_user = local_user_view.map(|l| l.local_user);
let mut communities = blocking(context.pool(), move |conn| {
CommunityQuery::builder()
.conn(conn)
.listing_type(listing_type)
.sort(sort)
- .show_nsfw(Some(show_nsfw))
- .my_person_id(person_id)
+ .local_user(local_user.as_ref())
.page(page)
.limit(limit)
.build()
let local_user_view =
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.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 {
Some(id) => id,
None => {
.page(page)
.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()
.conn(conn)
- .my_person_id(person_id)
- .show_bot_accounts(show_bot_accounts)
+ .local_user(local_user.as_ref())
.sort(sort.map(post_to_comment_sort_type))
.saved_only(saved_only)
.community_id(community_id)
source::{
comment::{Comment, CommentSaved},
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
+ local_user::LocalUser,
person::{Person, PersonSafe},
person_block::PersonBlock,
post::Post,
post_id: Option<PostId>,
parent_path: Option<Ltree>,
creator_id: Option<PersonId>,
- my_person_id: Option<PersonId>,
+ local_user: Option<&'a LocalUser>,
search_term: Option<String>,
saved_only: Option<bool>,
- show_bot_accounts: Option<bool>,
page: Option<i64>,
limit: Option<i64>,
max_depth: Option<i32>,
use diesel::dsl::*;
// 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
.inner_join(person::table)
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));
};
// 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(person_block::person_id.is_null());
}
use crate::comment_view::*;
use lemmy_db_schema::{
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},
utils::establish_unpooled_connection,
SubscribedType,
public_key: Some("pubkey".to_string()),
..PersonForm::default()
};
-
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 {
name: "sara".into(),
public_key: Some("pubkey".to_string()),
..PersonForm::default()
};
-
let inserted_person_2 = Person::create(&conn, &new_person_2).unwrap();
let new_community = CommunityForm {
let read_comment_views_with_person = CommentQuery::builder()
.conn(&conn)
.post_id(Some(inserted_post.id))
- .my_person_id(Some(inserted_person.id))
+ .local_user(Some(&inserted_local_user))
.build()
.list()
.unwrap();
source::{
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
language::Language,
+ local_user::LocalUser,
person::{Person, PersonSafe},
person_block::PersonBlock,
post::{Post, PostRead, PostSaved},
creator_id: Option<PersonId>,
community_id: Option<CommunityId>,
community_actor_id: Option<DbUrl>,
- my_person_id: Option<PersonId>,
- my_local_user_id: Option<LocalUserId>,
+ local_user: Option<&'a LocalUser>,
search_term: Option<String>,
url_search: Option<String>,
- show_nsfw: Option<bool>,
- show_bot_accounts: Option<bool>,
- show_read_posts: Option<bool>,
saved_only: Option<bool>,
page: Option<i64>,
limit: Option<i64>,
use diesel::dsl::*;
// The left join below will return None in this case
- let person_id_join = self.my_person_id.unwrap_or(PersonId(-1));
- let local_user_id_join = self.my_local_user_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.id).unwrap_or(LocalUserId(-1));
let mut query = post::table
.inner_join(person::table)
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
.filter(post::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));
};
}
// 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.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());
}
- // Filter out the rows with missing languages
- if self.my_local_user_id.is_some() {
+ if self.local_user.is_some() {
+ // Filter out the rows with missing languages
query = query.filter(local_user_language::id.is_not_null());
- }
- // Don't show blocked communities or persons
- if self.my_person_id.is_some() {
+ // Don't show blocked communities or persons
query = query.filter(community_block::person_id.is_null());
query = query.filter(person_block::person_id.is_null());
}
struct Data {
inserted_person: Person,
+ inserted_local_user: LocalUser,
inserted_blocked_person: Person,
inserted_bot: Person,
inserted_community: Community,
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 {
name: "mybot".to_string(),
bot_account: Some(true),
Data {
inserted_person,
+ inserted_local_user,
inserted_blocked_person,
inserted_bot,
inserted_community,
let conn = establish_unpooled_connection();
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()
.conn(&conn)
.sort(Some(SortType::New))
.community_id(Some(data.inserted_community.id))
- .show_bot_accounts(Some(false))
- .my_person_id(Some(data.inserted_person.id))
+ .local_user(Some(&inserted_local_user))
.build()
.list()
.unwrap();
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()
.conn(&conn)
.sort(Some(SortType::New))
.community_id(Some(data.inserted_community.id))
- .show_bot_accounts(Some(true))
- .my_person_id(Some(data.inserted_person.id))
+ .local_user(Some(&inserted_local_user))
.build()
.list()
.unwrap();
.conn(&conn)
.sort(Some(SortType::New))
.community_id(Some(data.inserted_community.id))
- .show_bot_accounts(Some(true))
- .my_person_id(Some(data.inserted_person.id))
+ .local_user(Some(&data.inserted_local_user))
.build()
.list()
.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()
.conn(&conn)
.sort(Some(SortType::New))
- .show_bot_accounts(Some(true))
- .my_person_id(Some(my_person.id))
- .my_local_user_id(Some(local_user.id))
+ .local_user(Some(&data.inserted_local_user))
.build()
.list()
.unwrap();
// 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();
- 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()
.conn(&conn)
.sort(Some(SortType::New))
- .show_bot_accounts(Some(true))
- .my_person_id(Some(my_person.id))
- .my_local_user_id(Some(local_user.id))
+ .local_user(Some(&data.inserted_local_user))
.build()
.list()
.unwrap();
LocalUserLanguage::update_user_languages(
&conn,
Some(vec![french_id, undetermined_id]),
- local_user.id,
+ data.inserted_local_user.id,
)
.unwrap();
let post_listings_french_und = PostQuery::builder()
.conn(&conn)
.sort(Some(SortType::New))
- .show_bot_accounts(Some(true))
- .my_person_id(Some(my_person.id))
- .my_local_user_id(Some(local_user.id))
+ .local_user(Some(&data.inserted_local_user))
.build()
.list()
.unwrap();
source::{
community::{Community, CommunityFollower, CommunitySafe},
community_block::CommunityBlock,
+ local_user::LocalUser,
},
traits::{ToSafe, ViewToVec},
utils::{functions::hot_rank, fuzzy_search, limit_and_offset},
conn: &'a PgConnection,
listing_type: Option<ListingType>,
sort: Option<SortType>,
- my_person_id: Option<PersonId>,
- show_nsfw: Option<bool>,
+ local_user: Option<&'a LocalUser>,
search_term: Option<String>,
page: Option<i64>,
limit: Option<i64>,
impl<'a> CommunityQuery<'a> {
pub fn list(self) -> Result<Vec<CommunityView>, Error> {
// 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
.inner_join(community_aggregates::table)
}
// 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::nsfw.eq(false).or(local_user::show_nsfw.eq(true)));
} else {
// 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));
}
}
let posts = PostQuery::builder()
.conn(conn)
.listing_type(Some(ListingType::Subscribed))
- .my_person_id(Some(local_user.person_id))
- .show_bot_accounts(Some(local_user.show_bot_accounts))
- .show_read_posts(Some(local_user.show_read_posts))
+ .local_user(Some(&local_user))
.sort(Some(*sort_type))
.limit(Some(RSS_FETCH_LIMIT))
.build()