4 announce::{AnnouncableActivities, GetCommunity},
10 verify_person_in_community,
14 vote::{Vote, VoteType},
17 context::lemmy_context,
18 fetcher::object_id::ObjectId,
19 objects::{community::ApubCommunity, person::ApubPerson},
22 use activitystreams::{
23 activity::kind::UndoType,
25 primitives::OneOrMany,
29 use lemmy_api_common::blocking;
32 traits::{ActivityFields, ActivityHandler, ActorType},
33 verify::verify_urls_match,
35 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
36 use lemmy_utils::LemmyError;
37 use lemmy_websocket::LemmyContext;
38 use serde::{Deserialize, Serialize};
42 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
43 #[serde(rename_all = "camelCase")]
45 actor: ObjectId<ApubPerson>,
49 #[serde(rename = "type")]
52 #[serde(rename = "@context")]
53 context: OneOrMany<AnyBase>,
60 object: &PostOrComment,
62 community_id: CommunityId,
64 context: &LemmyContext,
65 ) -> Result<(), LemmyError> {
66 let community: ApubCommunity = blocking(context.pool(), move |conn| {
67 Community::read(conn, community_id)
72 let object = Vote::new(object, actor, &community, kind.clone(), context)?;
73 let id = generate_activity_id(
75 &context.settings().get_protocol_and_hostname(),
77 let undo_vote = UndoVote {
78 actor: ObjectId::new(actor.actor_id()),
81 cc: vec![community.actor_id()],
84 context: lemmy_context(),
85 unparsed: Default::default(),
87 let activity = AnnouncableActivities::UndoVote(undo_vote);
88 send_to_community(activity, &id, actor, &community, vec![], context).await
92 #[async_trait::async_trait(?Send)]
93 impl ActivityHandler for UndoVote {
94 type DataType = LemmyContext;
97 context: &Data<LemmyContext>,
98 request_counter: &mut i32,
99 ) -> Result<(), LemmyError> {
100 verify_is_public(&self.to)?;
101 verify_activity(self, &context.settings())?;
102 let community = self.get_community(context, request_counter).await?;
103 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
104 verify_urls_match(self.actor(), self.object.actor())?;
105 self.object.verify(context, request_counter).await?;
111 context: &Data<LemmyContext>,
112 request_counter: &mut i32,
113 ) -> Result<(), LemmyError> {
114 let actor = self.actor.dereference(context, request_counter).await?;
118 .dereference(context, request_counter)
121 PostOrComment::Post(p) => undo_vote_post(actor, p.deref(), context).await,
122 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
127 #[async_trait::async_trait(?Send)]
128 impl GetCommunity for UndoVote {
129 async fn get_community(
131 context: &LemmyContext,
132 request_counter: &mut i32,
133 ) -> Result<ApubCommunity, LemmyError> {
134 self.object.get_community(context, request_counter).await