+ let selection = (
+ post::all_columns,
+ person::all_columns,
+ community::all_columns,
+ community_person_ban::id.nullable().is_not_null(),
+ post_aggregates::all_columns,
+ 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(),
+ post_aggregates::comments,
+ ),
+ );
+
+ let read =
+ move |mut conn: DbConn<'a>,
+ (post_id, my_person_id, is_mod_or_admin): (PostId, Option<PersonId>, bool)| async move {
+ // The left join below will return None in this case
+ let person_id_join = my_person_id.unwrap_or(PersonId(-1));
+
+ let mut query = all_joins(
+ post_aggregates::table
+ .filter(post_aggregates::post_id.eq(post_id))
+ .into_boxed(),
+ my_person_id,
+ )
+ .select(selection);
+
+ // Hide deleted and removed for non-admins or mods
+ if !is_mod_or_admin {
+ query = query
+ .filter(community::removed.eq(false))
+ .filter(post::removed.eq(false))
+ // users can see their own deleted posts
+ .filter(
+ community::deleted
+ .eq(false)
+ .or(post::creator_id.eq(person_id_join)),
+ )
+ .filter(
+ post::deleted
+ .eq(false)
+ .or(post::creator_id.eq(person_id_join)),
+ );
+ }