4 announce::{AnnouncableActivities, GetCommunity},
10 verify_person_in_community,
14 vote::{Vote, VoteType},
17 fetcher::object_id::ObjectId,
18 objects::{community::ApubCommunity, person::ApubPerson},
21 use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
22 use lemmy_api_common::blocking;
25 traits::{ActivityFields, ActivityHandler, ActorType},
26 verify::verify_urls_match,
28 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
29 use lemmy_utils::LemmyError;
30 use lemmy_websocket::LemmyContext;
31 use serde::{Deserialize, Serialize};
35 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
36 #[serde(rename_all = "camelCase")]
38 actor: ObjectId<ApubPerson>,
42 #[serde(rename = "type")]
51 object: &PostOrComment,
53 community_id: CommunityId,
55 context: &LemmyContext,
56 ) -> Result<(), LemmyError> {
57 let community: ApubCommunity = blocking(context.pool(), move |conn| {
58 Community::read(conn, community_id)
63 let object = Vote::new(object, actor, &community, kind.clone(), context)?;
64 let id = generate_activity_id(
66 &context.settings().get_protocol_and_hostname(),
68 let undo_vote = UndoVote {
69 actor: ObjectId::new(actor.actor_id()),
72 cc: vec![community.actor_id()],
75 unparsed: Default::default(),
77 let activity = AnnouncableActivities::UndoVote(undo_vote);
78 send_to_community(activity, &id, actor, &community, vec![], context).await
82 #[async_trait::async_trait(?Send)]
83 impl ActivityHandler for UndoVote {
84 type DataType = LemmyContext;
87 context: &Data<LemmyContext>,
88 request_counter: &mut i32,
89 ) -> Result<(), LemmyError> {
90 verify_is_public(&self.to)?;
91 verify_activity(self, &context.settings())?;
92 let community = self.get_community(context, request_counter).await?;
93 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
94 verify_urls_match(self.actor(), self.object.actor())?;
95 self.object.verify(context, request_counter).await?;
101 context: &Data<LemmyContext>,
102 request_counter: &mut i32,
103 ) -> Result<(), LemmyError> {
104 let actor = self.actor.dereference(context, request_counter).await?;
108 .dereference(context, request_counter)
111 PostOrComment::Post(p) => undo_vote_post(actor, p.deref(), context).await,
112 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
117 #[async_trait::async_trait(?Send)]
118 impl GetCommunity for UndoVote {
119 async fn get_community(
121 context: &LemmyContext,
122 request_counter: &mut i32,
123 ) -> Result<ApubCommunity, LemmyError> {
124 self.object.get_community(context, request_counter).await