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,
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
29 .dereference_local::<LemmyError>(context)
34 .dereference::<LemmyError>(context, local_instance(context), request_counter)
36 let accept = AcceptFollowCommunity {
37 actor: ObjectId::new(community.actor_id()),
39 kind: AcceptType::Accept,
40 id: generate_activity_id(
42 &context.settings().get_protocol_and_hostname(),
44 unparsed: Default::default(),
46 let inbox = vec![person.inbox_url()];
47 send_lemmy_activity(context, &accept, &accept.id, &community, inbox, true).await
51 /// Handle accepted follows
52 #[async_trait::async_trait(?Send)]
53 impl ActivityHandler for AcceptFollowCommunity {
54 type DataType = LemmyContext;
55 type Error = LemmyError;
57 fn id(&self) -> &Url {
61 fn actor(&self) -> &Url {
65 #[tracing::instrument(skip_all)]
68 context: &Data<LemmyContext>,
69 request_counter: &mut i32,
70 ) -> Result<(), LemmyError> {
71 verify_urls_match(self.actor.inner(), self.object.object.inner())?;
72 self.object.verify(context, request_counter).await?;
76 #[tracing::instrument(skip_all)]
79 context: &Data<LemmyContext>,
80 request_counter: &mut i32,
81 ) -> Result<(), LemmyError> {
84 .dereference::<LemmyError>(context, local_instance(context), request_counter)
89 .dereference::<LemmyError>(context, local_instance(context), request_counter)
91 // This will throw an error if no follow was requested
92 blocking(context.pool(), move |conn| {
93 CommunityFollower::follow_accepted(conn, person.id, community.id)