1 use crate::activities::{following::follow::FollowCommunity, verify_activity, verify_person};
2 use activitystreams::activity::kind::UndoType;
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, CommunityFollowerForm};
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 UndoFollowCommunity {
19 object: FollowCommunity,
20 #[serde(rename = "type")]
23 common: ActivityCommonFields,
26 #[async_trait::async_trait(?Send)]
27 impl ActivityHandler for UndoFollowCommunity {
30 context: &LemmyContext,
31 request_counter: &mut i32,
32 ) -> Result<(), LemmyError> {
33 verify_activity(self.common())?;
34 verify_urls_match(&self.to, &self.object.object)?;
35 verify_urls_match(&self.common.actor, &self.object.common.actor)?;
36 verify_person(&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_person(&self.common.actor, context, request_counter).await?;
48 let community = get_or_fetch_and_upsert_community(&self.to, context, request_counter).await?;
50 let community_follower_form = CommunityFollowerForm {
51 community_id: community.id,
56 // This will fail if they aren't a follower, but ignore the error.
57 blocking(context.pool(), move |conn| {
58 CommunityFollower::unfollow(conn, &community_follower_form).ok()
64 fn common(&self) -> &ActivityCommonFields {