mirror of https://github.com/LemmyNet/lemmy
Remove follow community traits (#3737)
* chore(FollowCommunity): remove Perform and Send Activity traits * chore(FollowCommunity): avoid fetching community and person from dbpull/3740/head^2
parent
91834d0d21
commit
7bc64ab91a
@ -1,6 +1,6 @@
|
||||
mod add_mod;
|
||||
mod ban;
|
||||
mod block;
|
||||
mod follow;
|
||||
pub mod follow;
|
||||
mod hide;
|
||||
mod transfer;
|
||||
|
@ -1,41 +1,27 @@
|
||||
use crate::{
|
||||
objects::community::ApubCommunity,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
protocol::activities::following::{follow::Follow, undo_follow::UndoFollow},
|
||||
SendActivity,
|
||||
};
|
||||
use activitypub_federation::config::Data;
|
||||
use lemmy_api_common::{
|
||||
community::{CommunityResponse, FollowCommunity},
|
||||
context::LemmyContext,
|
||||
utils::local_user_view_from_jwt,
|
||||
};
|
||||
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
||||
use lemmy_api_common::context::LemmyContext;
|
||||
use lemmy_db_schema::source::{community::Community, person::Person};
|
||||
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 = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let person = local_user_view.person.clone().into();
|
||||
let community: ApubCommunity = Community::read(&mut 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
|
||||
}
|
||||
pub async fn send_follow_community(
|
||||
community: Community,
|
||||
person: Person,
|
||||
follow: bool,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let community: ApubCommunity = community.into();
|
||||
let actor: ApubPerson = person.into();
|
||||
if follow {
|
||||
Follow::send(&actor, &community, context).await
|
||||
} else {
|
||||
UndoFollow::send(&actor, &community, context).await
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue