4 verify_person_in_community,
5 voting::{undo_vote_comment, undo_vote_post},
7 insert_received_activity,
8 objects::{community::ApubCommunity, person::ApubPerson},
10 activities::voting::{undo_vote::UndoVote, vote::Vote},
15 use activitypub_federation::{
17 kinds::activity::UndoType,
18 protocol::verification::verify_urls_match,
19 traits::{ActivityHandler, Actor},
21 use lemmy_api_common::context::LemmyContext;
22 use lemmy_utils::error::LemmyError;
26 pub(in crate::activities::voting) fn new(
29 community: &ApubCommunity,
30 context: &Data<LemmyContext>,
31 ) -> Result<Self, LemmyError> {
33 actor: actor.id().into(),
36 id: generate_activity_id(
38 &context.settings().get_protocol_and_hostname(),
40 audience: Some(community.id().into()),
45 #[async_trait::async_trait]
46 impl ActivityHandler for UndoVote {
47 type DataType = LemmyContext;
48 type Error = LemmyError;
50 fn id(&self) -> &Url {
54 fn actor(&self) -> &Url {
58 #[tracing::instrument(skip_all)]
59 async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
60 insert_received_activity(&self.id, context).await?;
61 let community = self.community(context).await?;
62 verify_person_in_community(&self.actor, &community, context).await?;
63 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
64 self.object.verify(context).await?;
68 #[tracing::instrument(skip_all)]
69 async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
70 let actor = self.actor.dereference(context).await?;
71 let object = self.object.object.dereference(context).await?;
73 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
74 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,