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;
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()),
59 unparsed: Default::default(),
61 let activity = AnnouncableActivities::UndoVote(undo_vote);
62 send_activity_in_community(activity, actor, &community, vec![], context).await
66 #[async_trait::async_trait(?Send)]
67 impl ActivityHandler for UndoVote {
68 type DataType = LemmyContext;
69 type Error = LemmyError;
71 fn id(&self) -> &Url {
75 fn actor(&self) -> &Url {
79 #[tracing::instrument(skip_all)]
82 context: &Data<LemmyContext>,
83 request_counter: &mut i32,
84 ) -> Result<(), LemmyError> {
85 let community = self.get_community(context, request_counter).await?;
86 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
87 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
88 self.object.verify(context, request_counter).await?;
92 #[tracing::instrument(skip_all)]
95 context: &Data<LemmyContext>,
96 request_counter: &mut i32,
97 ) -> Result<(), LemmyError> {
100 .dereference(context, local_instance(context), request_counter)
105 .dereference(context, local_instance(context), request_counter)
108 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
109 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
114 #[async_trait::async_trait(?Send)]
115 impl GetCommunity for UndoVote {
116 #[tracing::instrument(skip_all)]
117 async fn get_community(
119 context: &LemmyContext,
120 request_counter: &mut i32,
121 ) -> Result<ApubCommunity, LemmyError> {
122 self.object.get_community(context, request_counter).await