3 following::follow::FollowCommunity,
8 fetcher::object_id::ObjectId,
9 objects::{community::ApubCommunity, person::ApubPerson},
11 use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed};
12 use lemmy_api_common::blocking;
15 traits::{ActivityFields, ActivityHandler, ActorType},
16 verify::verify_urls_match,
18 use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
19 use lemmy_utils::LemmyError;
20 use lemmy_websocket::LemmyContext;
21 use serde::{Deserialize, Serialize};
24 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
25 #[serde(rename_all = "camelCase")]
26 pub struct AcceptFollowCommunity {
27 actor: ObjectId<ApubCommunity>,
28 to: [ObjectId<ApubPerson>; 1],
29 object: FollowCommunity,
30 #[serde(rename = "type")]
37 impl AcceptFollowCommunity {
39 follow: FollowCommunity,
40 context: &LemmyContext,
41 request_counter: &mut i32,
42 ) -> Result<(), LemmyError> {
43 let community = follow.object.dereference_local(context).await?;
47 .dereference(context, request_counter)
49 let accept = AcceptFollowCommunity {
50 actor: ObjectId::new(community.actor_id()),
51 to: [ObjectId::new(person.actor_id())],
53 kind: AcceptType::Accept,
54 id: generate_activity_id(
56 &context.settings().get_protocol_and_hostname(),
58 unparsed: Default::default(),
60 let inbox = vec![person.inbox_url()];
61 send_lemmy_activity(context, &accept, &accept.id, &community, inbox, true).await
65 /// Handle accepted follows
66 #[async_trait::async_trait(?Send)]
67 impl ActivityHandler for AcceptFollowCommunity {
68 type DataType = LemmyContext;
71 context: &Data<LemmyContext>,
72 request_counter: &mut i32,
73 ) -> Result<(), LemmyError> {
74 verify_activity(self, &context.settings())?;
75 verify_urls_match(self.to[0].inner(), self.object.actor())?;
76 verify_urls_match(self.actor(), self.object.to[0].inner())?;
77 self.object.verify(context, request_counter).await?;
83 context: &Data<LemmyContext>,
84 request_counter: &mut i32,
85 ) -> Result<(), LemmyError> {
86 let actor = self.actor.dereference(context, request_counter).await?;
87 let to = self.to[0].dereference(context, request_counter).await?;
88 // This will throw an error if no follow was requested
89 blocking(context.pool(), move |conn| {
90 CommunityFollower::follow_accepted(conn, actor.id, to.id)