-impl<'a> CommentReportQuery<'a> {
- pub fn list(self) -> Result<Vec<CommentReportView>, Error> {
- let mut query = comment_report::table
- .inner_join(comment::table)
- .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::table.on(comment_report::creator_id.eq(person::id)))
- .inner_join(person_alias_1::table.on(comment::creator_id.eq(person_alias_1::id)))
- .inner_join(
- comment_aggregates::table.on(comment_report::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(
- comment_like::table.on(
- comment::id
- .eq(comment_like::comment_id)
- .and(comment_like::person_id.eq(self.my_person_id)),
- ),
- )
- .left_join(
- person_alias_2::table.on(comment_report::resolver_id.eq(person_alias_2::id.nullable())),
- )
- .select((
- comment_report::all_columns,
- comment::all_columns,
- post::all_columns,
- Community::safe_columns_tuple(),
- Person::safe_columns_tuple(),
- PersonAlias1::safe_columns_tuple(),
- comment_aggregates::all_columns,
- community_person_ban::all_columns.nullable(),
- comment_like::score.nullable(),
- PersonAlias2::safe_columns_tuple().nullable(),
- ))
- .into_boxed();
-
- if let Some(community_id) = self.community_id {
- query = query.filter(post::community_id.eq(community_id));
- }
-
- if self.unresolved_only.unwrap_or(true) {
- query = query.filter(comment_report::resolved.eq(false));
- }
-
- let (limit, offset) = limit_and_offset(self.page, self.limit)?;
-
- query = query
- .order_by(comment_report::published.desc())
- .limit(limit)
- .offset(offset);
-
- // If its not an admin, get only the ones you mod
- let res = if !self.admin {
- query
- .inner_join(
- community_moderator::table.on(
- community_moderator::community_id
- .eq(post::community_id)
- .and(community_moderator::person_id.eq(self.my_person_id)),
- ),
- )
- .load::<CommentReportViewTuple>(self.conn)?
- } else {
- query.load::<CommentReportViewTuple>(self.conn)?
- };
-
- Ok(CommentReportView::from_tuple_to_vec(res))