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