-
-
Notifications
You must be signed in to change notification settings - Fork 948
Expand file tree
/
Copy pathreject.rs
More file actions
71 lines (63 loc) · 2.26 KB
/
reject.rs
File metadata and controls
71 lines (63 loc) · 2.26 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
69
70
71
use super::send_activity_from_user_or_community_or_multi;
use crate::{
check_community_deleted_or_removed,
generate_activity_id,
protocol::following::{follow::Follow, reject::RejectFollow},
};
use activitypub_federation::{
config::Data,
kinds::activity::RejectType,
protocol::verification::verify_urls_match,
traits::{Activity, Actor, Object},
};
use lemmy_api_utils::context::LemmyContext;
use lemmy_db_schema::{
source::{activity::ActivitySendTargets, community::CommunityActions},
traits::Followable,
};
use lemmy_utils::error::{LemmyError, LemmyResult, UntranslatedError};
use url::Url;
impl RejectFollow {
pub async fn send(follow: Follow, context: &Data<LemmyContext>) -> LemmyResult<()> {
let user_or_community = follow.object.dereference_local(context).await?;
let person = follow.actor.clone().dereference(context).await?;
let reject = RejectFollow {
actor: user_or_community.id().clone().into(),
to: Some([person.id().clone().into()]),
object: follow,
kind: RejectType::Reject,
id: generate_activity_id(RejectType::Reject, None, context)?,
};
let inbox = ActivitySendTargets::to_inbox(person.shared_inbox_or_inbox());
send_activity_from_user_or_community_or_multi(context, reject, user_or_community, inbox).await
}
}
/// Handle rejected follows
#[async_trait::async_trait]
impl Activity for RejectFollow {
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<()> {
verify_urls_match(self.actor.inner(), self.object.object.inner())?;
self.object.verify(context).await?;
if let Some(to) = &self.to {
verify_urls_match(to[0].inner(), self.object.actor.inner())?;
}
Ok(())
}
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
let community = self.actor.dereference(context).await?;
check_community_deleted_or_removed(&community)?;
let actor = self.object.actor.dereference(context).await?;
let person = actor.left().ok_or(UntranslatedError::Unreachable)?;
// remove the follow
CommunityActions::unfollow(&mut context.pool(), person.id, community.id).await?;
Ok(())
}
}