- .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: &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)
- }
-}
-
-pub struct CommentReplyQueryBuilder<'a> {
- conn: &'a 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> CommentReplyQueryBuilder<'a> {
- pub fn create(conn: &'a PgConnection) -> Self {
- CommentReplyQueryBuilder {
- conn,
- my_person_id: None,
- recipient_id: None,
- sort: None,
- unread_only: None,
- show_bot_accounts: None,
- page: None,
- limit: None,
- }
- }
-
- pub fn sort<T: MaybeOptional<CommentSortType>>(mut self, sort: T) -> Self {
- self.sort = sort.get_optional();
- self
- }
-
- pub fn unread_only<T: MaybeOptional<bool>>(mut self, unread_only: T) -> Self {
- self.unread_only = unread_only.get_optional();
- self
- }
-
- pub fn show_bot_accounts<T: MaybeOptional<bool>>(mut self, show_bot_accounts: T) -> Self {
- self.show_bot_accounts = show_bot_accounts.get_optional();
- self
- }
-
- pub fn recipient_id<T: MaybeOptional<PersonId>>(mut self, recipient_id: T) -> Self {
- self.recipient_id = recipient_id.get_optional();
- self
- }
-
- pub fn my_person_id<T: MaybeOptional<PersonId>>(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<CommentReplyView>, Error> {
- use diesel::dsl::*;
-
- // 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::table)
- .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)),
- ),
- )
- .left_join(
- comment_saved::table.on(
- comment::id
- .eq(comment_saved::comment_id)
- .and(comment_saved::person_id.eq(person_id_join)),
- ),
- )
- .left_join(
- person_block::table.on(
- comment::creator_id
- .eq(person_block::target_id)
- .and(person_block::person_id.eq(person_id_join)),
- ),
- )
- .left_join(
- comment_like::table.on(
- comment::id
- .eq(comment_like::comment_id)
- .and(comment_like::person_id.eq(person_id_join)),
- ),