lemmy/crates/apub/src/activities/following/mod.rs
Nutomic 6f513793cb
Activitypub crate rewrite (#2782)
* update activitypub-federation crate to 0.4.0

* fixes

* apub compiles!

* everything compiling!

* almost done, federated follow failing

* some test fixes

* use release

* add code back in
2023-03-21 16:03:05 +01:00

43 lines
1.2 KiB
Rust

use crate::{
objects::community::ApubCommunity,
protocol::activities::following::{follow::Follow, undo_follow::UndoFollow},
SendActivity,
};
use activitypub_federation::config::Data;
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]
impl SendActivity for FollowCommunity {
type Response = CommunityResponse;
async fn send_activity(
request: &Self,
_response: &Self::Response,
context: &Data<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
}
}
}