- .select((
- person_mention::all_columns,
- comment::all_columns,
- person::all_columns,
- post::all_columns,
- community::all_columns,
- person_alias_1.fields(person::all_columns),
- comment_aggregates::all_columns,
- community_person_ban::all_columns.nullable(),
- community_follower::all_columns.nullable(),
- comment_saved::all_columns.nullable(),
- person_block::all_columns.nullable(),
- comment_like::score.nullable(),
- ))
- .first::<PersonMentionViewTuple>(conn)
- .await?;
-
- Ok(PersonMentionView {
- person_mention,
- comment,
- creator,
- post,
- community,
- recipient,
- counts,
- creator_banned_from_community: creator_banned_from_community.is_some(),
- subscribed: CommunityFollower::to_subscribed_type(&follower),
- saved: saved.is_some(),
- creator_blocked: creator_blocked.is_some(),
- my_vote,
- })
- }
-
- /// Gets the number of unread mentions
- pub async fn get_unread_mentions(
- pool: &mut DbPool<'_>,
- my_person_id: PersonId,
- ) -> Result<i64, Error> {
- use diesel::dsl::count;
- let conn = &mut get_conn(pool).await?;
-
- person_mention::table
- .inner_join(comment::table)
- .filter(person_mention::recipient_id.eq(my_person_id))
- .filter(person_mention::read.eq(false))
- .filter(comment::deleted.eq(false))
- .filter(comment::removed.eq(false))
- .select(count(person_mention::id))
- .first::<i64>(conn)
+ };
+
+ 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::all_columns.nullable(),
+ community_follower::all_columns.nullable(),
+ comment_saved::all_columns.nullable(),
+ person_block::all_columns.nullable(),
+ 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,
+ )
+ .left_join(
+ community_person_ban::table.on(
+ community::id
+ .eq(community_person_ban::community_id)
+ .and(community_person_ban::person_id.eq(comment::creator_id)),
+ ),
+ )
+ .select(selection)
+ .first::<PersonMentionViewTuple>(&mut conn)