2 activities::{generate_activity_id, send_lemmy_activity, verify_person},
3 fetcher::user_or_community::UserOrCommunity,
5 objects::{community::ApubCommunity, person::ApubPerson},
6 protocol::activities::following::{follow::Follow, undo_follow::UndoFollow},
9 use activitypub_federation::{
10 core::object_id::ObjectId,
12 traits::{ActivityHandler, Actor},
13 utils::verify_urls_match,
15 use activitystreams_kinds::activity::UndoType;
16 use lemmy_db_schema::{
18 community::{CommunityFollower, CommunityFollowerForm},
19 person::{PersonFollower, PersonFollowerForm},
23 use lemmy_utils::error::LemmyError;
24 use lemmy_websocket::LemmyContext;
28 #[tracing::instrument(skip_all)]
31 community: &ApubCommunity,
32 context: &LemmyContext,
33 ) -> Result<(), LemmyError> {
34 let object = Follow::new(actor, community, context)?;
35 let undo = UndoFollow {
36 actor: ObjectId::new(actor.actor_id()),
39 id: generate_activity_id(
41 &context.settings().get_protocol_and_hostname(),
44 let inbox = vec![community.shared_inbox_or_inbox()];
45 send_lemmy_activity(context, undo, actor, inbox, true).await
49 #[async_trait::async_trait(?Send)]
50 impl ActivityHandler for UndoFollow {
51 type DataType = LemmyContext;
52 type Error = LemmyError;
54 fn id(&self) -> &Url {
58 fn actor(&self) -> &Url {
62 #[tracing::instrument(skip_all)]
65 context: &Data<LemmyContext>,
66 request_counter: &mut i32,
67 ) -> Result<(), LemmyError> {
68 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
69 verify_person(&self.actor, context, request_counter).await?;
70 self.object.verify(context, request_counter).await?;
74 #[tracing::instrument(skip_all)]
77 context: &Data<LemmyContext>,
78 request_counter: &mut i32,
79 ) -> Result<(), LemmyError> {
82 .dereference(context, local_instance(context).await, request_counter)
87 .dereference(context, local_instance(context).await, request_counter)
91 UserOrCommunity::User(u) => {
92 let form = PersonFollowerForm {
94 follower_id: person.id,
97 PersonFollower::unfollow(context.pool(), &form).await?;
99 UserOrCommunity::Community(c) => {
100 let form = CommunityFollowerForm {
102 person_id: person.id,
105 CommunityFollower::unfollow(context.pool(), &form).await?;