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