3 use activitystreams::{activity::kind::UndoType, public};
5 use lemmy_api_common::blocking;
8 traits::{ActivityFields, ActivityHandler, ActorType},
9 verify::verify_urls_match,
11 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
12 use lemmy_utils::LemmyError;
13 use lemmy_websocket::LemmyContext;
17 community::{announce::GetCommunity, send_to_community},
21 verify_person_in_community,
22 voting::{undo_vote_comment, undo_vote_post},
24 activity_lists::AnnouncableActivities,
25 fetcher::object_id::ObjectId,
26 objects::{community::ApubCommunity, person::ApubPerson},
27 protocol::activities::voting::{
29 vote::{Vote, VoteType},
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()),
57 cc: vec![community.actor_id()],
60 unparsed: Default::default(),
62 let activity = AnnouncableActivities::UndoVote(undo_vote);
63 send_to_community(activity, &id, actor, &community, vec![], context).await
67 #[async_trait::async_trait(?Send)]
68 impl ActivityHandler for UndoVote {
69 type DataType = LemmyContext;
72 context: &Data<LemmyContext>,
73 request_counter: &mut i32,
74 ) -> Result<(), LemmyError> {
75 verify_is_public(&self.to)?;
76 verify_activity(self, &context.settings())?;
77 let community = self.get_community(context, request_counter).await?;
78 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
79 verify_urls_match(self.actor(), self.object.actor())?;
80 self.object.verify(context, request_counter).await?;
86 context: &Data<LemmyContext>,
87 request_counter: &mut i32,
88 ) -> Result<(), LemmyError> {
89 let actor = self.actor.dereference(context, request_counter).await?;
93 .dereference(context, request_counter)
96 PostOrComment::Post(p) => undo_vote_post(actor, p.deref(), context).await,
97 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
102 #[async_trait::async_trait(?Send)]
103 impl GetCommunity for UndoVote {
104 async fn get_community(
106 context: &LemmyContext,
107 request_counter: &mut i32,
108 ) -> Result<ApubCommunity, LemmyError> {
109 self.object.get_community(context, request_counter).await