2021-08-02 20:33:40 +00:00
|
|
|
use crate::{
|
|
|
|
activities::{
|
|
|
|
generate_activity_id,
|
|
|
|
verify_person_in_community,
|
2021-10-29 10:32:42 +00:00
|
|
|
voting::{undo_vote_comment, undo_vote_post},
|
2021-08-02 20:33:40 +00:00
|
|
|
},
|
2023-07-14 15:17:06 +00:00
|
|
|
insert_received_activity,
|
2021-10-18 21:36:44 +00:00
|
|
|
objects::{community::ApubCommunity, person::ApubPerson},
|
2022-12-01 20:52:49 +00:00
|
|
|
protocol::{
|
2022-11-28 14:29:33 +00:00
|
|
|
activities::voting::{undo_vote::UndoVote, vote::Vote},
|
2022-12-01 20:52:49 +00:00
|
|
|
InCommunity,
|
2021-10-29 10:32:42 +00:00
|
|
|
},
|
2021-08-02 20:33:40 +00:00
|
|
|
PostOrComment,
|
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{
|
2023-03-21 15:03:05 +00:00
|
|
|
config::Data,
|
|
|
|
kinds::activity::UndoType,
|
|
|
|
protocol::verification::verify_urls_match,
|
|
|
|
traits::{ActivityHandler, Actor},
|
2021-11-03 17:33:51 +00:00
|
|
|
};
|
2022-11-28 14:29:33 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
2024-04-10 14:14:11 +00:00
|
|
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
2022-06-02 14:33:41 +00:00
|
|
|
use url::Url;
|
2021-08-02 20:33:40 +00:00
|
|
|
|
|
|
|
impl UndoVote {
|
2022-11-28 14:29:33 +00:00
|
|
|
pub(in crate::activities::voting) fn new(
|
|
|
|
vote: Vote,
|
2021-10-18 21:36:44 +00:00
|
|
|
actor: &ApubPerson,
|
2022-11-28 14:29:33 +00:00
|
|
|
community: &ApubCommunity,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<Self> {
|
2022-11-28 14:29:33 +00:00
|
|
|
Ok(UndoVote {
|
2023-03-21 15:03:05 +00:00
|
|
|
actor: actor.id().into(),
|
2022-11-28 14:29:33 +00:00
|
|
|
object: vote,
|
2021-08-02 20:33:40 +00:00
|
|
|
kind: UndoType::Undo,
|
2024-10-18 09:02:30 +00:00
|
|
|
id: generate_activity_id(UndoType::Undo)?,
|
2023-03-21 15:03:05 +00:00
|
|
|
audience: Some(community.id().into()),
|
2022-11-28 14:29:33 +00:00
|
|
|
})
|
2021-08-02 20:33:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
#[async_trait::async_trait]
|
2021-08-02 20:33:40 +00:00
|
|
|
impl ActivityHandler for UndoVote {
|
2021-10-06 20:20:05 +00:00
|
|
|
type DataType = LemmyContext;
|
2022-06-02 14:33:41 +00:00
|
|
|
type Error = LemmyError;
|
|
|
|
|
|
|
|
fn id(&self) -> &Url {
|
|
|
|
&self.id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn actor(&self) -> &Url {
|
|
|
|
self.actor.inner()
|
|
|
|
}
|
2021-12-06 14:54:47 +00:00
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
2024-04-10 14:14:11 +00:00
|
|
|
async fn verify(&self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
2023-03-21 15:03:05 +00:00
|
|
|
let community = self.community(context).await?;
|
|
|
|
verify_person_in_community(&self.actor, &community, context).await?;
|
2021-11-03 17:33:51 +00:00
|
|
|
verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
|
2023-03-21 15:03:05 +00:00
|
|
|
self.object.verify(context).await?;
|
2021-08-02 20:33:40 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2024-04-10 14:14:11 +00:00
|
|
|
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
|
2024-01-11 23:56:19 +00:00
|
|
|
insert_received_activity(&self.id, context).await?;
|
2023-03-21 15:03:05 +00:00
|
|
|
let actor = self.actor.dereference(context).await?;
|
|
|
|
let object = self.object.object.dereference(context).await?;
|
2021-08-02 20:33:40 +00:00
|
|
|
match object {
|
2021-11-06 13:25:34 +00:00
|
|
|
PostOrComment::Post(p) => undo_vote_post(actor, &p, context).await,
|
2021-10-12 16:46:26 +00:00
|
|
|
PostOrComment::Comment(c) => undo_vote_comment(actor, &c, context).await,
|
2021-08-02 20:33:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|