2 activities::{following::follow::FollowCommunity, verify_activity, verify_community},
3 fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
5 use activitystreams::activity::kind::AcceptType;
6 use lemmy_api_common::blocking;
7 use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler};
8 use lemmy_db_queries::Followable;
9 use lemmy_db_schema::source::community::CommunityFollower;
10 use lemmy_utils::LemmyError;
11 use lemmy_websocket::LemmyContext;
14 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
15 #[serde(rename_all = "camelCase")]
16 pub struct AcceptFollowCommunity {
18 object: FollowCommunity,
19 #[serde(rename = "type")]
22 common: ActivityCommonFields,
25 /// Handle accepted follows
26 #[async_trait::async_trait(?Send)]
27 impl ActivityHandler for AcceptFollowCommunity {
30 context: &LemmyContext,
31 request_counter: &mut i32,
32 ) -> Result<(), LemmyError> {
33 verify_activity(self.common())?;
34 verify_urls_match(&self.to, &self.object.common.actor)?;
35 verify_urls_match(&self.common.actor, &self.object.to)?;
36 verify_community(&self.common.actor, context, request_counter).await?;
37 self.object.verify(context, request_counter).await?;
43 context: &LemmyContext,
44 request_counter: &mut i32,
45 ) -> Result<(), LemmyError> {
47 get_or_fetch_and_upsert_community(&self.common.actor, context, request_counter).await?;
48 let to = get_or_fetch_and_upsert_person(&self.to, context, request_counter).await?;
49 // This will throw an error if no follow was requested
50 blocking(context.pool(), move |conn| {
51 CommunityFollower::follow_accepted(conn, actor.id, to.id)
58 fn common(&self) -> &ActivityCommonFields {