2 activities::{generate_activity_id, send_lemmy_activity, verify_person},
4 objects::{community::ApubCommunity, person::ApubPerson},
5 protocol::activities::following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity},
8 use activitypub_federation::{
9 core::object_id::ObjectId,
11 traits::{ActivityHandler, Actor},
12 utils::verify_urls_match,
14 use activitystreams_kinds::activity::UndoType;
15 use lemmy_db_schema::{
16 source::community::{CommunityFollower, CommunityFollowerForm},
19 use lemmy_utils::error::LemmyError;
20 use lemmy_websocket::LemmyContext;
23 impl UndoFollowCommunity {
24 #[tracing::instrument(skip_all)]
27 community: &ApubCommunity,
28 context: &LemmyContext,
29 ) -> Result<(), LemmyError> {
30 let object = FollowCommunity::new(actor, community, context)?;
31 let undo = UndoFollowCommunity {
32 actor: ObjectId::new(actor.actor_id()),
35 id: generate_activity_id(
37 &context.settings().get_protocol_and_hostname(),
39 unparsed: Default::default(),
41 let inbox = vec![community.shared_inbox_or_inbox()];
42 send_lemmy_activity(context, undo, actor, inbox, true).await
46 #[async_trait::async_trait(?Send)]
47 impl ActivityHandler for UndoFollowCommunity {
48 type DataType = LemmyContext;
49 type Error = LemmyError;
51 fn id(&self) -> &Url {
55 fn actor(&self) -> &Url {
59 #[tracing::instrument(skip_all)]
62 context: &Data<LemmyContext>,
63 request_counter: &mut i32,
64 ) -> Result<(), LemmyError> {
65 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
66 verify_person(&self.actor, context, request_counter).await?;
67 self.object.verify(context, request_counter).await?;
71 #[tracing::instrument(skip_all)]
74 context: &Data<LemmyContext>,
75 request_counter: &mut i32,
76 ) -> Result<(), LemmyError> {
79 .dereference(context, local_instance(context).await, request_counter)
84 .dereference(context, local_instance(context).await, request_counter)
87 let community_follower_form = CommunityFollowerForm {
88 community_id: community.id,
93 // This will fail if they aren't a follower, but ignore the error.
94 CommunityFollower::unfollow(context.pool(), &community_follower_form)