4 verify_person_in_community,
5 voting::{vote_comment, vote_post},
8 objects::{community::ApubCommunity, person::ApubPerson},
10 activities::voting::vote::{Vote, VoteType},
16 use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
18 use lemmy_api_common::context::LemmyContext;
19 use lemmy_db_schema::source::local_site::LocalSite;
20 use lemmy_utils::error::LemmyError;
24 pub(in crate::activities::voting) fn new(
25 object_id: ObjectId<PostOrComment>,
27 community: &ApubCommunity,
29 context: &LemmyContext,
30 ) -> Result<Vote, LemmyError> {
32 actor: ObjectId::new(actor.actor_id()),
35 id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?,
36 audience: Some(ObjectId::new(community.actor_id())),
41 #[async_trait::async_trait(?Send)]
42 impl ActivityHandler for Vote {
43 type DataType = LemmyContext;
44 type Error = LemmyError;
46 fn id(&self) -> &Url {
50 fn actor(&self) -> &Url {
54 #[tracing::instrument(skip_all)]
57 context: &Data<LemmyContext>,
58 request_counter: &mut i32,
59 ) -> Result<(), LemmyError> {
60 let community = self.community(context, request_counter).await?;
61 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
62 let enable_downvotes = LocalSite::read(context.pool())
64 .map(|l| l.enable_downvotes)
66 if self.kind == VoteType::Dislike && !enable_downvotes {
67 return Err(anyhow!("Downvotes disabled").into());
72 #[tracing::instrument(skip_all)]
75 context: &Data<LemmyContext>,
76 request_counter: &mut i32,
77 ) -> Result<(), LemmyError> {
80 .dereference(context, local_instance(context).await, request_counter)
84 .dereference(context, local_instance(context).await, request_counter)
87 PostOrComment::Post(p) => vote_post(&self.kind, actor, &p, context).await,
88 PostOrComment::Comment(c) => vote_comment(&self.kind, actor, &c, context).await,