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 objects::{community::ApubCommunity, person::ApubPerson},
12 protocol::activities::voting::{
14 vote::{Vote, VoteType},
18 use activitystreams::{activity::kind::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;
32 object: &PostOrComment,
34 community_id: CommunityId,
36 context: &LemmyContext,
37 ) -> Result<(), LemmyError> {
38 let community: ApubCommunity = blocking(context.pool(), move |conn| {
39 Community::read(conn, community_id)
44 let object = Vote::new(object, actor, &community, kind.clone(), context)?;
45 let id = generate_activity_id(
47 &context.settings().get_protocol_and_hostname(),
49 let undo_vote = UndoVote {
50 actor: ObjectId::new(actor.actor_id()),
53 cc: vec![community.actor_id()],
56 unparsed: Default::default(),
58 let activity = AnnouncableActivities::UndoVote(undo_vote);
59 send_to_community(activity, &id, actor, &community, vec![], context).await
63 #[async_trait::async_trait(?Send)]
64 impl ActivityHandler for UndoVote {
65 type DataType = LemmyContext;
68 context: &Data<LemmyContext>,
69 request_counter: &mut i32,
70 ) -> Result<(), LemmyError> {
71 verify_is_public(&self.to)?;
72 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
73 let community = self.get_community(context, request_counter).await?;
74 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
75 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
76 self.object.verify(context, request_counter).await?;
82 context: &Data<LemmyContext>,
83 request_counter: &mut i32,
84 ) -> Result<(), LemmyError> {
85 let actor = self.actor.dereference(context, request_counter).await?;
89 .dereference(context, request_counter)
92 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
93 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
98 #[async_trait::async_trait(?Send)]
99 impl GetCommunity for UndoVote {
100 async fn get_community(
102 context: &LemmyContext,
103 request_counter: &mut i32,
104 ) -> Result<ApubCommunity, LemmyError> {
105 self.object.get_community(context, request_counter).await