post_saved,
},
source::{
- community::{Community, CommunityFollower, CommunityPersonBan},
+ community::{Community, CommunityFollower},
person::Person,
- person_block::PersonBlock,
- post::{Post, PostRead, PostSaved},
+ post::Post,
},
traits::JoinView,
utils::{fuzzy_search, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn},
ListingType,
SortType,
+ SubscribedType,
};
use tracing::debug;
Post,
Person,
Community,
- Option<CommunityPersonBan>,
+ bool,
PostAggregates,
- Option<CommunityFollower>,
- Option<PostSaved>,
- Option<PostRead>,
- Option<PersonBlock>,
+ SubscribedType,
+ bool,
+ bool,
+ bool,
Option<i16>,
i64,
);
post::all_columns,
person::all_columns,
community::all_columns,
- community_person_ban::all_columns.nullable(),
+ community_person_ban::id.nullable().is_not_null(),
post_aggregates::all_columns,
- community_follower::all_columns.nullable(),
- post_saved::all_columns.nullable(),
- post_read::all_columns.nullable(),
- person_block::all_columns.nullable(),
+ CommunityFollower::select_subscribed_type(),
+ post_saved::id.nullable().is_not_null(),
+ post_read::id.nullable().is_not_null(),
+ person_block::id.nullable().is_not_null(),
post_like::score.nullable(),
coalesce(
post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(),
)
.select(selection);
- let is_profile_view = options.is_profile_view.unwrap_or(false);
let is_creator = options.creator_id == options.local_user.map(|l| l.person.id);
// only show deleted posts to creator
if is_creator {
let is_admin = options.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) {
+ if !(options.is_profile_view && is_admin) {
query = query
.filter(community::removed.eq(false))
.filter(post::removed.eq(false));
if let Some(listing_type) = options.listing_type {
match listing_type {
- ListingType::Subscribed => {
- query = query.filter(community_follower::person_id.is_not_null())
- }
+ ListingType::Subscribed => query = query.filter(community_follower::pending.is_not_null()),
ListingType::Local => {
query = query.filter(community::local.eq(true)).filter(
community::hidden
};
if options.saved_only.unwrap_or(false) {
- query = query.filter(post_saved::post_id.is_not_null());
+ query = query.filter(post_saved::id.is_not_null());
}
if options.moderator_view.unwrap_or(false) {
.map(|l| l.local_user.show_read_posts)
.unwrap_or(true)
{
- query = query.filter(post_read::post_id.is_null());
+ // Do not hide read posts when it is a user profile view
+ if !options.is_profile_view {
+ query = query.filter(post_read::post_id.is_null());
+ }
+ }
+
+ if options.liked_only.unwrap_or_default() {
+ query = query.filter(post_like::score.eq(1));
+ } else if options.disliked_only.unwrap_or_default() {
+ query = query.filter(post_like::score.eq(-1));
}
if options.local_user.is_some() {
pub search_term: Option<String>,
pub url_search: Option<String>,
pub saved_only: Option<bool>,
+ pub liked_only: Option<bool>,
+ pub disliked_only: Option<bool>,
pub moderator_view: Option<bool>,
- pub is_profile_view: Option<bool>,
+ pub is_profile_view: bool,
pub page: Option<i64>,
pub limit: Option<i64>,
}
post: a.0,
creator: a.1,
community: a.2,
- creator_banned_from_community: a.3.is_some(),
+ creator_banned_from_community: a.3,
counts: a.4,
- subscribed: CommunityFollower::to_subscribed_type(&a.5),
- saved: a.6.is_some(),
- read: a.7.is_some(),
- creator_blocked: a.8.is_some(),
+ subscribed: a.5,
+ saved: a.6,
+ read: a.7,
+ creator_blocked: a.8,
my_vote: a.9,
unread_comments: a.10,
}
assert_eq!(expected_post_with_upvote, read_post_listing[0]);
+ let read_liked_post_listing = PostQuery {
+ community_id: (Some(data.inserted_community.id)),
+ local_user: (Some(&data.local_user_view)),
+ liked_only: (Some(true)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ assert_eq!(read_post_listing, read_liked_post_listing);
+
+ let read_disliked_post_listing = PostQuery {
+ community_id: (Some(data.inserted_community.id)),
+ local_user: (Some(&data.local_user_view)),
+ disliked_only: (Some(true)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ assert!(read_disliked_post_listing.is_empty());
+
let like_removed =
PostLike::remove(pool, data.local_user_view.person.id, data.inserted_post.id)
.await
let post_listings_is_admin = PostQuery {
sort: Some(SortType::New),
local_user: Some(&data.local_user_view),
- is_profile_view: Some(true),
+ is_profile_view: true,
..Default::default()
}
.list(pool)