2022-04-13 18:12:25 +00:00
|
|
|
use crate::Perform;
|
|
|
|
use actix_web::web::Data;
|
|
|
|
use lemmy_api_common::{
|
|
|
|
comment::{ListCommentReports, ListCommentReportsResponse},
|
2022-11-28 14:29:33 +00:00
|
|
|
context::LemmyContext,
|
2023-05-25 14:50:07 +00:00
|
|
|
utils::local_user_view_from_jwt,
|
2022-04-13 18:12:25 +00:00
|
|
|
};
|
2022-08-04 19:30:17 +00:00
|
|
|
use lemmy_db_views::comment_report_view::CommentReportQuery;
|
2022-06-02 14:33:41 +00:00
|
|
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
2022-04-13 18:12:25 +00:00
|
|
|
|
|
|
|
/// Lists comment reports for a community if an id is supplied
|
|
|
|
/// or returns all comment reports for communities a user moderates
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl Perform for ListCommentReports {
|
|
|
|
type Response = ListCommentReportsResponse;
|
|
|
|
|
|
|
|
#[tracing::instrument(skip(context, _websocket_id))]
|
|
|
|
async fn perform(
|
|
|
|
&self,
|
|
|
|
context: &Data<LemmyContext>,
|
|
|
|
_websocket_id: Option<ConnectionId>,
|
|
|
|
) -> Result<ListCommentReportsResponse, LemmyError> {
|
|
|
|
let data: &ListCommentReports = self;
|
2023-05-25 14:50:07 +00:00
|
|
|
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
|
|
|
let person_id = local_user_view.person.id;
|
|
|
|
let admin = local_user_view.person.admin;
|
|
|
|
let community_id = data.community_id;
|
|
|
|
let unresolved_only = data.unresolved_only;
|
|
|
|
|
|
|
|
let page = data.page;
|
|
|
|
let limit = data.limit;
|
2022-11-09 10:05:00 +00:00
|
|
|
let comment_reports = CommentReportQuery::builder()
|
|
|
|
.pool(context.pool())
|
|
|
|
.my_person_id(person_id)
|
|
|
|
.admin(admin)
|
|
|
|
.community_id(community_id)
|
|
|
|
.unresolved_only(unresolved_only)
|
|
|
|
.page(page)
|
|
|
|
.limit(limit)
|
|
|
|
.build()
|
|
|
|
.list()
|
|
|
|
.await?;
|
2022-04-13 18:12:25 +00:00
|
|
|
|
|
|
|
let res = ListCommentReportsResponse { comment_reports };
|
|
|
|
|
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
}
|