- .select((
- comment_report::all_columns,
- comment::all_columns,
- post::all_columns,
- community::all_columns,
- person::all_columns,
- person_alias_1.fields(person::all_columns),
- comment_aggregates::all_columns,
- community_person_ban::all_columns.nullable(),
- comment_like::score.nullable(),
- person_alias_2.fields(person::all_columns).nullable(),
- ))
- .first::<<CommentReportView as JoinView>::JoinTuple>(conn)
- .await?;
-
- Ok(Self::from_tuple(res))
+ };
+
+ let selection = (
+ comment_report::all_columns,
+ comment::all_columns,
+ post::all_columns,
+ community::all_columns,
+ person::all_columns,
+ aliases::person1.fields(person::all_columns),
+ comment_aggregates::all_columns,
+ community_person_ban::id.nullable().is_not_null(),
+ comment_like::score.nullable(),
+ aliases::person2.fields(person::all_columns).nullable(),
+ );
+
+ let read = move |mut conn: DbConn<'a>, (report_id, my_person_id): (CommentReportId, PersonId)| async move {
+ all_joins(
+ comment_report::table.find(report_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::<<CommentReportView as JoinView>::JoinTuple>(&mut conn)
+ .await
+ };
+
+ let list = move |mut conn: DbConn<'a>, (options, my_person): (CommentReportQuery, &'a Person)| async move {
+ let mut query = all_joins(comment_report::table.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))
+ .and(
+ community_person_ban::expires
+ .is_null()
+ .or(community_person_ban::expires.gt(now)),
+ ),
+ ),
+ )
+ .select(selection);
+
+ if let Some(community_id) = options.community_id {
+ query = query.filter(post::community_id.eq(community_id));
+ }
+
+ if options.unresolved_only {
+ query = query.filter(comment_report::resolved.eq(false));
+ }
+
+ let (limit, offset) = limit_and_offset(options.page, options.limit)?;
+
+ query = query
+ .order_by(comment_report::published.desc())
+ .limit(limit)
+ .offset(offset);
+
+ // If its not an admin, get only the ones you mod
+ if !my_person.admin {
+ query
+ .inner_join(
+ community_moderator::table.on(
+ community_moderator::community_id
+ .eq(post::community_id)
+ .and(community_moderator::person_id.eq(my_person.id)),
+ ),
+ )
+ .load::<<CommentReportView as JoinView>::JoinTuple>(&mut conn)
+ .await
+ } else {
+ query
+ .load::<<CommentReportView as JoinView>::JoinTuple>(&mut conn)
+ .await
+ }
+ };
+
+ Queries::new(read, list)
+}
+
+impl CommentReportView {
+ /// returns the CommentReportView for the provided report_id
+ ///
+ /// * `report_id` - the report id to obtain
+ pub async fn read(
+ pool: &mut DbPool<'_>,
+ report_id: CommentReportId,
+ my_person_id: PersonId,
+ ) -> Result<Self, Error> {
+ queries().read(pool, (report_id, my_person_id)).await