X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fapub%2Fsrc%2Factivity_lists.rs;h=d4ca20c3368aaffaf94fc1a20d18964966a2bdba;hb=21a87ebaf2e5c038594eb70ef58bd51826259529;hp=70ae1bb8ff4c0fc47e4ba8ef5a07e0d3dbf47ddc;hpb=62663a9f2e91e3e909d96c921c21bea598a57f91;p=lemmy.git diff --git a/crates/apub/src/activity_lists.rs b/crates/apub/src/activity_lists.rs index 70ae1bb8..d4ca20c3 100644 --- a/crates/apub/src/activity_lists.rs +++ b/crates/apub/src/activity_lists.rs @@ -24,20 +24,32 @@ use crate::{ InCommunity, }, }; -use activitypub_federation::{data::Data, deser::context::WithContext, traits::ActivityHandler}; +use activitypub_federation::{config::Data, traits::ActivityHandler}; use lemmy_api_common::context::LemmyContext; use lemmy_utils::error::LemmyError; use serde::{Deserialize, Serialize}; use url::Url; +/// List of activities which the shared inbox can handle. +/// +/// This could theoretically be defined as an enum with variants `GroupInboxActivities` and +/// `PersonInboxActivities`. In practice we need to write it out manually so that priorities +/// are handled correctly. #[derive(Debug, Deserialize, Serialize)] #[serde(untagged)] #[enum_delegate::implement(ActivityHandler)] pub enum SharedInboxActivities { - PersonInboxActivities(Box>), - GroupInboxActivities(Box>), + Follow(Follow), + AcceptFollow(AcceptFollow), + UndoFollow(UndoFollow), + CreateOrUpdatePrivateMessage(CreateOrUpdateChatMessage), + Report(Report), + AnnounceActivity(AnnounceActivity), + /// This is a catch-all and needs to be last + RawAnnouncableActivities(RawAnnouncableActivities), } +/// List of activities which the group inbox can handle. #[derive(Debug, Deserialize, Serialize)] #[serde(untagged)] #[enum_delegate::implement(ActivityHandler)] @@ -45,10 +57,11 @@ pub enum GroupInboxActivities { Follow(Follow), UndoFollow(UndoFollow), Report(Report), - // This is a catch-all and needs to be last + /// This is a catch-all and needs to be last AnnouncableActivities(RawAnnouncableActivities), } +/// List of activities which the person inbox can handle. #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(untagged)] #[enum_delegate::implement(ActivityHandler)] @@ -60,17 +73,8 @@ pub enum PersonInboxActivities { Delete(Delete), UndoDelete(UndoDelete), AnnounceActivity(AnnounceActivity), -} - -/// This is necessary for user inbox, which can also receive some "announcable" activities, -/// eg a comment mention. This needs to be a separate enum so that announcables received in shared -/// inbox can fall through to be parsed as GroupInboxActivities::AnnouncableActivities. -#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(untagged)] -#[enum_delegate::implement(ActivityHandler)] -pub enum PersonInboxActivitiesWithAnnouncable { - PersonInboxActivities(Box), - AnnouncableActivities(Box), + /// User can also receive some "announcable" activities, eg a comment mention. + AnnouncableActivities(AnnouncableActivities), } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -104,29 +108,25 @@ pub enum SiteInboxActivities { DeleteUser(DeleteUser), } -#[async_trait::async_trait(?Send)] +#[async_trait::async_trait] impl InCommunity for AnnouncableActivities { #[tracing::instrument(skip(self, context))] - async fn community( - &self, - context: &LemmyContext, - request_counter: &mut i32, - ) -> Result { + async fn community(&self, context: &Data) -> Result { use AnnouncableActivities::*; match self { - CreateOrUpdateComment(a) => a.community(context, request_counter).await, - CreateOrUpdatePost(a) => a.community(context, request_counter).await, - Vote(a) => a.community(context, request_counter).await, - UndoVote(a) => a.community(context, request_counter).await, - Delete(a) => a.community(context, request_counter).await, - UndoDelete(a) => a.community(context, request_counter).await, - UpdateCommunity(a) => a.community(context, request_counter).await, - BlockUser(a) => a.community(context, request_counter).await, - UndoBlockUser(a) => a.community(context, request_counter).await, - CollectionAdd(a) => a.community(context, request_counter).await, - CollectionRemove(a) => a.community(context, request_counter).await, - LockPost(a) => a.community(context, request_counter).await, - UndoLockPost(a) => a.community(context, request_counter).await, + CreateOrUpdateComment(a) => a.community(context).await, + CreateOrUpdatePost(a) => a.community(context).await, + Vote(a) => a.community(context).await, + UndoVote(a) => a.community(context).await, + Delete(a) => a.community(context).await, + UndoDelete(a) => a.community(context).await, + UpdateCommunity(a) => a.community(context).await, + BlockUser(a) => a.community(context).await, + UndoBlockUser(a) => a.community(context).await, + CollectionAdd(a) => a.community(context).await, + CollectionRemove(a) => a.community(context).await, + LockPost(a) => a.community(context).await, + UndoLockPost(a) => a.community(context).await, Page(_) => unimplemented!(), } } @@ -134,13 +134,11 @@ impl InCommunity for AnnouncableActivities { #[cfg(test)] mod tests { + #![allow(clippy::unwrap_used)] + #![allow(clippy::indexing_slicing)] + use crate::{ - activity_lists::{ - GroupInboxActivities, - PersonInboxActivities, - PersonInboxActivitiesWithAnnouncable, - SiteInboxActivities, - }, + activity_lists::{GroupInboxActivities, PersonInboxActivities, SiteInboxActivities}, protocol::tests::{test_json, test_parse_lemmy_item}, }; @@ -158,16 +156,15 @@ mod tests { fn test_person_inbox() { test_parse_lemmy_item::("assets/lemmy/activities/following/accept.json") .unwrap(); - test_parse_lemmy_item::( + test_parse_lemmy_item::( "assets/lemmy/activities/create_or_update/create_note.json", ) .unwrap(); - test_parse_lemmy_item::( + test_parse_lemmy_item::( "assets/lemmy/activities/create_or_update/create_private_message.json", ) .unwrap(); - test_json::("assets/mastodon/activities/follow.json") - .unwrap(); + test_json::("assets/mastodon/activities/follow.json").unwrap(); } #[test]