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()),
54 unparsed: Default::default(),
56 let activity = AnnouncableActivities::UndoVote(undo_vote);
57 send_activity_in_community(activity, actor, &community, vec![], context).await
61 #[async_trait::async_trait(?Send)]
62 impl ActivityHandler for UndoVote {
63 type DataType = LemmyContext;
64 type Error = LemmyError;
66 fn id(&self) -> &Url {
70 fn actor(&self) -> &Url {
74 #[tracing::instrument(skip_all)]
77 context: &Data<LemmyContext>,
78 request_counter: &mut i32,
79 ) -> Result<(), LemmyError> {
80 let community = self.get_community(context, request_counter).await?;
81 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
82 verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
83 self.object.verify(context, request_counter).await?;
87 #[tracing::instrument(skip_all)]
90 context: &Data<LemmyContext>,
91 request_counter: &mut i32,
92 ) -> Result<(), LemmyError> {
95 .dereference(context, local_instance(context).await, request_counter)
100 .dereference(context, local_instance(context).await, request_counter)
103 PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
104 PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
109 #[async_trait::async_trait(?Send)]
110 impl GetCommunity for UndoVote {
111 #[tracing::instrument(skip_all)]
112 async fn get_community(
114 context: &LemmyContext,
115 request_counter: &mut i32,
116 ) -> Result<ApubCommunity, LemmyError> {
117 self.object.get_community(context, request_counter).await