2 activities::{generate_activity_id, send_lemmy_activity},
4 protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
7 use activitypub_federation::{
8 core::object_id::ObjectId,
10 traits::{ActivityHandler, Actor},
11 utils::verify_urls_match,
13 use activitystreams_kinds::activity::AcceptType;
14 use lemmy_api_common::utils::blocking;
15 use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
16 use lemmy_utils::error::LemmyError;
17 use lemmy_websocket::LemmyContext;
20 impl AcceptFollowCommunity {
21 #[tracing::instrument(skip_all)]
23 follow: FollowCommunity,
24 context: &LemmyContext,
25 request_counter: &mut i32,
26 ) -> Result<(), LemmyError> {
27 let community = follow.object.dereference_local(context).await?;
31 .dereference(context, local_instance(context), request_counter)
33 let accept = AcceptFollowCommunity {
34 actor: ObjectId::new(community.actor_id()),
36 kind: AcceptType::Accept,
37 id: generate_activity_id(
39 &context.settings().get_protocol_and_hostname(),
41 unparsed: Default::default(),
43 let inbox = vec![person.shared_inbox_or_inbox()];
44 send_lemmy_activity(context, accept, &community, inbox, true).await
48 /// Handle accepted follows
49 #[async_trait::async_trait(?Send)]
50 impl ActivityHandler for AcceptFollowCommunity {
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.object.inner())?;
69 self.object.verify(context, request_counter).await?;
73 #[tracing::instrument(skip_all)]
76 context: &Data<LemmyContext>,
77 request_counter: &mut i32,
78 ) -> Result<(), LemmyError> {
81 .dereference(context, local_instance(context), request_counter)
86 .dereference(context, local_instance(context), request_counter)
88 // This will throw an error if no follow was requested
89 blocking(context.pool(), move |conn| {
90 CommunityFollower::follow_accepted(conn, person.id, community.id)