]> Untitled Git - lemmy.git/blob - src/apub/inbox/activities/announce.rs
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / src / apub / inbox / activities / announce.rs
1 use crate::{
2   apub::inbox::{
3     activities::{
4       create::receive_create,
5       delete::receive_delete,
6       dislike::receive_dislike,
7       like::receive_like,
8       remove::receive_remove,
9       undo::receive_undo,
10       update::receive_update,
11     },
12     shared_inbox::{get_community_id_from_activity, receive_unhandled_activity},
13   },
14   LemmyContext,
15 };
16 use activitystreams::{
17   activity::*,
18   base::{AnyBase, BaseExt},
19   prelude::ExtendsExt,
20 };
21 use actix_web::HttpResponse;
22 use anyhow::Context;
23 use lemmy_utils::{location_info, LemmyError};
24
25 pub async fn receive_announce(
26   activity: AnyBase,
27   context: &LemmyContext,
28 ) -> Result<HttpResponse, LemmyError> {
29   let announce = Announce::from_any_base(activity)?.context(location_info!())?;
30
31   // ensure that announce and community come from the same instance
32   let community = get_community_id_from_activity(&announce)?;
33   announce.id(community.domain().context(location_info!())?)?;
34
35   let kind = announce.object().as_single_kind_str();
36   let object = announce.object();
37   let object2 = object.clone().one().context(location_info!())?;
38   match kind {
39     Some("Create") => receive_create(object2, context).await,
40     Some("Update") => receive_update(object2, context).await,
41     Some("Like") => receive_like(object2, context).await,
42     Some("Dislike") => receive_dislike(object2, context).await,
43     Some("Delete") => receive_delete(object2, context).await,
44     Some("Remove") => receive_remove(object2, context).await,
45     Some("Undo") => receive_undo(object2, context).await,
46     _ => receive_unhandled_activity(announce),
47   }
48 }