2 activities::{generate_activity_id, send_lemmy_activity, verify_person_in_community},
4 objects::{community::ApubCommunity, person::ApubPerson},
5 protocol::{activities::community::report::Report, InCommunity},
9 use activitypub_federation::{
11 fetch::object_id::ObjectId,
12 kinds::activity::FlagType,
13 traits::{ActivityHandler, Actor},
15 use lemmy_api_common::{
16 comment::{CommentReportResponse, CreateCommentReport},
17 context::LemmyContext,
18 post::{CreatePostReport, PostReportResponse},
19 utils::local_user_view_from_jwt,
21 use lemmy_db_schema::{
23 comment_report::{CommentReport, CommentReportForm},
24 post_report::{PostReport, PostReportForm},
28 use lemmy_utils::error::LemmyError;
31 #[async_trait::async_trait]
32 impl SendActivity for CreatePostReport {
33 type Response = PostReportResponse;
35 async fn send_activity(
37 response: &Self::Response,
38 context: &Data<LemmyContext>,
39 ) -> Result<(), LemmyError> {
40 let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
42 ObjectId::from(response.post_report_view.post.ap_id.clone()),
43 &local_user_view.person.into(),
44 ObjectId::from(response.post_report_view.community.actor_id.clone()),
45 request.reason.to_string(),
52 #[async_trait::async_trait]
53 impl SendActivity for CreateCommentReport {
54 type Response = CommentReportResponse;
56 async fn send_activity(
58 response: &Self::Response,
59 context: &Data<LemmyContext>,
60 ) -> Result<(), LemmyError> {
61 let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
63 ObjectId::from(response.comment_report_view.comment.ap_id.clone()),
64 &local_user_view.person.into(),
65 ObjectId::from(response.comment_report_view.community.actor_id.clone()),
66 request.reason.to_string(),
74 #[tracing::instrument(skip_all)]
76 object_id: ObjectId<PostOrComment>,
78 community_id: ObjectId<ApubCommunity>,
80 context: &Data<LemmyContext>,
81 ) -> Result<(), LemmyError> {
82 let community = community_id.dereference_local(context).await?;
83 let kind = FlagType::Flag;
84 let id = generate_activity_id(
86 &context.settings().get_protocol_and_hostname(),
89 actor: actor.id().into(),
90 to: [community.id().into()],
95 audience: Some(community.id().into()),
98 let inbox = vec![community.shared_inbox_or_inbox()];
99 send_lemmy_activity(context, report, actor, inbox, false).await
103 #[async_trait::async_trait]
104 impl ActivityHandler for Report {
105 type DataType = LemmyContext;
106 type Error = LemmyError;
108 fn id(&self) -> &Url {
112 fn actor(&self) -> &Url {
116 #[tracing::instrument(skip_all)]
117 async fn verify(&self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
118 let community = self.community(context).await?;
119 verify_person_in_community(&self.actor, &community, context).await?;
123 #[tracing::instrument(skip_all)]
124 async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
125 insert_activity(&self.id, &self, false, true, context).await?;
126 let actor = self.actor.dereference(context).await?;
127 match self.object.dereference(context).await? {
128 PostOrComment::Post(post) => {
129 let report_form = PostReportForm {
130 creator_id: actor.id,
132 original_post_name: post.name.clone(),
133 original_post_url: post.url.clone(),
134 reason: self.summary,
135 original_post_body: post.body.clone(),
137 PostReport::report(&mut context.pool(), &report_form).await?;
139 PostOrComment::Comment(comment) => {
140 let report_form = CommentReportForm {
141 creator_id: actor.id,
142 comment_id: comment.id,
143 original_comment_text: comment.content.clone(),
144 reason: self.summary,
146 CommentReport::report(&mut context.pool(), &report_form).await?;