]> Untitled Git - lemmy.git/blob - server/src/apub/inbox/activities/announce.rs
Some apub fixes
[lemmy.git] / server / 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   routes::ChatServerParam,
15   DbPool,
16   LemmyError,
17 };
18 use activitystreams::{
19   activity::*,
20   base::{AnyBase, BaseExt},
21   prelude::ExtendsExt,
22 };
23 use actix_web::{client::Client, HttpResponse};
24
25 pub async fn receive_announce(
26   activity: AnyBase,
27   client: &Client,
28   pool: &DbPool,
29   chat_server: ChatServerParam,
30 ) -> Result<HttpResponse, LemmyError> {
31   let announce = Announce::from_any_base(activity)?.unwrap();
32
33   // ensure that announce and community come from the same instance
34   let community = get_community_id_from_activity(&announce)?;
35   announce.id(community.domain().unwrap())?;
36
37   let kind = announce.object().as_single_kind_str();
38   let object = announce.object();
39   let object2 = object.clone().one().unwrap();
40   match kind {
41     Some("Create") => receive_create(object2, client, pool, chat_server).await,
42     Some("Update") => receive_update(object2, client, pool, chat_server).await,
43     Some("Like") => receive_like(object2, client, pool, chat_server).await,
44     Some("Dislike") => receive_dislike(object2, client, pool, chat_server).await,
45     Some("Delete") => receive_delete(object2, client, pool, chat_server).await,
46     Some("Remove") => receive_remove(object2, client, pool, chat_server).await,
47     Some("Undo") => receive_undo(object2, client, pool, chat_server).await,
48     _ => receive_unhandled_activity(announce),
49   }
50 }