2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 site::{GetModlog, GetModlogResponse},
5 utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
7 use lemmy_db_views_moderator::structs::{
9 AdminPurgeCommunityView,
14 ModBanFromCommunityView,
19 ModRemoveCommunityView,
22 ModTransferCommunityView,
24 use lemmy_utils::{error::LemmyError, ConnectionId};
25 use lemmy_websocket::LemmyContext;
27 #[async_trait::async_trait(?Send)]
28 impl Perform for GetModlog {
29 type Response = GetModlogResponse;
31 #[tracing::instrument(skip(context, _websocket_id))]
34 context: &Data<LemmyContext>,
35 _websocket_id: Option<ConnectionId>,
36 ) -> Result<GetModlogResponse, LemmyError> {
37 let data: &GetModlog = self;
40 get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
43 check_private_instance(&local_user_view, context.pool()).await?;
45 let community_id = data.community_id;
46 let mod_person_id = data.mod_person_id;
48 let limit = data.limit;
49 let removed_posts = blocking(context.pool(), move |conn| {
50 ModRemovePostView::list(conn, community_id, mod_person_id, page, limit)
54 let locked_posts = blocking(context.pool(), move |conn| {
55 ModLockPostView::list(conn, community_id, mod_person_id, page, limit)
59 let stickied_posts = blocking(context.pool(), move |conn| {
60 ModStickyPostView::list(conn, community_id, mod_person_id, page, limit)
64 let removed_comments = blocking(context.pool(), move |conn| {
65 ModRemoveCommentView::list(conn, community_id, mod_person_id, page, limit)
69 let banned_from_community = blocking(context.pool(), move |conn| {
70 ModBanFromCommunityView::list(conn, community_id, mod_person_id, page, limit)
74 let added_to_community = blocking(context.pool(), move |conn| {
75 ModAddCommunityView::list(conn, community_id, mod_person_id, page, limit)
79 let transferred_to_community = blocking(context.pool(), move |conn| {
80 ModTransferCommunityView::list(conn, community_id, mod_person_id, page, limit)
84 let hidden_communities = blocking(context.pool(), move |conn| {
85 ModHideCommunityView::list(conn, community_id, mod_person_id, page, limit)
89 // These arrays are only for the full modlog, when a community isn't given
95 admin_purged_communities,
97 admin_purged_comments,
98 ) = if data.community_id.is_none() {
99 blocking(context.pool(), move |conn| {
101 ModRemoveCommunityView::list(conn, mod_person_id, page, limit)?,
102 ModBanView::list(conn, mod_person_id, page, limit)?,
103 ModAddView::list(conn, mod_person_id, page, limit)?,
104 AdminPurgePersonView::list(conn, mod_person_id, page, limit)?,
105 AdminPurgeCommunityView::list(conn, mod_person_id, page, limit)?,
106 AdminPurgePostView::list(conn, mod_person_id, page, limit)?,
107 AdminPurgeCommentView::list(conn, mod_person_id, page, limit)?,
108 )) as Result<_, LemmyError>
116 Ok(GetModlogResponse {
122 banned_from_community,
126 transferred_to_community,
127 admin_purged_persons,
128 admin_purged_communities,
130 admin_purged_comments,