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, 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()),
60 unparsed: Default::default(),
62 let activity = AnnouncableActivities::UndoVote(undo_vote);
63 send_activity_in_community(activity, actor, &community, vec![], context).await
67 #[async_trait::async_trait(?Send)]
68 impl ActivityHandler for UndoVote {
69 type DataType = LemmyContext;
70 type Error = LemmyError;
72 fn id(&self) -> &Url {
76 fn actor(&self) -> &Url {
80 #[tracing::instrument(skip_all)]
83 context: &Data<LemmyContext>,
84 request_counter: &mut i32,
85 ) -> Result<(), LemmyError> {
86 let community = self.get_community(context, request_counter).await?;
87 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
88 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
89 self.object.verify(context, request_counter).await?;
93 #[tracing::instrument(skip_all)]
96 context: &Data<LemmyContext>,
97 request_counter: &mut i32,
98 ) -> Result<(), LemmyError> {
101 .dereference(context, local_instance(context), request_counter)
106 .dereference(context, local_instance(context), request_counter)
109 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
110 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
115 #[async_trait::async_trait(?Send)]
116 impl GetCommunity for UndoVote {
117 #[tracing::instrument(skip_all)]
118 async fn get_community(
120 context: &LemmyContext,
121 request_counter: &mut i32,
122 ) -> Result<ApubCommunity, LemmyError> {
123 self.object.get_community(context, request_counter).await