2 activities::verify_community_matches,
3 fetcher::post_or_comment::PostOrComment,
5 objects::{community::ApubCommunity, person::ApubPerson},
8 use activitypub_federation::core::object_id::ObjectId;
9 use lemmy_api_common::context::LemmyContext;
10 use lemmy_utils::error::LemmyError;
11 use serde::{Deserialize, Serialize};
12 use std::convert::TryFrom;
13 use strum_macros::Display;
16 #[derive(Clone, Debug, Deserialize, Serialize)]
17 #[serde(rename_all = "camelCase")]
19 pub(crate) actor: ObjectId<ApubPerson>,
20 pub(crate) object: ObjectId<PostOrComment>,
21 #[serde(rename = "type")]
22 pub(crate) kind: VoteType,
24 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
27 #[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq, Eq)]
33 impl TryFrom<i16> for VoteType {
34 type Error = LemmyError;
36 fn try_from(value: i16) -> Result<Self, Self::Error> {
38 1 => Ok(VoteType::Like),
39 -1 => Ok(VoteType::Dislike),
40 _ => Err(LemmyError::from_message("invalid vote value")),
45 impl From<&VoteType> for i16 {
46 fn from(value: &VoteType) -> i16 {
49 VoteType::Dislike => -1,
54 #[async_trait::async_trait(?Send)]
55 impl InCommunity for Vote {
58 context: &LemmyContext,
59 request_counter: &mut i32,
60 ) -> Result<ApubCommunity, LemmyError> {
61 let local_instance = local_instance(context).await;
62 let object_community = self
64 .dereference(context, local_instance, request_counter)
66 .community(context, request_counter)
68 if let Some(audience) = &self.audience {
69 let audience = audience
70 .dereference(context, local_instance, request_counter)
72 verify_community_matches(&audience, object_community.id)?;