mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-08 11:11:37 +00:00
41 lines
1.2 KiB
Rust
41 lines
1.2 KiB
Rust
use crate::{
|
|
objects::community::ApubCommunity,
|
|
protocol::activities::following::{follow::Follow, undo_follow::UndoFollow},
|
|
SendActivity,
|
|
};
|
|
use lemmy_api_common::{
|
|
community::{CommunityResponse, FollowCommunity},
|
|
context::LemmyContext,
|
|
utils::get_local_user_view_from_jwt,
|
|
};
|
|
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
|
use lemmy_utils::error::LemmyError;
|
|
|
|
pub mod accept;
|
|
pub mod follow;
|
|
pub mod undo_follow;
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
impl SendActivity for FollowCommunity {
|
|
type Response = CommunityResponse;
|
|
|
|
async fn send_activity(
|
|
request: &Self,
|
|
_response: &Self::Response,
|
|
context: &LemmyContext,
|
|
) -> Result<(), LemmyError> {
|
|
let local_user_view =
|
|
get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
|
|
let person = local_user_view.person.clone().into();
|
|
let community: ApubCommunity = Community::read(context.pool(), request.community_id)
|
|
.await?
|
|
.into();
|
|
if community.local {
|
|
Ok(())
|
|
} else if request.follow {
|
|
Follow::send(&person, &community, context).await
|
|
} else {
|
|
UndoFollow::send(&person, &community, context).await
|
|
}
|
|
}
|
|
}
|