3 community::{announce::GetCommunity, send_activity_in_community},
6 verify_person_in_community,
7 voting::{undo_vote_comment, undo_vote_post},
9 activity_lists::AnnouncableActivities,
11 objects::{community::ApubCommunity, person::ApubPerson},
12 protocol::activities::voting::{
14 vote::{Vote, VoteType},
19 use activitypub_federation::{
20 core::object_id::ObjectId,
22 traits::ActivityHandler,
23 utils::verify_urls_match,
25 use activitystreams_kinds::{activity::UndoType, public};
26 use lemmy_api_common::utils::blocking;
27 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
28 use lemmy_utils::error::LemmyError;
29 use lemmy_websocket::LemmyContext;
33 /// UndoVote has as:Public value in cc field, unlike other activities. This indicates to other
34 /// software (like GNU social, or presumably Mastodon), that the like actor should not be
36 #[tracing::instrument(skip_all)]
38 object: &PostOrComment,
40 community_id: CommunityId,
42 context: &LemmyContext,
43 ) -> Result<(), LemmyError> {
44 let community: ApubCommunity = blocking(context.pool(), move |conn| {
45 Community::read(conn, community_id)
50 let object = Vote::new(object, actor, &community, kind.clone(), context)?;
51 let id = generate_activity_id(
53 &context.settings().get_protocol_and_hostname(),
55 let undo_vote = UndoVote {
56 actor: ObjectId::new(actor.actor_id()),
57 to: vec![community.actor_id()],
62 unparsed: Default::default(),
64 let activity = AnnouncableActivities::UndoVote(undo_vote);
65 send_activity_in_community(activity, &id, actor, &community, vec![], context).await
69 #[async_trait::async_trait(?Send)]
70 impl ActivityHandler for UndoVote {
71 type DataType = LemmyContext;
72 type Error = LemmyError;
74 fn id(&self) -> &Url {
78 fn actor(&self) -> &Url {
82 #[tracing::instrument(skip_all)]
85 context: &Data<LemmyContext>,
86 request_counter: &mut i32,
87 ) -> Result<(), LemmyError> {
88 verify_is_public(&self.to, &self.cc)?;
89 let community = self.get_community(context, request_counter).await?;
90 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
91 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
92 self.object.verify(context, request_counter).await?;
96 #[tracing::instrument(skip_all)]
99 context: &Data<LemmyContext>,
100 request_counter: &mut i32,
101 ) -> Result<(), LemmyError> {
104 .dereference::<LemmyError>(context, local_instance(context), request_counter)
109 .dereference::<LemmyError>(context, local_instance(context), request_counter)
112 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
113 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
118 #[async_trait::async_trait(?Send)]
119 impl GetCommunity for UndoVote {
120 #[tracing::instrument(skip_all)]
121 async fn get_community(
123 context: &LemmyContext,
124 request_counter: &mut i32,
125 ) -> Result<ApubCommunity, LemmyError> {
126 self.object.get_community(context, request_counter).await