]> Untitled Git - lemmy.git/blob - crates/apub/src/protocol/activities/voting/undo_vote.rs
add enable_federated_downvotes site option
[lemmy.git] / crates / apub / src / protocol / activities / voting / undo_vote.rs
1 use crate::{
2   activities::verify_community_matches,
3   objects::{community::ApubCommunity, person::ApubPerson},
4   protocol::{activities::voting::vote::Vote, InCommunity},
5 };
6 use activitypub_federation::{config::Data, fetch::object_id::ObjectId, kinds::activity::UndoType};
7 use lemmy_api_common::context::LemmyContext;
8 use lemmy_utils::error::LemmyError;
9 use serde::{Deserialize, Serialize};
10 use url::Url;
11
12 #[derive(Clone, Debug, Deserialize, Serialize)]
13 #[serde(rename_all = "camelCase")]
14 pub struct UndoVote {
15   pub(crate) actor: ObjectId<ApubPerson>,
16   pub(crate) object: Vote,
17   #[serde(rename = "type")]
18   pub(crate) kind: UndoType,
19   pub(crate) id: Url,
20   pub(crate) audience: Option<ObjectId<ApubCommunity>>,
21 }
22
23 #[async_trait::async_trait]
24 impl InCommunity for UndoVote {
25   async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
26     let community = self.object.community(context).await?;
27     if let Some(audience) = &self.audience {
28       verify_community_matches(audience, community.actor_id.clone())?;
29     }
30     Ok(community)
31   }
32 }