- .first::<CommentReplyViewTuple>(conn)?;
-
- Ok(CommentReplyView {
- comment_reply,
- 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 replies
- pub fn get_unread_replies(conn: &mut PgConnection, my_person_id: PersonId) -> Result<i64, Error> {
- use diesel::dsl::*;
-
- comment_reply::table
- .filter(comment_reply::recipient_id.eq(my_person_id))
- .filter(comment_reply::read.eq(false))
- .select(count(comment_reply::id))
- .first::<i64>(conn)
- }
-}
-
-#[derive(TypedBuilder)]
-#[builder(field_defaults(default))]
-pub struct CommentReplyQuery<'a> {
- #[builder(!default)]
- conn: &'a mut PgConnection,
- my_person_id: Option<PersonId>,
- recipient_id: Option<PersonId>,
- sort: Option<CommentSortType>,
- unread_only: Option<bool>,
- show_bot_accounts: Option<bool>,
- page: Option<i64>,
- limit: Option<i64>,
-}
-
-impl<'a> CommentReplyQuery<'a> {
- pub fn list(self) -> Result<Vec<CommentReplyView>, Error> {
- use diesel::dsl::*;
-
- let person_alias_1 = diesel::alias!(person as person1);
-
- // The left join below will return None in this case
- let person_id_join = self.my_person_id.unwrap_or(PersonId(-1));
-
- let mut query = comment_reply::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)
- .inner_join(comment_aggregates::table.on(comment::id.eq(comment_aggregates::comment_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))
- .and(
- community_person_ban::expires
- .is_null()
- .or(community_person_ban::expires.gt(now)),
- ),
- ),
- )
- .left_join(
- community_follower::table.on(
- post::community_id
- .eq(community_follower::community_id)
- .and(community_follower::person_id.eq(person_id_join)),
- ),