2 activities::{generate_activity_id, send_lemmy_activity, verify_activity},
3 protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
5 use activitystreams_kinds::activity::AcceptType;
6 use lemmy_api_common::blocking;
10 traits::{ActivityHandler, ActorType},
11 verify::verify_urls_match,
13 use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
14 use lemmy_utils::LemmyError;
15 use lemmy_websocket::LemmyContext;
17 impl AcceptFollowCommunity {
18 #[tracing::instrument(skip_all)]
20 follow: FollowCommunity,
21 context: &LemmyContext,
22 request_counter: &mut i32,
23 ) -> Result<(), LemmyError> {
24 let community = follow.object.dereference_local(context).await?;
28 .dereference(context, request_counter)
30 let accept = AcceptFollowCommunity {
31 actor: ObjectId::new(community.actor_id()),
33 kind: AcceptType::Accept,
34 id: generate_activity_id(
36 &context.settings().get_protocol_and_hostname(),
38 unparsed: Default::default(),
40 let inbox = vec![person.inbox_url()];
41 send_lemmy_activity(context, &accept, &accept.id, &community, inbox, true).await
45 /// Handle accepted follows
46 #[async_trait::async_trait(?Send)]
47 impl ActivityHandler for AcceptFollowCommunity {
48 type DataType = LemmyContext;
50 #[tracing::instrument(skip_all)]
53 context: &Data<LemmyContext>,
54 request_counter: &mut i32,
55 ) -> Result<(), LemmyError> {
56 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
57 verify_urls_match(self.actor.inner(), self.object.object.inner())?;
58 self.object.verify(context, request_counter).await?;
62 #[tracing::instrument(skip_all)]
65 context: &Data<LemmyContext>,
66 request_counter: &mut i32,
67 ) -> Result<(), LemmyError> {
68 let person = self.actor.dereference(context, request_counter).await?;
72 .dereference(context, request_counter)
74 // This will throw an error if no follow was requested
75 blocking(context.pool(), move |conn| {
76 CommunityFollower::follow_accepted(conn, person.id, community.id)