]> Untitled Git - lemmy.git/blob - crates/apub/src/activities/following/mod.rs
Merge pull request #2593 from LemmyNet/refactor-notifications
[lemmy.git] / crates / apub / src / activities / following / mod.rs
1 use crate::{
2   objects::community::ApubCommunity,
3   protocol::activities::following::{follow::Follow, undo_follow::UndoFollow},
4   SendActivity,
5 };
6 use lemmy_api_common::{
7   community::{CommunityResponse, FollowCommunity},
8   context::LemmyContext,
9   utils::get_local_user_view_from_jwt,
10 };
11 use lemmy_db_schema::{source::community::Community, traits::Crud};
12 use lemmy_utils::error::LemmyError;
13
14 pub mod accept;
15 pub mod follow;
16 pub mod undo_follow;
17
18 #[async_trait::async_trait(?Send)]
19 impl SendActivity for FollowCommunity {
20   type Response = CommunityResponse;
21
22   async fn send_activity(
23     request: &Self,
24     _response: &Self::Response,
25     context: &LemmyContext,
26   ) -> Result<(), LemmyError> {
27     let local_user_view =
28       get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
29     let person = local_user_view.person.clone().into();
30     let community: ApubCommunity = Community::read(context.pool(), request.community_id)
31       .await?
32       .into();
33     if community.local {
34       Ok(())
35     } else if request.follow {
36       Follow::send(&person, &community, context).await
37     } else {
38       UndoFollow::send(&person, &community, context).await
39     }
40   }
41 }