2 activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
3 objects::{community::ApubCommunity, person::ApubPerson},
4 protocol::activities::following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity},
6 use activitystreams_kinds::activity::UndoType;
7 use lemmy_api_common::utils::blocking;
11 traits::{ActivityHandler, ActorType},
12 verify::verify_urls_match,
14 use lemmy_db_schema::{
15 source::community::{CommunityFollower, CommunityFollowerForm},
18 use lemmy_utils::LemmyError;
19 use lemmy_websocket::LemmyContext;
21 impl UndoFollowCommunity {
22 #[tracing::instrument(skip_all)]
25 community: &ApubCommunity,
26 context: &LemmyContext,
27 ) -> Result<(), LemmyError> {
28 let object = FollowCommunity::new(actor, community, context)?;
29 let undo = UndoFollowCommunity {
30 actor: ObjectId::new(actor.actor_id()),
33 id: generate_activity_id(
35 &context.settings().get_protocol_and_hostname(),
37 unparsed: Default::default(),
39 let inbox = vec![community.shared_inbox_or_inbox_url()];
40 send_lemmy_activity(context, &undo, &undo.id, actor, inbox, true).await
44 #[async_trait::async_trait(?Send)]
45 impl ActivityHandler for UndoFollowCommunity {
46 type DataType = LemmyContext;
48 #[tracing::instrument(skip_all)]
51 context: &Data<LemmyContext>,
52 request_counter: &mut i32,
53 ) -> Result<(), LemmyError> {
54 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
55 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
56 verify_person(&self.actor, context, request_counter).await?;
57 self.object.verify(context, request_counter).await?;
61 #[tracing::instrument(skip_all)]
64 context: &Data<LemmyContext>,
65 request_counter: &mut i32,
66 ) -> Result<(), LemmyError> {
69 .dereference(context, context.client(), request_counter)
74 .dereference(context, context.client(), request_counter)
77 let community_follower_form = CommunityFollowerForm {
78 community_id: community.id,
83 // This will fail if they aren't a follower, but ignore the error.
84 blocking(context.pool(), move |conn| {
85 CommunityFollower::unfollow(conn, &community_follower_form).ok()