-impl<'a> PostReportQuery<'a> {
- pub fn list(self) -> Result<Vec<PostReportView>, Error> {
- let mut query = post_report::table
- .inner_join(post::table)
- .inner_join(community::table.on(post::community_id.eq(community::id)))
- .inner_join(person::table.on(post_report::creator_id.eq(person::id)))
- .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
- .left_join(
- community_person_ban::table.on(
- post::community_id
- .eq(community_person_ban::community_id)
- .and(community_person_ban::person_id.eq(post::creator_id))
- .and(
- community_person_ban::expires
- .is_null()
- .or(community_person_ban::expires.gt(now)),
- ),
- ),
- )
- .left_join(
- post_like::table.on(
- post::id
- .eq(post_like::post_id)
- .and(post_like::person_id.eq(self.my_person_id)),
- ),
- )
- .inner_join(post_aggregates::table.on(post_report::post_id.eq(post_aggregates::post_id)))
- .left_join(
- person_alias_2::table.on(post_report::resolver_id.eq(person_alias_2::id.nullable())),
- )
- .select((
- post_report::all_columns,
- post::all_columns,
- Community::safe_columns_tuple(),
- Person::safe_columns_tuple(),
- PersonAlias1::safe_columns_tuple(),
- community_person_ban::all_columns.nullable(),
- post_like::score.nullable(),
- post_aggregates::all_columns,
- 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(post_report::resolved.eq(false));
- }
-
- let (limit, offset) = limit_and_offset(self.page, self.limit)?;
-
- query = query
- .order_by(post_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::<PostReportViewTuple>(self.conn)?
- } else {
- query.load::<PostReportViewTuple>(self.conn)?
- };
-
- Ok(PostReportView::from_tuple_to_vec(res))