3 community::{announce::GetCommunity, send_to_community},
7 verify_person_in_community,
8 voting::{undo_vote_comment, undo_vote_post},
10 activity_lists::AnnouncableActivities,
11 fetcher::object_id::ObjectId,
12 objects::{community::ApubCommunity, person::ApubPerson},
13 protocol::activities::voting::{
15 vote::{Vote, VoteType},
19 use activitystreams::{activity::kind::UndoType, public};
20 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;
33 object: &PostOrComment,
35 community_id: CommunityId,
37 context: &LemmyContext,
38 ) -> Result<(), LemmyError> {
39 let community: ApubCommunity = blocking(context.pool(), move |conn| {
40 Community::read(conn, community_id)
45 let object = Vote::new(object, actor, &community, kind.clone(), context)?;
46 let id = generate_activity_id(
48 &context.settings().get_protocol_and_hostname(),
50 let undo_vote = UndoVote {
51 actor: ObjectId::new(actor.actor_id()),
54 cc: vec![community.actor_id()],
57 unparsed: Default::default(),
59 let activity = AnnouncableActivities::UndoVote(undo_vote);
60 send_to_community(activity, &id, actor, &community, vec![], context).await
64 #[async_trait::async_trait(?Send)]
65 impl ActivityHandler for UndoVote {
66 type DataType = LemmyContext;
69 context: &Data<LemmyContext>,
70 request_counter: &mut i32,
71 ) -> Result<(), LemmyError> {
72 verify_is_public(&self.to)?;
73 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
74 let community = self.get_community(context, request_counter).await?;
75 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
76 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
77 self.object.verify(context, request_counter).await?;
83 context: &Data<LemmyContext>,
84 request_counter: &mut i32,
85 ) -> Result<(), LemmyError> {
86 let actor = self.actor.dereference(context, request_counter).await?;
90 .dereference(context, request_counter)
93 PostOrComment::Post(p) => undo_vote_post(actor, p.deref(), context).await,
94 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
99 #[async_trait::async_trait(?Send)]
100 impl GetCommunity for UndoVote {
101 async fn get_community(
103 context: &LemmyContext,
104 request_counter: &mut i32,
105 ) -> Result<ApubCommunity, LemmyError> {
106 self.object.get_community(context, request_counter).await