-
-
Notifications
You must be signed in to change notification settings - Fork 948
Expand file tree
/
Copy pathundo_vote.rs
More file actions
68 lines (62 loc) · 1.97 KB
/
undo_vote.rs
File metadata and controls
68 lines (62 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::{
check_community_deleted_or_removed,
generate_activity_id,
protocol::voting::{undo_vote::UndoVote, vote::Vote},
voting::{undo_vote_comment, undo_vote_post},
};
use activitypub_federation::{
config::Data,
kinds::activity::UndoType,
protocol::verification::verify_urls_match,
traits::{Activity, Object},
};
use lemmy_api_utils::context::LemmyContext;
use lemmy_apub_objects::{
objects::{PostOrComment, community::ApubCommunity, person::ApubPerson},
utils::{functions::verify_person_in_community, protocol::InCommunity},
};
use lemmy_utils::error::{LemmyError, LemmyResult};
use url::Url;
impl UndoVote {
pub(in crate::voting) fn new(
vote: Vote,
actor: &ApubPerson,
community: &ApubCommunity,
context: &Data<LemmyContext>,
) -> LemmyResult<Self> {
Ok(UndoVote {
actor: actor.id().clone().into(),
object: vote,
kind: UndoType::Undo,
id: generate_activity_id(UndoType::Undo, None, context)?,
audience: Some(community.ap_id.clone().into()),
})
}
}
#[async_trait::async_trait]
impl Activity for UndoVote {
type DataType = LemmyContext;
type Error = LemmyError;
fn id(&self) -> &Url {
&self.id
}
fn actor(&self) -> &Url {
self.actor.inner()
}
async fn verify(&self, context: &Data<LemmyContext>) -> LemmyResult<()> {
let community = self.object.community(context).await?;
check_community_deleted_or_removed(&community)?;
verify_person_in_community(&self.actor, &community, context).await?;
verify_urls_match(self.actor.inner(), self.object.actor.inner())?;
self.object.verify(context).await?;
Ok(())
}
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
let actor = self.actor.dereference(context).await?;
let object = self.object.object.dereference(context).await?;
match object {
PostOrComment::Left(p) => undo_vote_post(actor, &p, context).await,
PostOrComment::Right(c) => undo_vote_comment(actor, &c, context).await,
}
}
}