use activitypub_federation::{
config::Data,
kinds::activity::FollowType,
+ protocol::verification::verify_urls_match,
traits::{ActivityHandler, Actor},
};
use lemmy_api_common::{
community::{BlockCommunity, BlockCommunityResponse},
context::LemmyContext,
- utils::get_local_user_view_from_jwt,
+ utils::local_user_view_from_jwt,
};
use lemmy_db_schema::{
source::{
Ok(Follow {
actor: actor.id().into(),
object: community.id().into(),
+ to: Some([community.id().into()]),
kind: FollowType::Follow,
id: generate_activity_id(
FollowType::Follow,
person_id: actor.id,
pending: true,
};
- CommunityFollower::follow(context.pool(), &community_follower_form)
+ CommunityFollower::follow(&mut context.pool(), &community_follower_form)
.await
.ok();
if let UserOrCommunity::Community(c) = object {
verify_person_in_community(&self.actor, &c, context).await?;
}
+ if let Some(to) = &self.to {
+ verify_urls_match(to[0].inner(), self.object.inner())?;
+ }
Ok(())
}
follower_id: actor.id,
pending: false,
};
- PersonFollower::follow(context.pool(), &form).await?;
+ PersonFollower::follow(&mut context.pool(), &form).await?;
}
UserOrCommunity::Community(c) => {
let form = CommunityFollowerForm {
person_id: actor.id,
pending: false,
};
- CommunityFollower::follow(context.pool(), &form).await?;
+ CommunityFollower::follow(&mut context.pool(), &form).await?;
}
}
_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 community = Community::read(context.pool(), request.community_id).await?;
+ let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
+ let community = Community::read(&mut context.pool(), request.community_id).await?;
UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await
}
}