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::{
10 ModBanFromCommunityView,
15 ModRemoveCommunityView,
18 ModTransferCommunityView,
20 use lemmy_utils::{ConnectionId, LemmyError};
21 use lemmy_websocket::LemmyContext;
23 #[async_trait::async_trait(?Send)]
24 impl Perform for GetModlog {
25 type Response = GetModlogResponse;
27 #[tracing::instrument(skip(context, _websocket_id))]
30 context: &Data<LemmyContext>,
31 _websocket_id: Option<ConnectionId>,
32 ) -> Result<GetModlogResponse, LemmyError> {
33 let data: &GetModlog = self;
36 get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
39 check_private_instance(&local_user_view, context.pool()).await?;
41 let community_id = data.community_id;
42 let mod_person_id = data.mod_person_id;
44 let limit = data.limit;
45 let removed_posts = blocking(context.pool(), move |conn| {
46 ModRemovePostView::list(conn, community_id, mod_person_id, page, limit)
50 let locked_posts = blocking(context.pool(), move |conn| {
51 ModLockPostView::list(conn, community_id, mod_person_id, page, limit)
55 let stickied_posts = blocking(context.pool(), move |conn| {
56 ModStickyPostView::list(conn, community_id, mod_person_id, page, limit)
60 let removed_comments = blocking(context.pool(), move |conn| {
61 ModRemoveCommentView::list(conn, community_id, mod_person_id, page, limit)
65 let banned_from_community = blocking(context.pool(), move |conn| {
66 ModBanFromCommunityView::list(conn, community_id, mod_person_id, page, limit)
70 let added_to_community = blocking(context.pool(), move |conn| {
71 ModAddCommunityView::list(conn, community_id, mod_person_id, page, limit)
75 let transferred_to_community = blocking(context.pool(), move |conn| {
76 ModTransferCommunityView::list(conn, community_id, mod_person_id, page, limit)
80 let hidden_communities = blocking(context.pool(), move |conn| {
81 ModHideCommunityView::list(conn, community_id, mod_person_id, page, limit)
85 // These arrays are only for the full modlog, when a community isn't given
86 let (removed_communities, banned, added) = if data.community_id.is_none() {
87 blocking(context.pool(), move |conn| {
89 ModRemoveCommunityView::list(conn, mod_person_id, page, limit)?,
90 ModBanView::list(conn, mod_person_id, page, limit)?,
91 ModAddView::list(conn, mod_person_id, page, limit)?,
92 )) as Result<_, LemmyError>
96 (Vec::new(), Vec::new(), Vec::new())
100 Ok(GetModlogResponse {
106 banned_from_community,
110 transferred_to_community,