3 community::{announce::GetCommunity, 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},
11 protocol::activities::voting::{
13 vote::{Vote, VoteType},
18 use activitypub_federation::{
19 core::object_id::ObjectId,
21 traits::ActivityHandler,
22 utils::verify_urls_match,
24 use activitystreams_kinds::{activity::UndoType, public};
25 use lemmy_api_common::utils::blocking;
26 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
27 use lemmy_utils::error::LemmyError;
28 use lemmy_websocket::LemmyContext;
32 /// UndoVote has as:Public value in cc field, unlike other activities. This indicates to other
33 /// software (like GNU social, or presumably Mastodon), that the like actor should not be
35 #[tracing::instrument(skip_all)]
37 object: &PostOrComment,
39 community_id: CommunityId,
41 context: &LemmyContext,
42 ) -> Result<(), LemmyError> {
43 let community: ApubCommunity = blocking(context.pool(), move |conn| {
44 Community::read(conn, community_id)
49 let object = Vote::new(object, actor, &community, kind.clone(), context)?;
50 let id = generate_activity_id(
52 &context.settings().get_protocol_and_hostname(),
54 let undo_vote = UndoVote {
55 actor: ObjectId::new(actor.actor_id()),
56 to: vec![community.actor_id()],
61 unparsed: Default::default(),
63 let activity = AnnouncableActivities::UndoVote(undo_vote);
64 send_activity_in_community(activity, actor, &community, vec![], context).await
68 #[async_trait::async_trait(?Send)]
69 impl ActivityHandler for UndoVote {
70 type DataType = LemmyContext;
71 type Error = LemmyError;
73 fn id(&self) -> &Url {
77 fn actor(&self) -> &Url {
81 #[tracing::instrument(skip_all)]
84 context: &Data<LemmyContext>,
85 request_counter: &mut i32,
86 ) -> Result<(), LemmyError> {
87 let community = self.get_community(context, request_counter).await?;
88 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
89 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
90 self.object.verify(context, request_counter).await?;
94 #[tracing::instrument(skip_all)]
97 context: &Data<LemmyContext>,
98 request_counter: &mut i32,
99 ) -> Result<(), LemmyError> {
102 .dereference(context, local_instance(context), request_counter)
107 .dereference(context, local_instance(context), request_counter)
110 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
111 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
116 #[async_trait::async_trait(?Send)]
117 impl GetCommunity for UndoVote {
118 #[tracing::instrument(skip_all)]
119 async fn get_community(
121 context: &LemmyContext,
122 request_counter: &mut i32,
123 ) -> Result<ApubCommunity, LemmyError> {
124 self.object.get_community(context, request_counter).await