- .select((
- person_mention::all_columns,
- comment::all_columns,
- Person::safe_columns_tuple(),
- post::all_columns,
- Community::safe_columns_tuple(),
- PersonAlias1::safe_columns_tuple(),
- comment_aggregates::all_columns,
- community_person_ban::all_columns.nullable(),
- community_follower::all_columns.nullable(),
- comment_saved::all_columns.nullable(),
- comment_like::score.nullable(),
- ))
- .first::<PersonMentionViewTuple>(conn)?;
-
- Ok(PersonMentionView {
- person_mention,
- comment,
- creator,
- post,
- community,
- recipient,
- counts,
- creator_banned_from_community: creator_banned_from_community.is_some(),
- subscribed: subscribed.is_some(),
- saved: saved.is_some(),
- my_vote,
- })
- }
-}
-
-pub struct PersonMentionQueryBuilder<'a> {
- conn: &'a PgConnection,
- my_person_id: Option<i32>,
- recipient_id: Option<i32>,
- sort: &'a SortType,
- unread_only: bool,
- page: Option<i64>,
- limit: Option<i64>,
-}
-
-impl<'a> PersonMentionQueryBuilder<'a> {
- pub fn create(conn: &'a PgConnection) -> Self {
- PersonMentionQueryBuilder {
- conn,
- my_person_id: None,
- recipient_id: None,
- sort: &SortType::New,
- unread_only: false,
- page: None,
- limit: None,
- }
- }
-
- pub fn sort(mut self, sort: &'a SortType) -> Self {
- self.sort = sort;
- self
- }
-
- pub fn unread_only(mut self, unread_only: bool) -> Self {
- self.unread_only = unread_only;
- self
- }
-
- pub fn recipient_id<T: MaybeOptional<i32>>(mut self, recipient_id: T) -> Self {
- self.recipient_id = recipient_id.get_optional();
- self
- }
-
- pub fn my_person_id<T: MaybeOptional<i32>>(mut self, my_person_id: T) -> Self {
- self.my_person_id = my_person_id.get_optional();
- self
- }
-
- pub fn page<T: MaybeOptional<i64>>(mut self, page: T) -> Self {
- self.page = page.get_optional();
- self
- }
-
- pub fn limit<T: MaybeOptional<i64>>(mut self, limit: T) -> Self {
- self.limit = limit.get_optional();
- self
- }
-
- pub fn list(self) -> Result<Vec<PersonMentionView>, Error> {
- use diesel::dsl::*;
-
- // The left join below will return None in this case
- let person_id_join = self.my_person_id.unwrap_or(-1);
-
- let mut query = person_mention::table
- .inner_join(comment::table)
- .inner_join(person::table.on(comment::creator_id.eq(person::id)))
- .inner_join(post::table.on(comment::post_id.eq(post::id)))
- .inner_join(community::table.on(post::community_id.eq(community::id)))
- .inner_join(person_alias_1::table)
- .inner_join(comment_aggregates::table.on(comment::id.eq(comment_aggregates::comment_id)))
+ };
+
+ let selection = (
+ person_mention::all_columns,
+ comment::all_columns,
+ person::all_columns,
+ post::all_columns,
+ community::all_columns,
+ aliases::person1.fields(person::all_columns),
+ comment_aggregates::all_columns,
+ community_person_ban::id.nullable().is_not_null(),
+ CommunityFollower::select_subscribed_type(),
+ comment_saved::id.nullable().is_not_null(),
+ person_block::id.nullable().is_not_null(),
+ comment_like::score.nullable(),
+ );
+
+ let read =
+ move |mut conn: DbConn<'a>,
+ (person_mention_id, my_person_id): (PersonMentionId, Option<PersonId>)| async move {
+ all_joins(
+ person_mention::table.find(person_mention_id).into_boxed(),
+ my_person_id,
+ )