3 community::{announce::GetCommunity, send_activity_in_community},
7 verify_person_in_community,
8 voting::{undo_vote_comment, undo_vote_post},
10 activity_lists::AnnouncableActivities,
11 objects::{community::ApubCommunity, person::ApubPerson},
12 protocol::activities::voting::{
14 vote::{Vote, VoteType},
18 use activitystreams_kinds::{activity::UndoType, public};
19 use lemmy_api_common::blocking;
23 traits::{ActivityHandler, ActorType},
24 verify::verify_urls_match,
26 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
27 use lemmy_utils::LemmyError;
28 use lemmy_websocket::LemmyContext;
31 /// UndoVote has as:Public value in cc field, unlike other activities. This indicates to other
32 /// software (like GNU social, or presumably Mastodon), that the like actor should not be
34 #[tracing::instrument(skip_all)]
36 object: &PostOrComment,
38 community_id: CommunityId,
40 context: &LemmyContext,
41 ) -> Result<(), LemmyError> {
42 let community: ApubCommunity = blocking(context.pool(), move |conn| {
43 Community::read(conn, community_id)
48 let object = Vote::new(object, actor, &community, kind.clone(), context)?;
49 let id = generate_activity_id(
51 &context.settings().get_protocol_and_hostname(),
53 let undo_vote = UndoVote {
54 actor: ObjectId::new(actor.actor_id()),
55 to: vec![community.actor_id()],
60 unparsed: Default::default(),
62 let activity = AnnouncableActivities::UndoVote(undo_vote);
63 send_activity_in_community(activity, &id, actor, &community, vec![], context).await
67 #[async_trait::async_trait(?Send)]
68 impl ActivityHandler for UndoVote {
69 type DataType = LemmyContext;
71 #[tracing::instrument(skip_all)]
74 context: &Data<LemmyContext>,
75 request_counter: &mut i32,
76 ) -> Result<(), LemmyError> {
77 verify_is_public(&self.to, &self.cc)?;
78 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
79 let community = self.get_community(context, request_counter).await?;
80 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
81 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
82 self.object.verify(context, request_counter).await?;
86 #[tracing::instrument(skip_all)]
89 context: &Data<LemmyContext>,
90 request_counter: &mut i32,
91 ) -> Result<(), LemmyError> {
94 .dereference(context, context.client(), request_counter)
99 .dereference(context, context.client(), request_counter)
102 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
103 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
108 #[async_trait::async_trait(?Send)]
109 impl GetCommunity for UndoVote {
110 #[tracing::instrument(skip_all)]
111 async fn get_community(
113 context: &LemmyContext,
114 request_counter: &mut i32,
115 ) -> Result<ApubCommunity, LemmyError> {
116 self.object.get_community(context, request_counter).await