2 activities::verify_community_matches,
3 fetcher::post_or_comment::PostOrComment,
4 objects::{community::ApubCommunity, person::ApubPerson},
7 use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
8 use lemmy_api_common::context::LemmyContext;
9 use lemmy_utils::error::{LemmyError, LemmyErrorType};
10 use serde::{Deserialize, Serialize};
11 use std::convert::TryFrom;
12 use strum_macros::Display;
15 #[derive(Clone, Debug, Deserialize, Serialize)]
16 #[serde(rename_all = "camelCase")]
18 pub(crate) actor: ObjectId<ApubPerson>,
19 pub(crate) object: ObjectId<PostOrComment>,
20 #[serde(rename = "type")]
21 pub(crate) kind: VoteType,
23 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
26 #[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq, Eq)]
32 impl TryFrom<i16> for VoteType {
33 type Error = LemmyError;
35 fn try_from(value: i16) -> Result<Self, Self::Error> {
37 1 => Ok(VoteType::Like),
38 -1 => Ok(VoteType::Dislike),
39 _ => Err(LemmyErrorType::InvalidVoteValue.into()),
44 impl From<&VoteType> for i16 {
45 fn from(value: &VoteType) -> i16 {
48 VoteType::Dislike => -1,
53 #[async_trait::async_trait]
54 impl InCommunity for Vote {
55 async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
62 if let Some(audience) = &self.audience {
63 verify_community_matches(audience, community.actor_id.clone())?;