2 activities::{following::follow::FollowCommunity, verify_activity, verify_person},
3 fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
5 use activitystreams::activity::kind::UndoType;
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, CommunityFollowerForm};
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 UndoFollowCommunity {
18 object: FollowCommunity,
19 #[serde(rename = "type")]
22 common: ActivityCommonFields,
25 #[async_trait::async_trait(?Send)]
26 impl ActivityHandler for UndoFollowCommunity {
29 context: &LemmyContext,
30 request_counter: &mut i32,
31 ) -> Result<(), LemmyError> {
32 verify_activity(self.common())?;
33 verify_urls_match(&self.to, &self.object.object)?;
34 verify_urls_match(&self.common.actor, &self.object.common.actor)?;
35 verify_person(&self.common.actor, context, request_counter).await?;
36 self.object.verify(context, request_counter).await?;
42 context: &LemmyContext,
43 request_counter: &mut i32,
44 ) -> Result<(), LemmyError> {
46 get_or_fetch_and_upsert_person(&self.common.actor, context, request_counter).await?;
47 let community = get_or_fetch_and_upsert_community(&self.to, context, request_counter).await?;
49 let community_follower_form = CommunityFollowerForm {
50 community_id: community.id,
55 // This will fail if they aren't a follower, but ignore the error.
56 blocking(context.pool(), move |conn| {
57 CommunityFollower::unfollow(conn, &community_follower_form).ok()
63 fn common(&self) -> &ActivityCommonFields {