3 community::send_activity_in_community,
5 verify_person_in_community,
6 voting::{vote_comment, vote_post},
8 activity_lists::AnnouncableActivities,
10 objects::{community::ApubCommunity, person::ApubPerson},
12 activities::voting::vote::{Vote, VoteType},
18 use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
20 use lemmy_db_schema::{
21 newtypes::CommunityId,
22 source::{community::Community, local_site::LocalSite},
25 use lemmy_utils::error::LemmyError;
26 use lemmy_websocket::LemmyContext;
29 /// Vote has as:Public value in cc field, unlike other activities. This indicates to other software
30 /// (like GNU social, or presumably Mastodon), that the like actor should not be disclosed.
32 pub(in crate::activities::voting) fn new(
33 object: &PostOrComment,
35 community: &ApubCommunity,
37 context: &LemmyContext,
38 ) -> Result<Vote, LemmyError> {
40 actor: ObjectId::new(actor.actor_id()),
41 object: ObjectId::new(object.ap_id()),
43 id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?,
44 audience: Some(ObjectId::new(community.actor_id())),
48 #[tracing::instrument(skip_all)]
50 object: &PostOrComment,
52 community_id: CommunityId,
54 context: &LemmyContext,
55 ) -> Result<(), LemmyError> {
56 let community = Community::read(context.pool(), community_id).await?.into();
57 let vote = Vote::new(object, actor, &community, kind, context)?;
59 let activity = AnnouncableActivities::Vote(vote);
60 send_activity_in_community(activity, actor, &community, vec![], false, context).await
64 #[async_trait::async_trait(?Send)]
65 impl ActivityHandler for Vote {
66 type DataType = LemmyContext;
67 type Error = LemmyError;
69 fn id(&self) -> &Url {
73 fn actor(&self) -> &Url {
77 #[tracing::instrument(skip_all)]
80 context: &Data<LemmyContext>,
81 request_counter: &mut i32,
82 ) -> Result<(), LemmyError> {
83 let community = self.community(context, request_counter).await?;
84 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
85 let enable_downvotes = LocalSite::read(context.pool())
87 .map(|l| l.enable_downvotes)
89 if self.kind == VoteType::Dislike && !enable_downvotes {
90 return Err(anyhow!("Downvotes disabled").into());
95 #[tracing::instrument(skip_all)]
98 context: &Data<LemmyContext>,
99 request_counter: &mut i32,
100 ) -> Result<(), LemmyError> {
103 .dereference(context, local_instance(context).await, request_counter)
107 .dereference(context, local_instance(context).await, request_counter)
110 PostOrComment::Post(p) => vote_post(&self.kind, actor, &p, context).await,
111 PostOrComment::Comment(c) => vote_comment(&self.kind, actor, &c, context).await,