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 {
19 follow: FollowCommunity,
20 context: &LemmyContext,
21 request_counter: &mut i32,
22 ) -> Result<(), LemmyError> {
23 let community = follow.object.dereference_local(context).await?;
27 .dereference(context, request_counter)
29 let accept = AcceptFollowCommunity {
30 actor: ObjectId::new(community.actor_id()),
32 kind: AcceptType::Accept,
33 id: generate_activity_id(
35 &context.settings().get_protocol_and_hostname(),
37 unparsed: Default::default(),
39 let inbox = vec![person.inbox_url()];
40 send_lemmy_activity(context, &accept, &accept.id, &community, inbox, true).await
44 /// Handle accepted follows
45 #[async_trait::async_trait(?Send)]
46 impl ActivityHandler for AcceptFollowCommunity {
47 type DataType = LemmyContext;
50 context: &Data<LemmyContext>,
51 request_counter: &mut i32,
52 ) -> Result<(), LemmyError> {
53 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
54 verify_urls_match(self.actor.inner(), self.object.object.inner())?;
55 self.object.verify(context, request_counter).await?;
61 context: &Data<LemmyContext>,
62 request_counter: &mut i32,
63 ) -> Result<(), LemmyError> {
64 let person = self.actor.dereference(context, request_counter).await?;
68 .dereference(context, request_counter)
70 // This will throw an error if no follow was requested
71 blocking(context.pool(), move |conn| {
72 CommunityFollower::follow_accepted(conn, person.id, community.id)