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(),
40 let inbox = vec![community.shared_inbox_or_inbox()];
41 send_lemmy_activity(context, undo, actor, inbox, true).await
45 #[async_trait::async_trait(?Send)]
46 impl ActivityHandler for UndoFollowCommunity {
47 type DataType = LemmyContext;
48 type Error = LemmyError;
50 fn id(&self) -> &Url {
54 fn actor(&self) -> &Url {
58 #[tracing::instrument(skip_all)]
61 context: &Data<LemmyContext>,
62 request_counter: &mut i32,
63 ) -> Result<(), LemmyError> {
64 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
65 verify_person(&self.actor, context, request_counter).await?;
66 self.object.verify(context, request_counter).await?;
70 #[tracing::instrument(skip_all)]
73 context: &Data<LemmyContext>,
74 request_counter: &mut i32,
75 ) -> Result<(), LemmyError> {
78 .dereference(context, local_instance(context).await, request_counter)
83 .dereference(context, local_instance(context).await, request_counter)
86 let community_follower_form = CommunityFollowerForm {
87 community_id: community.id,
92 // This will fail if they aren't a follower, but ignore the error.
93 CommunityFollower::unfollow(context.pool(), &community_follower_form)