2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 check_private_instance,
6 get_local_user_view_from_jwt_opt,
7 site::{GetModlog, GetModlogResponse},
9 use lemmy_db_views_moderator::{
10 mod_add_community_view::ModAddCommunityView,
11 mod_add_view::ModAddView,
12 mod_ban_from_community_view::ModBanFromCommunityView,
13 mod_ban_view::ModBanView,
14 mod_hide_community_view::ModHideCommunityView,
15 mod_lock_post_view::ModLockPostView,
16 mod_remove_comment_view::ModRemoveCommentView,
17 mod_remove_community_view::ModRemoveCommunityView,
18 mod_remove_post_view::ModRemovePostView,
19 mod_sticky_post_view::ModStickyPostView,
20 mod_transfer_community_view::ModTransferCommunityView,
22 use lemmy_utils::{ConnectionId, LemmyError};
23 use lemmy_websocket::LemmyContext;
25 #[async_trait::async_trait(?Send)]
26 impl Perform for GetModlog {
27 type Response = GetModlogResponse;
29 #[tracing::instrument(skip(context, _websocket_id))]
32 context: &Data<LemmyContext>,
33 _websocket_id: Option<ConnectionId>,
34 ) -> Result<GetModlogResponse, LemmyError> {
35 let data: &GetModlog = self;
38 get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
41 check_private_instance(&local_user_view, context.pool()).await?;
43 let community_id = data.community_id;
44 let mod_person_id = data.mod_person_id;
46 let limit = data.limit;
47 let removed_posts = blocking(context.pool(), move |conn| {
48 ModRemovePostView::list(conn, community_id, mod_person_id, page, limit)
52 let locked_posts = blocking(context.pool(), move |conn| {
53 ModLockPostView::list(conn, community_id, mod_person_id, page, limit)
57 let stickied_posts = blocking(context.pool(), move |conn| {
58 ModStickyPostView::list(conn, community_id, mod_person_id, page, limit)
62 let removed_comments = blocking(context.pool(), move |conn| {
63 ModRemoveCommentView::list(conn, community_id, mod_person_id, page, limit)
67 let banned_from_community = blocking(context.pool(), move |conn| {
68 ModBanFromCommunityView::list(conn, community_id, mod_person_id, page, limit)
72 let added_to_community = blocking(context.pool(), move |conn| {
73 ModAddCommunityView::list(conn, community_id, mod_person_id, page, limit)
77 let transferred_to_community = blocking(context.pool(), move |conn| {
78 ModTransferCommunityView::list(conn, community_id, mod_person_id, page, limit)
82 let hidden_communities = blocking(context.pool(), move |conn| {
83 ModHideCommunityView::list(conn, community_id, mod_person_id, page, limit)
87 // These arrays are only for the full modlog, when a community isn't given
88 let (removed_communities, banned, added) = if data.community_id.is_none() {
89 blocking(context.pool(), move |conn| {
91 ModRemoveCommunityView::list(conn, mod_person_id, page, limit)?,
92 ModBanView::list(conn, mod_person_id, page, limit)?,
93 ModAddView::list(conn, mod_person_id, page, limit)?,
94 )) as Result<_, LemmyError>
98 (Vec::new(), Vec::new(), Vec::new())
102 Ok(GetModlogResponse {
108 banned_from_community,
112 transferred_to_community,