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 fetch_local_site_data,
12 objects::{community::ApubCommunity, person::ApubPerson},
13 protocol::activities::voting::{
15 vote::{Vote, VoteType},
20 use activitypub_federation::{
21 core::object_id::ObjectId,
23 traits::ActivityHandler,
24 utils::verify_urls_match,
26 use activitystreams_kinds::activity::UndoType;
27 use lemmy_api_common::utils::blocking;
28 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
29 use lemmy_utils::error::LemmyError;
30 use lemmy_websocket::LemmyContext;
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 = blocking(context.pool(), move |conn| {
46 Community::read(conn, community_id)
51 let object = Vote::new(object, actor, kind.clone(), context)?;
52 let id = generate_activity_id(
54 &context.settings().get_protocol_and_hostname(),
56 let undo_vote = UndoVote {
57 actor: ObjectId::new(actor.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 local_site_data = blocking(context.pool(), fetch_local_site_data).await??;
88 check_apub_id_valid(self.id(), &local_site_data, context.settings())
89 .map_err(LemmyError::from_message)?;
90 let community = self.get_community(context, request_counter).await?;
91 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
92 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
93 self.object.verify(context, request_counter).await?;
97 #[tracing::instrument(skip_all)]
100 context: &Data<LemmyContext>,
101 request_counter: &mut i32,
102 ) -> Result<(), LemmyError> {
105 .dereference(context, local_instance(context), request_counter)
110 .dereference(context, local_instance(context), request_counter)
113 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
114 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
119 #[async_trait::async_trait(?Send)]
120 impl GetCommunity for UndoVote {
121 #[tracing::instrument(skip_all)]
122 async fn get_community(
124 context: &LemmyContext,
125 request_counter: &mut i32,
126 ) -> Result<ApubCommunity, LemmyError> {
127 self.object.get_community(context, request_counter).await