3 community::send_activity_in_community,
5 verify_person_in_community,
6 voting::{undo_vote_comment, undo_vote_post},
8 activity_lists::AnnouncableActivities,
10 objects::{community::ApubCommunity, person::ApubPerson},
14 vote::{Vote, VoteType},
21 use activitypub_federation::{
22 core::object_id::ObjectId,
24 traits::ActivityHandler,
25 utils::verify_urls_match,
27 use activitystreams_kinds::activity::UndoType;
28 use lemmy_api_common::LemmyContext;
29 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
30 use lemmy_utils::error::LemmyError;
34 /// UndoVote has as:Public value in cc field, unlike other activities. This indicates to other
35 /// software (like GNU social, or presumably Mastodon), that the like actor should not be
37 #[tracing::instrument(skip_all)]
39 object: &PostOrComment,
41 community_id: CommunityId,
43 context: &LemmyContext,
44 ) -> Result<(), LemmyError> {
45 let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
47 let object = Vote::new(object, actor, &community, kind.clone(), context)?;
48 let id = generate_activity_id(
50 &context.settings().get_protocol_and_hostname(),
52 let undo_vote = UndoVote {
53 actor: ObjectId::new(actor.actor_id()),
57 audience: Some(ObjectId::new(community.actor_id())),
59 let activity = AnnouncableActivities::UndoVote(undo_vote);
60 send_activity_in_community(activity, actor, &community, vec![], false, context).await
64 #[async_trait::async_trait(?Send)]
65 impl ActivityHandler for UndoVote {
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 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
86 self.object.verify(context, request_counter).await?;
90 #[tracing::instrument(skip_all)]
93 context: &Data<LemmyContext>,
94 request_counter: &mut i32,
95 ) -> Result<(), LemmyError> {
98 .dereference(context, local_instance(context).await, request_counter)
103 .dereference(context, local_instance(context).await, request_counter)
106 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
107 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,