3 community::{announce::GetCommunity, send_activity_in_community},
5 verify_person_in_community,
6 voting::{undo_vote_comment, undo_vote_post},
8 activity_lists::AnnouncableActivities,
10 objects::{community::ApubCommunity, person::ApubPerson},
11 protocol::activities::voting::{
13 vote::{Vote, VoteType},
18 use activitypub_federation::{
19 core::object_id::ObjectId,
21 traits::ActivityHandler,
22 utils::verify_urls_match,
24 use activitystreams_kinds::activity::UndoType;
25 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
26 use lemmy_utils::error::LemmyError;
27 use lemmy_websocket::LemmyContext;
31 /// UndoVote has as:Public value in cc field, unlike other activities. This indicates to other
32 /// software (like GNU social, or presumably Mastodon), that the like actor should not be
34 #[tracing::instrument(skip_all)]
36 object: &PostOrComment,
38 community_id: CommunityId,
40 context: &LemmyContext,
41 ) -> Result<(), LemmyError> {
42 let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
44 let object = Vote::new(object, actor, 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()),
55 let activity = AnnouncableActivities::UndoVote(undo_vote);
56 send_activity_in_community(activity, actor, &community, vec![], context).await
60 #[async_trait::async_trait(?Send)]
61 impl ActivityHandler for UndoVote {
62 type DataType = LemmyContext;
63 type Error = LemmyError;
65 fn id(&self) -> &Url {
69 fn actor(&self) -> &Url {
73 #[tracing::instrument(skip_all)]
76 context: &Data<LemmyContext>,
77 request_counter: &mut i32,
78 ) -> Result<(), LemmyError> {
79 let community = self.get_community(context, request_counter).await?;
80 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
81 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
82 self.object.verify(context, request_counter).await?;
86 #[tracing::instrument(skip_all)]
89 context: &Data<LemmyContext>,
90 request_counter: &mut i32,
91 ) -> Result<(), LemmyError> {
94 .dereference(context, local_instance(context).await, request_counter)
99 .dereference(context, local_instance(context).await, request_counter)
102 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
103 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
108 #[async_trait::async_trait(?Send)]
109 impl GetCommunity for UndoVote {
110 #[tracing::instrument(skip_all)]
111 async fn get_community(
113 context: &LemmyContext,
114 request_counter: &mut i32,
115 ) -> Result<ApubCommunity, LemmyError> {
116 self.object.get_community(context, request_counter).await