use crate::{
activities::{generate_activity_id, send_lemmy_activity, verify_person},
fetcher::user_or_community::UserOrCommunity,
- local_instance,
+ insert_activity,
objects::{community::ApubCommunity, person::ApubPerson},
protocol::activities::following::{follow::Follow, undo_follow::UndoFollow},
- ActorType,
};
use activitypub_federation::{
- core::object_id::ObjectId,
- data::Data,
+ config::Data,
+ kinds::activity::UndoType,
+ protocol::verification::verify_urls_match,
traits::{ActivityHandler, Actor},
- utils::verify_urls_match,
};
-use activitystreams_kinds::activity::UndoType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{
source::{
community::{CommunityFollower, CommunityFollowerForm},
pub async fn send(
actor: &ApubPerson,
community: &ApubCommunity,
- context: &LemmyContext,
+ context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let object = Follow::new(actor, community, context)?;
let undo = UndoFollow {
- actor: ObjectId::new(actor.actor_id()),
+ actor: actor.id().into(),
+ to: Some([community.id().into()]),
object,
kind: UndoType::Undo,
id: generate_activity_id(
}
}
-#[async_trait::async_trait(?Send)]
+#[async_trait::async_trait]
impl ActivityHandler for UndoFollow {
type DataType = LemmyContext;
type Error = LemmyError;
}
#[tracing::instrument(skip_all)]
- async fn verify(
- &self,
- context: &Data<LemmyContext>,
- request_counter: &mut i32,
- ) -> Result<(), LemmyError> {
+ async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
- verify_person(&self.actor, context, request_counter).await?;
- self.object.verify(context, request_counter).await?;
+ verify_person(&self.actor, context).await?;
+ self.object.verify(context).await?;
+ if let Some(to) = &self.to {
+ verify_urls_match(to[0].inner(), self.object.object.inner())?;
+ }
Ok(())
}
#[tracing::instrument(skip_all)]
- async fn receive(
- self,
- context: &Data<LemmyContext>,
- request_counter: &mut i32,
- ) -> Result<(), LemmyError> {
- let person = self
- .actor
- .dereference(context, local_instance(context).await, request_counter)
- .await?;
- let object = self
- .object
- .object
- .dereference(context, local_instance(context).await, request_counter)
- .await?;
+ async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
+ insert_activity(&self.id, &self, false, true, context).await?;
+ let person = self.actor.dereference(context).await?;
+ let object = self.object.object.dereference(context).await?;
match object {
UserOrCommunity::User(u) => {
follower_id: person.id,
pending: false,
};
- PersonFollower::unfollow(context.pool(), &form).await?;
+ PersonFollower::unfollow(&mut context.pool(), &form).await?;
}
UserOrCommunity::Community(c) => {
let form = CommunityFollowerForm {
person_id: person.id,
pending: false,
};
- CommunityFollower::unfollow(context.pool(), &form).await?;
+ CommunityFollower::unfollow(&mut context.pool(), &form).await?;
}
}