]> Untitled Git - lemmy.git/commitdiff
Move activity structs to protocol folder
authorFelix Ableitner <me@nutomic.com>
Fri, 29 Oct 2021 10:32:42 +0000 (12:32 +0200)
committerFelix Ableitner <me@nutomic.com>
Fri, 29 Oct 2021 10:50:32 +0000 (12:50 +0200)
71 files changed:
crates/api/src/comment.rs
crates/api/src/comment_report.rs
crates/api/src/community.rs
crates/api/src/post.rs
crates/api/src/post_report.rs
crates/api_crud/src/comment/create.rs
crates/api_crud/src/comment/update.rs
crates/api_crud/src/community/update.rs
crates/api_crud/src/post/create.rs
crates/api_crud/src/post/update.rs
crates/api_crud/src/private_message/create.rs
crates/api_crud/src/private_message/delete.rs
crates/api_crud/src/private_message/update.rs
crates/apub/src/activities/comment/create_or_update.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/block_user.rs
crates/apub/src/activities/community/mod.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/report.rs [moved from crates/apub/src/activities/report.rs with 88% similarity]
crates/apub/src/activities/community/undo_block_user.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/mod.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/following/accept.rs
crates/apub/src/activities/following/follow.rs
crates/apub/src/activities/following/mod.rs
crates/apub/src/activities/following/undo_follow.rs [moved from crates/apub/src/activities/following/undo.rs with 79% similarity]
crates/apub/src/activities/mod.rs
crates/apub/src/activities/post/create_or_update.rs
crates/apub/src/activities/private_message/create_or_update.rs
crates/apub/src/activities/private_message/delete.rs
crates/apub/src/activities/private_message/undo_delete.rs
crates/apub/src/activities/voting/mod.rs
crates/apub/src/activities/voting/undo_vote.rs
crates/apub/src/activities/voting/vote.rs
crates/apub/src/activity_lists.rs [new file with mode: 0644]
crates/apub/src/collections/community_outbox.rs
crates/apub/src/http/community.rs
crates/apub/src/http/mod.rs
crates/apub/src/http/person.rs
crates/apub/src/lib.rs
crates/apub/src/protocol/activities/community/add_mod.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/community/announce.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/community/block_user.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/community/mod.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/community/remove_mod.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/community/report.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/community/undo_block_user.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/community/update.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/create_or_update/comment.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/create_or_update/mod.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/create_or_update/post.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/deletion/delete.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/deletion/mod.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/deletion/undo_delete.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/following/accept.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/following/follow.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/following/mod.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/following/undo_follow.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/mod.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/private_message/create_or_update.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/private_message/delete.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/private_message/mod.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/private_message/undo_delete.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/voting/mod.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/voting/undo_vote.rs [new file with mode: 0644]
crates/apub/src/protocol/activities/voting/vote.rs [new file with mode: 0644]
crates/apub/src/protocol/collections/group_outbox.rs
crates/apub/src/protocol/mod.rs

index 62b01b33facbf4c7c96ac20f3af325ca9d50b062..e6eef2cba3c81e3f50f191d66b3cbe2e3a96c730 100644 (file)
@@ -1,5 +1,7 @@
-use crate::Perform;
+use std::convert::TryInto;
+
 use actix_web::web::Data;
+
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -9,11 +11,11 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
 };
 use lemmy_apub::{
-  activities::voting::{
+  fetcher::post_or_comment::PostOrComment,
+  protocol::activities::voting::{
     undo_vote::UndoVote,
     vote::{Vote, VoteType},
   },
-  fetcher::post_or_comment::PostOrComment,
 };
 use lemmy_db_schema::{
   newtypes::LocalUserId,
@@ -23,7 +25,8 @@ use lemmy_db_schema::{
 use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView};
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation};
-use std::convert::TryInto;
+
+use crate::Perform;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for MarkCommentAsRead {
index a7299b7ae508009d79495b78351b845d3f0d9d21..82ecc1f445db4704a9b9029bb311d37049ae314b 100644 (file)
@@ -1,5 +1,5 @@
-use crate::Perform;
 use actix_web::web::Data;
+
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -7,7 +7,7 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
   is_mod_or_admin,
 };
-use lemmy_apub::{activities::report::Report, fetcher::object_id::ObjectId};
+use lemmy_apub::{fetcher::object_id::ObjectId, protocol::activities::community::report::Report};
 use lemmy_db_schema::{source::comment_report::*, traits::Reportable};
 use lemmy_db_views::{
   comment_report_view::{CommentReportQueryBuilder, CommentReportView},
@@ -16,6 +16,8 @@ use lemmy_db_views::{
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
 
+use crate::Perform;
+
 /// Creates a comment report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for CreateCommentReport {
index ac39751c86320a977a5d3668a410d64f5e5ec722..b47a4ec6013dd24e378f24c52a1693e3f766a117 100644 (file)
@@ -10,16 +10,16 @@ use lemmy_api_common::{
   is_mod_or_admin,
 };
 use lemmy_apub::{
-  activities::{
+  objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::{
     community::{
       add_mod::AddMod,
       block_user::BlockUserFromCommunity,
       remove_mod::RemoveMod,
       undo_block_user::UndoBlockUserFromCommunity,
     },
-    following::{follow::FollowCommunity as FollowCommunityApub, undo::UndoFollowCommunity},
+    following::{follow::FollowCommunity as FollowCommunityApub, undo_follow::UndoFollowCommunity},
   },
-  objects::{community::ApubCommunity, person::ApubPerson},
 };
 use lemmy_db_schema::{
   source::{
index 488c8f590aef4c52ab38c5a070ca49be39dffe95..3564f13526f655349af74cbb1ec0f1890791dea0 100644 (file)
@@ -12,16 +12,16 @@ use lemmy_api_common::{
   post::*,
 };
 use lemmy_apub::{
-  activities::{
-    post::create_or_update::CreateOrUpdatePost,
+  fetcher::post_or_comment::PostOrComment,
+  objects::post::ApubPost,
+  protocol::activities::{
+    create_or_update::post::CreateOrUpdatePost,
     voting::{
       undo_vote::UndoVote,
       vote::{Vote, VoteType},
     },
     CreateOrUpdateType,
   },
-  fetcher::post_or_comment::PostOrComment,
-  objects::post::ApubPost,
 };
 use lemmy_db_schema::{
   source::{moderator::*, post::*},
index 3e610bff8f14800b3cdeab017fa3a8976534d21d..98b2f1c119b2ffb3cdc2fa54b09cf96f72ce4ffb 100644 (file)
@@ -1,5 +1,5 @@
-use crate::Perform;
 use actix_web::web::Data;
+
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -13,7 +13,7 @@ use lemmy_api_common::{
     ResolvePostReport,
   },
 };
-use lemmy_apub::{activities::report::Report, fetcher::object_id::ObjectId};
+use lemmy_apub::{fetcher::object_id::ObjectId, protocol::activities::community::report::Report};
 use lemmy_db_schema::{
   source::post_report::{PostReport, PostReportForm},
   traits::Reportable,
@@ -25,6 +25,8 @@ use lemmy_db_views::{
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
 use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
 
+use crate::Perform;
+
 /// Creates a post report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for CreatePostReport {
index 6c90e94e1a95057d055e6b1e71ba5e256a8a63a7..ab093ea194bb246d7f66c7e264452f3568c6d255 100644 (file)
@@ -1,5 +1,5 @@
-use crate::PerformCrud;
 use actix_web::web::Data;
+
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -11,13 +11,13 @@ use lemmy_api_common::{
   get_post,
 };
 use lemmy_apub::{
-  activities::{
-    comment::create_or_update::CreateOrUpdateComment,
+  fetcher::post_or_comment::PostOrComment,
+  generate_local_apub_endpoint,
+  protocol::activities::{
+    create_or_update::comment::CreateOrUpdateComment,
     voting::vote::{Vote, VoteType},
     CreateOrUpdateType,
   },
-  fetcher::post_or_comment::PostOrComment,
-  generate_local_apub_endpoint,
   EndpointType,
 };
 use lemmy_db_schema::{
@@ -40,6 +40,8 @@ use lemmy_websocket::{
   UserOperationCrud,
 };
 
+use crate::PerformCrud;
+
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for CreateComment {
   type Response = CommentResponse;
index 9a164fc3fef1d3508e6719d8f965b57612888981..70f15dfb2c1319a61517cea7280937ad607a42bb 100644 (file)
@@ -1,5 +1,5 @@
-use crate::PerformCrud;
 use actix_web::web::Data;
+
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -8,8 +8,8 @@ use lemmy_api_common::{
   comment::*,
   get_local_user_view_from_jwt,
 };
-use lemmy_apub::activities::{
-  comment::create_or_update::CreateOrUpdateComment,
+use lemmy_apub::protocol::activities::{
+  create_or_update::comment::CreateOrUpdateComment,
   CreateOrUpdateType,
 };
 use lemmy_db_schema::source::comment::Comment;
@@ -26,6 +26,8 @@ use lemmy_websocket::{
   UserOperationCrud,
 };
 
+use crate::PerformCrud;
+
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for EditComment {
   type Response = CommentResponse;
index 97722a98b0c24b05d6ef70bd5a9327bde0eb024b..4764b0254cd44ddecf04f32288d7fec522e3e93a 100644 (file)
@@ -5,7 +5,7 @@ use lemmy_api_common::{
   community::{CommunityResponse, EditCommunity},
   get_local_user_view_from_jwt,
 };
-use lemmy_apub::activities::community::update::UpdateCommunity;
+use lemmy_apub::protocol::activities::community::update::UpdateCommunity;
 use lemmy_db_schema::{
   diesel_option_overwrite_to_url,
   naive_now,
index a6641034175d9d8a412159afce2c5a0ff22336a9..99b67d2eaf46c63debdad966f96bc08b5bf5b4c6 100644 (file)
@@ -1,5 +1,7 @@
-use crate::PerformCrud;
 use actix_web::web::Data;
+use log::warn;
+use webmention::{Webmention, WebmentionError};
+
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -10,13 +12,13 @@ use lemmy_api_common::{
   post::*,
 };
 use lemmy_apub::{
-  activities::{
-    post::create_or_update::CreateOrUpdatePost,
+  fetcher::post_or_comment::PostOrComment,
+  generate_local_apub_endpoint,
+  protocol::activities::{
+    create_or_update::post::CreateOrUpdatePost,
     voting::vote::{Vote, VoteType},
     CreateOrUpdateType,
   },
-  fetcher::post_or_comment::PostOrComment,
-  generate_local_apub_endpoint,
   EndpointType,
 };
 use lemmy_db_schema::{
@@ -31,8 +33,8 @@ use lemmy_utils::{
   LemmyError,
 };
 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
-use log::warn;
-use webmention::{Webmention, WebmentionError};
+
+use crate::PerformCrud;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for CreatePost {
index 96e4400a5a2e1c9ccc9a2256aee765058a03b10d..0a982d688d989bff69b6f254dd6fa73f953c26cb 100644 (file)
@@ -1,5 +1,5 @@
-use crate::PerformCrud;
 use actix_web::web::Data;
+
 use lemmy_api_common::{
   blocking,
   check_community_ban,
@@ -7,7 +7,10 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
   post::*,
 };
-use lemmy_apub::activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType};
+use lemmy_apub::protocol::activities::{
+  create_or_update::post::CreateOrUpdatePost,
+  CreateOrUpdateType,
+};
 use lemmy_db_schema::{
   naive_now,
   source::post::{Post, PostForm},
@@ -22,6 +25,8 @@ use lemmy_utils::{
 };
 use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
 
+use crate::PerformCrud;
+
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for EditPost {
   type Response = PostResponse;
index c7bca4e0249f401555760144d8a8960608741e44..705d781e2b27355118b5455ffca8bb6a24fda749 100644 (file)
@@ -7,11 +7,11 @@ use lemmy_api_common::{
   person::{CreatePrivateMessage, PrivateMessageResponse},
 };
 use lemmy_apub::{
-  activities::{
+  generate_local_apub_endpoint,
+  protocol::activities::{
     private_message::create_or_update::CreateOrUpdatePrivateMessage,
     CreateOrUpdateType,
   },
-  generate_local_apub_endpoint,
   EndpointType,
 };
 use lemmy_db_schema::{
index f369f82b1aa7776324c37a5ad66ec21e018fdbd9..06bc22edeec6eb75f93447d89ec7bd272fa3c4b3 100644 (file)
@@ -5,7 +5,7 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
   person::{DeletePrivateMessage, PrivateMessageResponse},
 };
-use lemmy_apub::activities::private_message::{
+use lemmy_apub::protocol::activities::private_message::{
   delete::DeletePrivateMessage as DeletePrivateMessageApub,
   undo_delete::UndoDeletePrivateMessage,
 };
index d72e3b13772bd6734843aa502c8974856cceb61e..8114556c1f7ab20d4aa6e4c48ddc7607a328ba1b 100644 (file)
@@ -5,7 +5,7 @@ use lemmy_api_common::{
   get_local_user_view_from_jwt,
   person::{EditPrivateMessage, PrivateMessageResponse},
 };
-use lemmy_apub::activities::{
+use lemmy_apub::protocol::activities::{
   private_message::create_or_update::CreateOrUpdatePrivateMessage,
   CreateOrUpdateType,
 };
index d53801aa23d118a5374a95265cf2a82608c6bedf..335e17139bf8b9179f038f98f88eda1473ce0adf 100644 (file)
@@ -1,11 +1,9 @@
-use activitystreams::{link::Mention, public, unparsed::Unparsed};
-use serde::{Deserialize, Serialize};
-use url::Url;
+use activitystreams::public;
 
 use lemmy_api_common::{blocking, check_post_deleted_or_removed};
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
+  traits::{ActivityHandler, ActorType, ApubObject},
   verify::verify_domains_match,
 };
 use lemmy_db_schema::{
@@ -19,37 +17,18 @@ use crate::{
   activities::{
     check_community_deleted_or_removed,
     comment::{collect_non_local_mentions, get_notif_recipients},
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      send_to_community,
-    },
+    community::{announce::GetCommunity, send_to_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
     verify_person_in_community,
-    CreateOrUpdateType,
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
-  protocol::objects::note::Note,
+  protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType},
 };
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct CreateOrUpdateComment {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  object: Note,
-  cc: Vec<Url>,
-  #[serde(default)]
-  tag: Vec<Mention>,
-  #[serde(rename = "type")]
-  kind: CreateOrUpdateType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
-
 impl CreateOrUpdateComment {
   pub async fn send(
     comment: &ApubComment,
index b65fa48e7b1eff72d5eccbe32b9a3341abe8695a..b18e50adaf7d2bc07909d7b592b6a34b7969d907 100644 (file)
@@ -1,10 +1,6 @@
 use crate::{
   activities::{
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      get_community_from_moderators_url,
-      send_to_community,
-    },
+    community::{announce::GetCommunity, get_community_from_moderators_url, send_to_community},
     generate_activity_id,
     verify_activity,
     verify_add_remove_moderator_target,
@@ -12,15 +8,17 @@ use crate::{
     verify_mod_action,
     verify_person_in_community,
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   generate_moderators_url,
   objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::community::add_mod::AddMod,
 };
-use activitystreams::{activity::kind::AddType, public, unparsed::Unparsed};
+use activitystreams::{activity::kind::AddType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
+  traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
   source::community::{CommunityModerator, CommunityModeratorForm},
@@ -28,23 +26,6 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct AddMod {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  object: ObjectId<ApubPerson>,
-  target: Url,
-  cc: Vec<Url>,
-  #[serde(rename = "type")]
-  kind: AddType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl AddMod {
   pub async fn send(
index 007fcbb3cc2549b1da6416a3d546f07fd6e0b33f..62e7c56fd5a15b3a006fe93c3049393111fb288a 100644 (file)
@@ -1,55 +1,27 @@
 use crate::{
   activities::{
-    comment::create_or_update::CreateOrUpdateComment,
-    community::{
-      add_mod::AddMod,
-      block_user::BlockUserFromCommunity,
-      list_community_follower_inboxes,
-      remove_mod::RemoveMod,
-      undo_block_user::UndoBlockUserFromCommunity,
-      update::UpdateCommunity,
-    },
-    deletion::{delete::Delete, undo_delete::UndoDelete},
+    community::list_community_follower_inboxes,
     generate_activity_id,
-    post::create_or_update::CreateOrUpdatePost,
     send_lemmy_activity,
     verify_activity,
     verify_is_public,
-    voting::{undo_vote::UndoVote, vote::Vote},
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   http::is_activity_already_known,
   insert_activity,
   objects::community::ApubCommunity,
+  protocol::activities::community::announce::AnnounceActivity,
 };
-use activitystreams::{activity::kind::AnnounceType, public, unparsed::Unparsed};
+use activitystreams::{activity::kind::AnnounceType, public};
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
-  verify::verify_urls_match,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
 use url::Url;
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
-#[serde(untagged)]
-#[activity_handler(LemmyContext)]
-pub enum AnnouncableActivities {
-  CreateOrUpdateComment(CreateOrUpdateComment),
-  CreateOrUpdatePost(Box<CreateOrUpdatePost>),
-  Vote(Vote),
-  UndoVote(UndoVote),
-  Delete(Delete),
-  UndoDelete(UndoDelete),
-  UpdateCommunity(Box<UpdateCommunity>),
-  BlockUserFromCommunity(BlockUserFromCommunity),
-  UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
-  AddMod(AddMod),
-  RemoveMod(RemoveMod),
-}
-
 #[async_trait::async_trait(?Send)]
 pub(crate) trait GetCommunity {
   async fn get_community(
@@ -59,46 +31,6 @@ pub(crate) trait GetCommunity {
   ) -> Result<ApubCommunity, LemmyError>;
 }
 
-#[async_trait::async_trait(?Send)]
-impl GetCommunity for AnnouncableActivities {
-  async fn get_community(
-    &self,
-    context: &LemmyContext,
-    request_counter: &mut i32,
-  ) -> Result<ApubCommunity, LemmyError> {
-    use AnnouncableActivities::*;
-    let community = match self {
-      CreateOrUpdateComment(a) => a.get_community(context, request_counter).await?,
-      CreateOrUpdatePost(a) => a.get_community(context, request_counter).await?,
-      Vote(a) => a.get_community(context, request_counter).await?,
-      UndoVote(a) => a.get_community(context, request_counter).await?,
-      Delete(a) => a.get_community(context, request_counter).await?,
-      UndoDelete(a) => a.get_community(context, request_counter).await?,
-      UpdateCommunity(a) => a.get_community(context, request_counter).await?,
-      BlockUserFromCommunity(a) => a.get_community(context, request_counter).await?,
-      UndoBlockUserFromCommunity(a) => a.get_community(context, request_counter).await?,
-      AddMod(a) => a.get_community(context, request_counter).await?,
-      RemoveMod(a) => a.get_community(context, request_counter).await?,
-    };
-    verify_urls_match(self.actor(), &community.actor_id())?;
-    Ok(community)
-  }
-}
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct AnnounceActivity {
-  actor: ObjectId<ApubCommunity>,
-  to: Vec<Url>,
-  object: AnnouncableActivities,
-  cc: Vec<Url>,
-  #[serde(rename = "type")]
-  kind: AnnounceType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
-
 impl AnnounceActivity {
   pub async fn send(
     object: AnnouncableActivities,
index 0a716228d360bc26ad77b50b321f401e022025bd..dfe6c4c9256ed588039286413a3a22788287d89d 100644 (file)
@@ -1,23 +1,22 @@
 use crate::{
   activities::{
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      send_to_community,
-    },
+    community::{announce::GetCommunity, send_to_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
     verify_mod_action,
     verify_person_in_community,
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::community::block_user::BlockUserFromCommunity,
 };
-use activitystreams::{activity::kind::BlockType, public, unparsed::Unparsed};
+use activitystreams::{activity::kind::BlockType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
+  traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
   source::community::{
@@ -30,23 +29,6 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct BlockUserFromCommunity {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  pub(in crate::activities::community) object: ObjectId<ApubPerson>,
-  cc: Vec<Url>,
-  target: ObjectId<ApubCommunity>,
-  #[serde(rename = "type")]
-  kind: BlockType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl BlockUserFromCommunity {
   pub(in crate::activities::community) fn new(
index 1f51c0335ae6395ea25461827027ed7b60784789..ebc6e7f9208d5496c3bbd0a74afed5550363000e 100644 (file)
@@ -1,23 +1,25 @@
+use itertools::Itertools;
+use url::Url;
+
+use lemmy_apub_lib::traits::ActorType;
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+
 use crate::{
-  activities::{
-    community::announce::{AnnouncableActivities, AnnounceActivity},
-    send_lemmy_activity,
-  },
+  activities::send_lemmy_activity,
+  activity_lists::AnnouncableActivities,
   check_is_apub_id_valid,
   fetcher::object_id::ObjectId,
   insert_activity,
   objects::community::ApubCommunity,
+  protocol::activities::community::announce::AnnounceActivity,
 };
-use itertools::Itertools;
-use lemmy_apub_lib::traits::ActorType;
-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-use url::Url;
 
 pub mod add_mod;
 pub mod announce;
 pub mod block_user;
 pub mod remove_mod;
+pub mod report;
 pub mod undo_block_user;
 pub mod update;
 
index f0c0b90e1cc7602da644001d59cf9030a7358d18..02ff3c0641ad77abd81882d665c6024b2264a32c 100644 (file)
@@ -1,10 +1,6 @@
 use crate::{
   activities::{
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      get_community_from_moderators_url,
-      send_to_community,
-    },
+    community::{announce::GetCommunity, get_community_from_moderators_url, send_to_community},
     generate_activity_id,
     verify_activity,
     verify_add_remove_moderator_target,
@@ -12,15 +8,17 @@ use crate::{
     verify_mod_action,
     verify_person_in_community,
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   generate_moderators_url,
   objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::community::remove_mod::RemoveMod,
 };
-use activitystreams::{activity::kind::RemoveType, public, unparsed::Unparsed};
+use activitystreams::{activity::kind::RemoveType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
+  traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
   source::community::{CommunityModerator, CommunityModeratorForm},
@@ -28,23 +26,6 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct RemoveMod {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  pub(in crate::activities) object: ObjectId<ApubPerson>,
-  cc: Vec<Url>,
-  #[serde(rename = "type")]
-  kind: RemoveType,
-  pub(in crate::activities) target: Url,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl RemoveMod {
   pub async fn send(
similarity index 88%
rename from crates/apub/src/activities/report.rs
rename to crates/apub/src/activities/community/report.rs
index 9256920a6a74ab43d272b01705405d7974703378..1e7cc5fad96a570895f400ea9b08e781da0346e4 100644 (file)
@@ -1,19 +1,9 @@
-use crate::{
-  activities::{
-    generate_activity_id,
-    send_lemmy_activity,
-    verify_activity,
-    verify_person_in_community,
-  },
-  fetcher::object_id::ObjectId,
-  objects::{community::ApubCommunity, person::ApubPerson},
-  PostOrComment,
-};
-use activitystreams::{activity::kind::FlagType, unparsed::Unparsed};
+use activitystreams::activity::kind::FlagType;
+
 use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse};
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
+  traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
   source::{
@@ -25,22 +15,19 @@ use lemmy_db_schema::{
 use lemmy_db_views::{comment_report_view::CommentReportView, post_report_view::PostReportView};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
-use serde::{Deserialize, Serialize};
-use url::Url;
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct Report {
-  actor: ObjectId<ApubPerson>,
-  to: [ObjectId<ApubCommunity>; 1],
-  object: ObjectId<PostOrComment>,
-  summary: String,
-  #[serde(rename = "type")]
-  kind: FlagType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
+use crate::{
+  activities::{
+    generate_activity_id,
+    send_lemmy_activity,
+    verify_activity,
+    verify_person_in_community,
+  },
+  fetcher::object_id::ObjectId,
+  objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::community::report::Report,
+  PostOrComment,
+};
 
 impl Report {
   pub async fn send(
index ad220c9681afd37af18ed3899244439c660acb4d..2bda94441f2e0eb3f6037ee3c6aebfaf449c0aa5 100644 (file)
@@ -1,24 +1,25 @@
 use crate::{
   activities::{
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      block_user::BlockUserFromCommunity,
-      send_to_community,
-    },
+    community::{announce::GetCommunity, send_to_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
     verify_mod_action,
     verify_person_in_community,
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::community::{
+    block_user::BlockUserFromCommunity,
+    undo_block_user::UndoBlockUserFromCommunity,
+  },
 };
-use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
+use activitystreams::{activity::kind::UndoType, public};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
+  traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
   source::community::{CommunityPersonBan, CommunityPersonBanForm},
@@ -26,22 +27,6 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct UndoBlockUserFromCommunity {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  object: BlockUserFromCommunity,
-  cc: Vec<Url>,
-  #[serde(rename = "type")]
-  kind: UndoType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl UndoBlockUserFromCommunity {
   pub async fn send(
index df34ca289ddf7696d97a47b5e2b040a95d549299..28de0db006b2797ba2419233a396a581192358de 100644 (file)
@@ -1,52 +1,29 @@
-use activitystreams::{activity::kind::UpdateType, public, unparsed::Unparsed};
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::{
-  data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
-};
-use lemmy_db_schema::{
-  source::community::{Community, CommunityForm},
-  traits::Crud,
-};
-use lemmy_utils::LemmyError;
-use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
-
 use crate::{
   activities::{
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      send_to_community,
-    },
+    community::{announce::GetCommunity, send_to_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
     verify_mod_action,
     verify_person_in_community,
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
-  protocol::objects::group::Group,
+  protocol::{activities::community::update::UpdateCommunity, objects::group::Group},
 };
-
-/// This activity is received from a remote community mod, and updates the description or other
-/// fields of a local community.
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct UpdateCommunity {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  // TODO: would be nice to use a separate struct here, which only contains the fields updated here
-  object: Group,
-  cc: Vec<Url>,
-  #[serde(rename = "type")]
-  kind: UpdateType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
+use activitystreams::{activity::kind::UpdateType, public};
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::{
+  data::Data,
+  traits::{ActivityHandler, ActorType, ApubObject},
+};
+use lemmy_db_schema::{
+  source::community::{Community, CommunityForm},
+  traits::Crud,
+};
+use lemmy_utils::LemmyError;
+use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
 
 impl UpdateCommunity {
   pub async fn send(
index 0db590b9a19bea87502022f844d9742d2ec59539..672fca52a53aa80e9fe804318a000141e21f9287 100644 (file)
@@ -1,28 +1,11 @@
-use crate::{
-  activities::{
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      send_to_community,
-    },
-    deletion::{
-      receive_delete_action,
-      verify_delete_activity,
-      DeletableObjects,
-      WebsocketMessages,
-    },
-    generate_activity_id,
-    verify_activity,
-    verify_is_public,
-  },
-  fetcher::object_id::ObjectId,
-  objects::{community::ApubCommunity, person::ApubPerson},
-};
-use activitystreams::{activity::kind::DeleteType, public, unparsed::Unparsed};
+use activitystreams::{activity::kind::DeleteType, public};
 use anyhow::anyhow;
+use url::Url;
+
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
+  traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
   source::{
@@ -46,35 +29,25 @@ use lemmy_websocket::{
   LemmyContext,
   UserOperationCrud,
 };
-use serde::{Deserialize, Serialize};
-use serde_with::skip_serializing_none;
-use url::Url;
 
-/// This is very confusing, because there are four distinct cases to handle:
-/// - user deletes their post
-/// - user deletes their comment
-/// - remote community mod deletes local community
-/// - remote community deletes itself (triggered by a mod)
-///
-/// TODO: we should probably change how community deletions work to simplify this. Probably by
-/// wrapping it in an announce just like other activities, instead of having the community send it.
-#[skip_serializing_none]
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct Delete {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  pub(in crate::activities::deletion) object: Url,
-  pub(in crate::activities::deletion) cc: Vec<Url>,
-  #[serde(rename = "type")]
-  kind: DeleteType,
-  /// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
-  /// deleting their own content.
-  pub(in crate::activities::deletion) summary: Option<String>,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
+use crate::{
+  activities::{
+    community::{announce::GetCommunity, send_to_community},
+    deletion::{
+      receive_delete_action,
+      verify_delete_activity,
+      DeletableObjects,
+      WebsocketMessages,
+    },
+    generate_activity_id,
+    verify_activity,
+    verify_is_public,
+  },
+  activity_lists::AnnouncableActivities,
+  fetcher::object_id::ObjectId,
+  objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::deletion::delete::Delete,
+};
 
 #[async_trait::async_trait(?Send)]
 impl ActivityHandler for Delete {
index 1af02245904f17ddf4c7dfd0b473edadebf12ead..b9c11291fc0e61e2875d5c3e06ede4d8706139ea 100644 (file)
@@ -1,12 +1,5 @@
-use crate::{
-  activities::{
-    deletion::{delete::Delete, undo_delete::UndoDelete},
-    verify_mod_action,
-    verify_person_in_community,
-  },
-  fetcher::object_id::ObjectId,
-  objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
-};
+use url::Url;
+
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   traits::{ActivityFields, ActorType, ApubObject},
@@ -19,7 +12,13 @@ use lemmy_websocket::{
   LemmyContext,
   UserOperationCrud,
 };
-use url::Url;
+
+use crate::{
+  activities::{verify_mod_action, verify_person_in_community},
+  fetcher::object_id::ObjectId,
+  objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson, post::ApubPost},
+  protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
+};
 
 pub mod delete;
 pub mod undo_delete;
index 5cc4dffc2a839c24f2e466733bcd10cf6e47d7d2..c1689119088e09f3eb197d59cd8e04cc84d2160b 100644 (file)
@@ -1,11 +1,24 @@
+use activitystreams::{activity::kind::UndoType, public};
+use anyhow::anyhow;
+use url::Url;
+
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::{
+  data::Data,
+  traits::{ActivityHandler, ActorType},
+};
+use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
+use lemmy_utils::LemmyError;
+use lemmy_websocket::{
+  send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
+  LemmyContext,
+  UserOperationCrud,
+};
+
 use crate::{
   activities::{
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      send_to_community,
-    },
+    community::{announce::GetCommunity, send_to_community},
     deletion::{
-      delete::Delete,
       receive_delete_action,
       verify_delete_activity,
       DeletableObjects,
@@ -15,39 +28,11 @@ use crate::{
     verify_activity,
     verify_is_public,
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
 };
-use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
-use anyhow::anyhow;
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::{
-  data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
-};
-use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
-use lemmy_utils::LemmyError;
-use lemmy_websocket::{
-  send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
-  LemmyContext,
-  UserOperationCrud,
-};
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct UndoDelete {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  object: Delete,
-  cc: Vec<Url>,
-  #[serde(rename = "type")]
-  kind: UndoType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 #[async_trait::async_trait(?Send)]
 impl ActivityHandler for UndoDelete {
index 28f6c10894de75f54baa7a5fac20dbb0b2aa743e..984d622a877b28b3118b9e3222285956216fd2bf 100644 (file)
@@ -1,14 +1,9 @@
 use crate::{
-  activities::{
-    following::follow::FollowCommunity,
-    generate_activity_id,
-    send_lemmy_activity,
-    verify_activity,
-  },
+  activities::{generate_activity_id, send_lemmy_activity, verify_activity},
   fetcher::object_id::ObjectId,
-  objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
 };
-use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed};
+use activitystreams::activity::kind::AcceptType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
@@ -18,21 +13,6 @@ use lemmy_apub_lib::{
 use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct AcceptFollowCommunity {
-  actor: ObjectId<ApubCommunity>,
-  to: [ObjectId<ApubPerson>; 1],
-  object: FollowCommunity,
-  #[serde(rename = "type")]
-  kind: AcceptType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl AcceptFollowCommunity {
   pub async fn send(
index 57a112e0bcb69029cb08730c50207f647470e5aa..e048907fe06f462785cffb97ad26925d19cc6b71 100644 (file)
@@ -1,6 +1,5 @@
 use crate::{
   activities::{
-    following::accept::AcceptFollowCommunity,
     generate_activity_id,
     send_lemmy_activity,
     verify_activity,
@@ -9,12 +8,13 @@ use crate::{
   },
   fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity},
 };
-use activitystreams::{activity::kind::FollowType, unparsed::Unparsed};
+use activitystreams::activity::kind::FollowType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
+  traits::{ActivityHandler, ActorType},
   verify::verify_urls_match,
 };
 use lemmy_db_schema::{
@@ -23,21 +23,6 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct FollowCommunity {
-  pub(in crate::activities::following) actor: ObjectId<ApubPerson>,
-  pub(in crate::activities::following) to: [ObjectId<ApubCommunity>; 1],
-  pub(in crate::activities::following) object: ObjectId<ApubCommunity>,
-  #[serde(rename = "type")]
-  kind: FollowType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl FollowCommunity {
   pub(in crate::activities::following) fn new(
index 050c36916b6041d3172c6c683dffb1e64439fc90..60bdd5f785c5ec3c5b6874d0401fa30c51785e53 100644 (file)
@@ -1,3 +1,3 @@
 pub mod accept;
 pub mod follow;
-pub mod undo;
+pub mod undo_follow;
similarity index 79%
rename from crates/apub/src/activities/following/undo.rs
rename to crates/apub/src/activities/following/undo_follow.rs
index a9326a2689bd787799f1f83ab7a7043dee5f57f2..c3fd78b51b81dd229a28cfd405cbf15c08721ab0 100644 (file)
@@ -1,15 +1,10 @@
 use crate::{
-  activities::{
-    following::follow::FollowCommunity,
-    generate_activity_id,
-    send_lemmy_activity,
-    verify_activity,
-    verify_person,
-  },
+  activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
   fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity},
 };
-use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use activitystreams::activity::kind::UndoType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
@@ -22,21 +17,6 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct UndoFollowCommunity {
-  actor: ObjectId<ApubPerson>,
-  to: [ObjectId<ApubCommunity>; 1],
-  object: FollowCommunity,
-  #[serde(rename = "type")]
-  kind: UndoType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl UndoFollowCommunity {
   pub async fn send(
index 9509babb0e2ab9a1047df340a0f9f5230cbfbd42..bc6cfb512b9f3cef88fe7fd0de77cad6bdb74360 100644 (file)
@@ -22,8 +22,7 @@ use lemmy_db_views_actor::{
 use lemmy_utils::{settings::structs::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
 use log::info;
-use serde::{Deserialize, Serialize};
-use strum_macros::ToString;
+use serde::Serialize;
 use url::{ParseError, Url};
 use uuid::Uuid;
 
@@ -33,15 +32,8 @@ pub mod deletion;
 pub mod following;
 pub mod post;
 pub mod private_message;
-pub mod report;
 pub mod voting;
 
-#[derive(Clone, Debug, ToString, Deserialize, Serialize)]
-pub enum CreateOrUpdateType {
-  Create,
-  Update,
-}
-
 /// Checks that the specified Url actually identifies a Person (by fetching it), and that the person
 /// doesn't have a site ban.
 async fn verify_person(
index ee1bf19c8daa955f40b52865c0db12513d63f3a4..41590493c6bc0d4c37fb43f106051d1e2ab74ddd 100644 (file)
@@ -1,7 +1,5 @@
-use activitystreams::{public, unparsed::Unparsed};
+use activitystreams::public;
 use anyhow::anyhow;
-use serde::{Deserialize, Serialize};
-use url::Url;
 
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
@@ -16,36 +14,19 @@ use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCru
 use crate::{
   activities::{
     check_community_deleted_or_removed,
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      send_to_community,
-    },
+    community::{announce::GetCommunity, send_to_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
     verify_mod_action,
     verify_person_in_community,
-    CreateOrUpdateType,
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
-  protocol::objects::page::Page,
+  protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
 };
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct CreateOrUpdatePost {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  object: Page,
-  cc: Vec<Url>,
-  #[serde(rename = "type")]
-  kind: CreateOrUpdateType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
-
 impl CreateOrUpdatePost {
   pub(crate) async fn new(
     post: &ApubPost,
index 0067607ecb897e8d4ed4a1650bca4bfec12da269..cfd7c8bcfb7f3b2545cce9413bc9da253b5fcfe1 100644 (file)
@@ -1,40 +1,21 @@
 use crate::{
-  activities::{
-    generate_activity_id,
-    send_lemmy_activity,
-    verify_activity,
-    verify_person,
-    CreateOrUpdateType,
-  },
+  activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
   fetcher::object_id::ObjectId,
   objects::{person::ApubPerson, private_message::ApubPrivateMessage},
-  protocol::objects::chat_message::ChatMessage,
+  protocol::activities::{
+    private_message::create_or_update::CreateOrUpdatePrivateMessage,
+    CreateOrUpdateType,
+  },
 };
-use activitystreams::unparsed::Unparsed;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
+  traits::{ActivityHandler, ActorType, ApubObject},
   verify::verify_domains_match,
 };
 use lemmy_db_schema::{source::person::Person, traits::Crud};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct CreateOrUpdatePrivateMessage {
-  id: Url,
-  actor: ObjectId<ApubPerson>,
-  to: [ObjectId<ApubPerson>; 1],
-  object: ChatMessage,
-  #[serde(rename = "type")]
-  kind: CreateOrUpdateType,
-  #[serde(flatten)]
-  pub unparsed: Unparsed,
-}
 
 impl CreateOrUpdatePrivateMessage {
   pub async fn send(
index 0928cba2e1ad73b72e28f5d832c9ce7adcf7bead..da3b6472d100187c40aac117e3f55194082d0ea5 100644 (file)
@@ -2,12 +2,13 @@ use crate::{
   activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
   fetcher::object_id::ObjectId,
   objects::{person::ApubPerson, private_message::ApubPrivateMessage},
+  protocol::activities::private_message::delete::DeletePrivateMessage,
 };
-use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
+use activitystreams::activity::kind::DeleteType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
+  traits::{ActivityHandler, ActorType},
   verify::verify_domains_match,
 };
 use lemmy_db_schema::{
@@ -16,21 +17,6 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct DeletePrivateMessage {
-  actor: ObjectId<ApubPerson>,
-  to: [ObjectId<ApubPerson>; 1],
-  pub(in crate::activities::private_message) object: ObjectId<ApubPrivateMessage>,
-  #[serde(rename = "type")]
-  kind: DeleteType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl DeletePrivateMessage {
   pub(in crate::activities::private_message) fn new(
index 4275ea9cd1d69d1a4aa031caf818ce2734825cd4..bba9e0f22d04a122570dba8c51e3576737ea7a17 100644 (file)
@@ -1,15 +1,13 @@
 use crate::{
-  activities::{
-    generate_activity_id,
-    private_message::delete::DeletePrivateMessage,
-    send_lemmy_activity,
-    verify_activity,
-    verify_person,
-  },
+  activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
   fetcher::object_id::ObjectId,
   objects::{person::ApubPerson, private_message::ApubPrivateMessage},
+  protocol::activities::private_message::{
+    delete::DeletePrivateMessage,
+    undo_delete::UndoDeletePrivateMessage,
+  },
 };
-use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use activitystreams::activity::kind::UndoType;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
@@ -22,21 +20,6 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct UndoDeletePrivateMessage {
-  actor: ObjectId<ApubPerson>,
-  to: [ObjectId<ApubPerson>; 1],
-  object: DeletePrivateMessage,
-  #[serde(rename = "type")]
-  kind: UndoType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl UndoDeletePrivateMessage {
   pub async fn send(
index 829553d35da53d13819cfb70611129fba19d35e3..0a2a8fd1f9b649b0b3abd2031e5b3d19aa8ec6f9 100644 (file)
@@ -1,7 +1,3 @@
-use crate::{
-  activities::voting::vote::VoteType,
-  objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
-};
 use lemmy_api_common::blocking;
 use lemmy_db_schema::{
   source::{
@@ -17,6 +13,11 @@ use lemmy_websocket::{
   UserOperation,
 };
 
+use crate::{
+  objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
+  protocol::activities::voting::vote::VoteType,
+};
+
 pub mod undo_vote;
 pub mod vote;
 
index cc6206616133c78b1cd5aec80363753a93542e74..e95d251799633580889aaad26461a5fa2a9a6029 100644 (file)
@@ -1,50 +1,35 @@
+use std::ops::Deref;
+
+use activitystreams::{activity::kind::UndoType, public};
+
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::{
+  data::Data,
+  traits::{ActivityFields, ActivityHandler, ActorType},
+  verify::verify_urls_match,
+};
+use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+
 use crate::{
   activities::{
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      send_to_community,
-    },
+    community::{announce::GetCommunity, send_to_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
     verify_person_in_community,
-    voting::{
-      undo_vote_comment,
-      undo_vote_post,
-      vote::{Vote, VoteType},
-    },
+    voting::{undo_vote_comment, undo_vote_post},
   },
+  activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::voting::{
+    undo_vote::UndoVote,
+    vote::{Vote, VoteType},
+  },
   PostOrComment,
 };
-use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::{
-  data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
-  verify::verify_urls_match,
-};
-use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use std::ops::Deref;
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct UndoVote {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  object: Vote,
-  cc: Vec<Url>,
-  #[serde(rename = "type")]
-  kind: UndoType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
 
 impl UndoVote {
   pub async fn send(
index 3efef7cf89a00ab22070d687d14ae3026ba674b4..01df4b93eea7cfa22cc1be8d7ab7de96abd0b057 100644 (file)
@@ -1,25 +1,11 @@
-use crate::{
-  activities::{
-    community::{
-      announce::{AnnouncableActivities, GetCommunity},
-      send_to_community,
-    },
-    generate_activity_id,
-    verify_activity,
-    verify_is_public,
-    verify_person_in_community,
-    voting::{vote_comment, vote_post},
-  },
-  fetcher::object_id::ObjectId,
-  objects::{community::ApubCommunity, person::ApubPerson},
-  PostOrComment,
-};
-use activitystreams::{public, unparsed::Unparsed};
-use anyhow::anyhow;
+use std::ops::Deref;
+
+use activitystreams::public;
+
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
-  traits::{ActivityFields, ActivityHandler, ActorType},
+  traits::{ActivityHandler, ActorType},
 };
 use lemmy_db_schema::{
   newtypes::CommunityId,
@@ -28,51 +14,22 @@ use lemmy_db_schema::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use std::{convert::TryFrom, ops::Deref};
-use strum_macros::ToString;
-use url::Url;
-
-#[derive(Clone, Debug, ToString, Deserialize, Serialize)]
-pub enum VoteType {
-  Like,
-  Dislike,
-}
-
-impl TryFrom<i16> for VoteType {
-  type Error = LemmyError;
-
-  fn try_from(value: i16) -> Result<Self, Self::Error> {
-    match value {
-      1 => Ok(VoteType::Like),
-      -1 => Ok(VoteType::Dislike),
-      _ => Err(anyhow!("invalid vote value").into()),
-    }
-  }
-}
-
-impl From<&VoteType> for i16 {
-  fn from(value: &VoteType) -> i16 {
-    match value {
-      VoteType::Like => 1,
-      VoteType::Dislike => -1,
-    }
-  }
-}
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct Vote {
-  actor: ObjectId<ApubPerson>,
-  to: Vec<Url>,
-  pub(in crate::activities::voting) object: ObjectId<PostOrComment>,
-  cc: Vec<Url>,
-  #[serde(rename = "type")]
-  pub(in crate::activities::voting) kind: VoteType,
-  id: Url,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
+use crate::{
+  activities::{
+    community::{announce::GetCommunity, send_to_community},
+    generate_activity_id,
+    verify_activity,
+    verify_is_public,
+    verify_person_in_community,
+    voting::{vote_comment, vote_post},
+  },
+  activity_lists::AnnouncableActivities,
+  fetcher::object_id::ObjectId,
+  objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::voting::vote::{Vote, VoteType},
+  PostOrComment,
+};
 
 impl Vote {
   pub(in crate::activities::voting) fn new(
diff --git a/crates/apub/src/activity_lists.rs b/crates/apub/src/activity_lists.rs
new file mode 100644 (file)
index 0000000..9fd1a9d
--- /dev/null
@@ -0,0 +1,113 @@
+use serde::{Deserialize, Serialize};
+
+use lemmy_apub_lib::{
+  traits::{ActivityFields, ActivityHandler, ActorType},
+  verify::verify_urls_match,
+};
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+
+use crate::{
+  activities::community::announce::GetCommunity,
+  objects::community::ApubCommunity,
+  protocol::activities::{
+    community::{
+      add_mod::AddMod,
+      announce::AnnounceActivity,
+      block_user::BlockUserFromCommunity,
+      remove_mod::RemoveMod,
+      report::Report,
+      undo_block_user::UndoBlockUserFromCommunity,
+      update::UpdateCommunity,
+    },
+    create_or_update::{comment::CreateOrUpdateComment, post::CreateOrUpdatePost},
+    deletion::{delete::Delete, undo_delete::UndoDelete},
+    following::{
+      accept::AcceptFollowCommunity,
+      follow::FollowCommunity,
+      undo_follow::UndoFollowCommunity,
+    },
+    private_message::{
+      create_or_update::CreateOrUpdatePrivateMessage,
+      delete::DeletePrivateMessage,
+      undo_delete::UndoDeletePrivateMessage,
+    },
+    voting::{undo_vote::UndoVote, vote::Vote},
+  },
+};
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
+#[serde(untagged)]
+#[activity_handler(LemmyContext)]
+pub enum SharedInboxActivities {
+  GroupInboxActivities(GroupInboxActivities),
+  // Note, pm activities need to be at the end, otherwise comments will end up here. We can probably
+  // avoid this problem by replacing createpm.object with our own struct, instead of NoteExt.
+  PersonInboxActivities(PersonInboxActivities),
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
+#[serde(untagged)]
+#[activity_handler(LemmyContext)]
+pub enum GroupInboxActivities {
+  FollowCommunity(FollowCommunity),
+  UndoFollowCommunity(UndoFollowCommunity),
+  AnnouncableActivities(AnnouncableActivities),
+  Report(Report),
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
+#[serde(untagged)]
+#[activity_handler(LemmyContext)]
+pub enum PersonInboxActivities {
+  AcceptFollowCommunity(AcceptFollowCommunity),
+  /// Some activities can also be sent from user to user, eg a comment with mentions
+  AnnouncableActivities(AnnouncableActivities),
+  CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
+  DeletePrivateMessage(DeletePrivateMessage),
+  UndoDeletePrivateMessage(UndoDeletePrivateMessage),
+  AnnounceActivity(Box<AnnounceActivity>),
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
+#[serde(untagged)]
+#[activity_handler(LemmyContext)]
+pub enum AnnouncableActivities {
+  CreateOrUpdateComment(CreateOrUpdateComment),
+  CreateOrUpdatePost(Box<CreateOrUpdatePost>),
+  Vote(Vote),
+  UndoVote(UndoVote),
+  Delete(Delete),
+  UndoDelete(UndoDelete),
+  UpdateCommunity(Box<UpdateCommunity>),
+  BlockUserFromCommunity(BlockUserFromCommunity),
+  UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
+  AddMod(AddMod),
+  RemoveMod(RemoveMod),
+}
+
+#[async_trait::async_trait(?Send)]
+impl GetCommunity for AnnouncableActivities {
+  async fn get_community(
+    &self,
+    context: &LemmyContext,
+    request_counter: &mut i32,
+  ) -> Result<ApubCommunity, LemmyError> {
+    use AnnouncableActivities::*;
+    let community = match self {
+      CreateOrUpdateComment(a) => a.get_community(context, request_counter).await?,
+      CreateOrUpdatePost(a) => a.get_community(context, request_counter).await?,
+      Vote(a) => a.get_community(context, request_counter).await?,
+      UndoVote(a) => a.get_community(context, request_counter).await?,
+      Delete(a) => a.get_community(context, request_counter).await?,
+      UndoDelete(a) => a.get_community(context, request_counter).await?,
+      UpdateCommunity(a) => a.get_community(context, request_counter).await?,
+      BlockUserFromCommunity(a) => a.get_community(context, request_counter).await?,
+      UndoBlockUserFromCommunity(a) => a.get_community(context, request_counter).await?,
+      AddMod(a) => a.get_community(context, request_counter).await?,
+      RemoveMod(a) => a.get_community(context, request_counter).await?,
+    };
+    verify_urls_match(self.actor(), &community.actor_id())?;
+    Ok(community)
+  }
+}
index cf5ad8b256fa81a21fc96069a28624dfef6fd6f0..451c3fa941043727138cc7e5687ae18c11b1a413 100644 (file)
@@ -1,12 +1,7 @@
-use crate::{
-  activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType},
-  collections::CommunityContext,
-  generate_outbox_url,
-  objects::{person::ApubPerson, post::ApubPost},
-  protocol::collections::group_outbox::GroupOutbox,
-};
 use activitystreams::collection::kind::OrderedCollectionType;
 use chrono::NaiveDateTime;
+use url::Url;
+
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
@@ -18,7 +13,16 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_utils::LemmyError;
-use url::Url;
+
+use crate::{
+  collections::CommunityContext,
+  generate_outbox_url,
+  objects::{person::ApubPerson, post::ApubPost},
+  protocol::{
+    activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType},
+    collections::group_outbox::GroupOutbox,
+  },
+};
 
 #[derive(Clone, Debug)]
 pub(crate) struct ApubCommunityOutbox(Vec<ApubPost>);
index 0a7cb664c10aacba33baeec6137dda71c8bba545..ffc76d3f4ca454a038485c5b9e1631823a79e425 100644 (file)
@@ -1,23 +1,6 @@
-use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
-use log::info;
-use serde::{Deserialize, Serialize};
-
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::{
-  traits::{ActivityFields, ActivityHandler, ActorType, ApubObject},
-  verify::verify_domains_match,
-};
-use lemmy_db_schema::source::community::Community;
-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-
 use crate::{
-  activities::{
-    community::announce::{AnnouncableActivities, AnnounceActivity, GetCommunity},
-    following::{follow::FollowCommunity, undo::UndoFollowCommunity},
-    report::Report,
-    verify_person_in_community,
-  },
+  activities::{community::announce::GetCommunity, verify_person_in_community},
+  activity_lists::GroupInboxActivities,
   collections::{
     community_moderators::ApubCommunityModerators,
     community_outbox::ApubCommunityOutbox,
@@ -33,8 +16,22 @@ use crate::{
     receive_activity,
   },
   objects::community::ApubCommunity,
-  protocol::collections::group_followers::CommunityFollowers,
+  protocol::{
+    activities::community::announce::AnnounceActivity,
+    collections::group_followers::CommunityFollowers,
+  },
+};
+use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::{
+  traits::{ActivityFields, ActorType, ApubObject},
+  verify::verify_domains_match,
 };
+use lemmy_db_schema::source::community::Community;
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+use log::info;
+use serde::Deserialize;
 
 #[derive(Deserialize)]
 pub(crate) struct CommunityQuery {
@@ -61,16 +58,6 @@ pub(crate) async fn get_apub_community_http(
   }
 }
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
-#[serde(untagged)]
-#[activity_handler(LemmyContext)]
-pub enum GroupInboxActivities {
-  FollowCommunity(FollowCommunity),
-  UndoFollowCommunity(UndoFollowCommunity),
-  AnnouncableActivities(AnnouncableActivities),
-  Report(Report),
-}
-
 /// Handler for all incoming receive to community inboxes.
 pub async fn community_inbox(
   request: HttpRequest,
index 48956cdf28b57225dde041e21befcfddec206e0b..9c61c2747411591bcd459384662ae7606f43c71b 100644 (file)
@@ -1,11 +1,9 @@
 use crate::{
+  activity_lists::SharedInboxActivities,
   check_is_apub_id_valid,
   context::WithContext,
   fetcher::get_or_fetch_and_upsert_actor,
-  http::{
-    community::{receive_group_inbox, GroupInboxActivities},
-    person::{receive_person_inbox, PersonInboxActivities},
-  },
+  http::{community::receive_group_inbox, person::receive_person_inbox},
   insert_activity,
 };
 use actix_web::{
@@ -39,16 +37,6 @@ mod person;
 mod post;
 pub mod routes;
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
-#[serde(untagged)]
-#[activity_handler(LemmyContext)]
-pub enum SharedInboxActivities {
-  GroupInboxActivities(GroupInboxActivities),
-  // Note, pm activities need to be at the end, otherwise comments will end up here. We can probably
-  // avoid this problem by replacing createpm.object with our own struct, instead of NoteExt.
-  PersonInboxActivities(PersonInboxActivities),
-}
-
 pub async fn shared_inbox(
   request: HttpRequest,
   payload: Payload,
index 77bfd69408355400f3904d582d8c5fe204203685..3f18bcc5030d58ffca7bb5e941199a9ee5119854 100644 (file)
@@ -1,23 +1,5 @@
-use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
-use log::info;
-use serde::{Deserialize, Serialize};
-
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::traits::{ActivityFields, ActivityHandler, ApubObject};
-use lemmy_db_schema::source::person::Person;
-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-
 use crate::{
-  activities::{
-    community::announce::{AnnouncableActivities, AnnounceActivity},
-    following::accept::AcceptFollowCommunity,
-    private_message::{
-      create_or_update::CreateOrUpdatePrivateMessage,
-      delete::DeletePrivateMessage,
-      undo_delete::UndoDeletePrivateMessage,
-    },
-  },
+  activity_lists::PersonInboxActivities,
   context::WithContext,
   http::{
     create_apub_response,
@@ -28,6 +10,14 @@ use crate::{
   objects::person::ApubPerson,
   protocol::collections::person_outbox::UserOutbox,
 };
+use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::traits::ApubObject;
+use lemmy_db_schema::source::person::Person;
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+use log::info;
+use serde::Deserialize;
 
 #[derive(Deserialize)]
 pub struct PersonQuery {
@@ -56,19 +46,6 @@ pub(crate) async fn get_apub_person_http(
   }
 }
 
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityHandler, ActivityFields)]
-#[serde(untagged)]
-#[activity_handler(LemmyContext)]
-pub enum PersonInboxActivities {
-  AcceptFollowCommunity(AcceptFollowCommunity),
-  /// Some activities can also be sent from user to user, eg a comment with mentions
-  AnnouncableActivities(AnnouncableActivities),
-  CreateOrUpdatePrivateMessage(CreateOrUpdatePrivateMessage),
-  DeletePrivateMessage(DeletePrivateMessage),
-  UndoDeletePrivateMessage(UndoDeletePrivateMessage),
-  AnnounceActivity(Box<AnnounceActivity>),
-}
-
 pub async fn person_inbox(
   request: HttpRequest,
   payload: Payload,
index d188274bed0ab70335491e4e5421e20754fffad0..f38a9f86d1485ea898f9c59f16837a63ba617acb 100644 (file)
@@ -1,11 +1,12 @@
 pub mod activities;
+pub(crate) mod activity_lists;
 pub(crate) mod collections;
 mod context;
 pub mod fetcher;
 pub mod http;
 pub mod migrations;
 pub mod objects;
-pub(crate) mod protocol;
+pub mod protocol;
 
 #[macro_use]
 extern crate lazy_static;
diff --git a/crates/apub/src/protocol/activities/community/add_mod.rs b/crates/apub/src/protocol/activities/community/add_mod.rs
new file mode 100644 (file)
index 0000000..74ec464
--- /dev/null
@@ -0,0 +1,20 @@
+use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
+use activitystreams::{activity::kind::AddType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct AddMod {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: ObjectId<ApubPerson>,
+  pub(crate) target: Url,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: AddType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/community/announce.rs b/crates/apub/src/protocol/activities/community/announce.rs
new file mode 100644 (file)
index 0000000..2f4e9bd
--- /dev/null
@@ -0,0 +1,23 @@
+use crate::{
+  activity_lists::AnnouncableActivities,
+  fetcher::object_id::ObjectId,
+  objects::community::ApubCommunity,
+};
+use activitystreams::{activity::kind::AnnounceType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct AnnounceActivity {
+  pub(crate) actor: ObjectId<ApubCommunity>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: AnnouncableActivities,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: AnnounceType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/community/block_user.rs b/crates/apub/src/protocol/activities/community/block_user.rs
new file mode 100644 (file)
index 0000000..4ede06a
--- /dev/null
@@ -0,0 +1,23 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::{community::ApubCommunity, person::ApubPerson},
+};
+use activitystreams::{activity::kind::BlockType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct BlockUserFromCommunity {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: ObjectId<ApubPerson>,
+  pub(crate) cc: Vec<Url>,
+  pub(crate) target: ObjectId<ApubCommunity>,
+  #[serde(rename = "type")]
+  pub(crate) kind: BlockType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/community/mod.rs b/crates/apub/src/protocol/activities/community/mod.rs
new file mode 100644 (file)
index 0000000..62f8329
--- /dev/null
@@ -0,0 +1,7 @@
+pub mod add_mod;
+pub mod announce;
+pub mod block_user;
+pub mod remove_mod;
+pub mod report;
+pub mod undo_block_user;
+pub mod update;
diff --git a/crates/apub/src/protocol/activities/community/remove_mod.rs b/crates/apub/src/protocol/activities/community/remove_mod.rs
new file mode 100644 (file)
index 0000000..db30ddb
--- /dev/null
@@ -0,0 +1,20 @@
+use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
+use activitystreams::{activity::kind::RemoveType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct RemoveMod {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: ObjectId<ApubPerson>,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: RemoveType,
+  pub(crate) target: Url,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/community/report.rs b/crates/apub/src/protocol/activities/community/report.rs
new file mode 100644 (file)
index 0000000..5efdd79
--- /dev/null
@@ -0,0 +1,22 @@
+use crate::{
+  fetcher::{object_id::ObjectId, post_or_comment::PostOrComment},
+  objects::{community::ApubCommunity, person::ApubPerson},
+};
+use activitystreams::{activity::kind::FlagType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct Report {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: [ObjectId<ApubCommunity>; 1],
+  pub(crate) object: ObjectId<PostOrComment>,
+  pub(crate) summary: String,
+  #[serde(rename = "type")]
+  pub(crate) kind: FlagType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/community/undo_block_user.rs b/crates/apub/src/protocol/activities/community/undo_block_user.rs
new file mode 100644 (file)
index 0000000..0e89f87
--- /dev/null
@@ -0,0 +1,23 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::person::ApubPerson,
+  protocol::activities::community::block_user::BlockUserFromCommunity,
+};
+use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct UndoBlockUserFromCommunity {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: BlockUserFromCommunity,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: UndoType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/community/update.rs b/crates/apub/src/protocol/activities/community/update.rs
new file mode 100644 (file)
index 0000000..4ba1ed8
--- /dev/null
@@ -0,0 +1,26 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::person::ApubPerson,
+  protocol::objects::group::Group,
+};
+use activitystreams::{activity::kind::UpdateType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+/// This activity is received from a remote community mod, and updates the description or other
+/// fields of a local community.
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct UpdateCommunity {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  // TODO: would be nice to use a separate struct here, which only contains the fields updated here
+  pub(crate) object: Group,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: UpdateType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/create_or_update/comment.rs b/crates/apub/src/protocol/activities/create_or_update/comment.rs
new file mode 100644 (file)
index 0000000..ede7417
--- /dev/null
@@ -0,0 +1,25 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::person::ApubPerson,
+  protocol::{activities::CreateOrUpdateType, objects::note::Note},
+};
+use activitystreams::{link::Mention, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateOrUpdateComment {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: Note,
+  pub(crate) cc: Vec<Url>,
+  #[serde(default)]
+  pub(crate) tag: Vec<Mention>,
+  #[serde(rename = "type")]
+  pub(crate) kind: CreateOrUpdateType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/create_or_update/mod.rs b/crates/apub/src/protocol/activities/create_or_update/mod.rs
new file mode 100644 (file)
index 0000000..38203b5
--- /dev/null
@@ -0,0 +1,2 @@
+pub mod comment;
+pub mod post;
diff --git a/crates/apub/src/protocol/activities/create_or_update/post.rs b/crates/apub/src/protocol/activities/create_or_update/post.rs
new file mode 100644 (file)
index 0000000..03b283e
--- /dev/null
@@ -0,0 +1,23 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::person::ApubPerson,
+  protocol::{activities::CreateOrUpdateType, objects::page::Page},
+};
+use activitystreams::unparsed::Unparsed;
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateOrUpdatePost {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: Page,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: CreateOrUpdateType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/deletion/delete.rs b/crates/apub/src/protocol/activities/deletion/delete.rs
new file mode 100644 (file)
index 0000000..f8e81b4
--- /dev/null
@@ -0,0 +1,24 @@
+use crate::{fetcher::object_id::ObjectId, objects::person::ApubPerson};
+use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use serde_with::skip_serializing_none;
+use url::Url;
+
+#[skip_serializing_none]
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct Delete {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: Url,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: DeleteType,
+  /// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
+  /// deleting their own content.
+  pub(crate) summary: Option<String>,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/deletion/mod.rs b/crates/apub/src/protocol/activities/deletion/mod.rs
new file mode 100644 (file)
index 0000000..b440edd
--- /dev/null
@@ -0,0 +1,2 @@
+pub mod delete;
+pub mod undo_delete;
diff --git a/crates/apub/src/protocol/activities/deletion/undo_delete.rs b/crates/apub/src/protocol/activities/deletion/undo_delete.rs
new file mode 100644 (file)
index 0000000..d962820
--- /dev/null
@@ -0,0 +1,25 @@
+use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use lemmy_apub_lib::traits::ActivityFields;
+
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::person::ApubPerson,
+  protocol::activities::deletion::delete::Delete,
+};
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct UndoDelete {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: Delete,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: UndoType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/following/accept.rs b/crates/apub/src/protocol/activities/following/accept.rs
new file mode 100644 (file)
index 0000000..502a908
--- /dev/null
@@ -0,0 +1,22 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::following::follow::FollowCommunity,
+};
+use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct AcceptFollowCommunity {
+  pub(crate) actor: ObjectId<ApubCommunity>,
+  pub(crate) to: [ObjectId<ApubPerson>; 1],
+  pub(crate) object: FollowCommunity,
+  #[serde(rename = "type")]
+  pub(crate) kind: AcceptType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/following/follow.rs b/crates/apub/src/protocol/activities/following/follow.rs
new file mode 100644 (file)
index 0000000..9dfec21
--- /dev/null
@@ -0,0 +1,21 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::{community::ApubCommunity, person::ApubPerson},
+};
+use activitystreams::{activity::kind::FollowType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct FollowCommunity {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: [ObjectId<ApubCommunity>; 1],
+  pub(crate) object: ObjectId<ApubCommunity>,
+  #[serde(rename = "type")]
+  pub(crate) kind: FollowType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/following/mod.rs b/crates/apub/src/protocol/activities/following/mod.rs
new file mode 100644 (file)
index 0000000..5dc6a3f
--- /dev/null
@@ -0,0 +1,3 @@
+pub(crate) mod accept;
+pub mod follow;
+pub mod undo_follow;
diff --git a/crates/apub/src/protocol/activities/following/undo_follow.rs b/crates/apub/src/protocol/activities/following/undo_follow.rs
new file mode 100644 (file)
index 0000000..be6a7ab
--- /dev/null
@@ -0,0 +1,22 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::{community::ApubCommunity, person::ApubPerson},
+  protocol::activities::following::follow::FollowCommunity,
+};
+use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct UndoFollowCommunity {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: [ObjectId<ApubCommunity>; 1],
+  pub(crate) object: FollowCommunity,
+  #[serde(rename = "type")]
+  pub(crate) kind: UndoType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/mod.rs b/crates/apub/src/protocol/activities/mod.rs
new file mode 100644 (file)
index 0000000..23575c2
--- /dev/null
@@ -0,0 +1,15 @@
+use serde::{Deserialize, Serialize};
+use strum_macros::ToString;
+
+pub mod community;
+pub mod create_or_update;
+pub mod deletion;
+pub mod following;
+pub mod private_message;
+pub mod voting;
+
+#[derive(Clone, Debug, ToString, Deserialize, Serialize)]
+pub enum CreateOrUpdateType {
+  Create,
+  Update,
+}
diff --git a/crates/apub/src/protocol/activities/private_message/create_or_update.rs b/crates/apub/src/protocol/activities/private_message/create_or_update.rs
new file mode 100644 (file)
index 0000000..7632ef9
--- /dev/null
@@ -0,0 +1,22 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::person::ApubPerson,
+  protocol::{activities::CreateOrUpdateType, objects::chat_message::ChatMessage},
+};
+use activitystreams::unparsed::Unparsed;
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct CreateOrUpdatePrivateMessage {
+  pub(crate) id: Url,
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: [ObjectId<ApubPerson>; 1],
+  pub(crate) object: ChatMessage,
+  #[serde(rename = "type")]
+  pub(crate) kind: CreateOrUpdateType,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/private_message/delete.rs b/crates/apub/src/protocol/activities/private_message/delete.rs
new file mode 100644 (file)
index 0000000..499d7d1
--- /dev/null
@@ -0,0 +1,21 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::{person::ApubPerson, private_message::ApubPrivateMessage},
+};
+use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct DeletePrivateMessage {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: [ObjectId<ApubPerson>; 1],
+  pub(crate) object: ObjectId<ApubPrivateMessage>,
+  #[serde(rename = "type")]
+  pub(crate) kind: DeleteType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/private_message/mod.rs b/crates/apub/src/protocol/activities/private_message/mod.rs
new file mode 100644 (file)
index 0000000..4bcda7c
--- /dev/null
@@ -0,0 +1,3 @@
+pub mod create_or_update;
+pub mod delete;
+pub mod undo_delete;
diff --git a/crates/apub/src/protocol/activities/private_message/undo_delete.rs b/crates/apub/src/protocol/activities/private_message/undo_delete.rs
new file mode 100644 (file)
index 0000000..699f6ee
--- /dev/null
@@ -0,0 +1,22 @@
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::person::ApubPerson,
+  protocol::activities::private_message::delete::DeletePrivateMessage,
+};
+use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use lemmy_apub_lib::traits::ActivityFields;
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct UndoDeletePrivateMessage {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: [ObjectId<ApubPerson>; 1],
+  pub(crate) object: DeletePrivateMessage,
+  #[serde(rename = "type")]
+  pub(crate) kind: UndoType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/voting/mod.rs b/crates/apub/src/protocol/activities/voting/mod.rs
new file mode 100644 (file)
index 0000000..4583c23
--- /dev/null
@@ -0,0 +1,2 @@
+pub mod undo_vote;
+pub mod vote;
diff --git a/crates/apub/src/protocol/activities/voting/undo_vote.rs b/crates/apub/src/protocol/activities/voting/undo_vote.rs
new file mode 100644 (file)
index 0000000..0d3e663
--- /dev/null
@@ -0,0 +1,25 @@
+use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
+use serde::{Deserialize, Serialize};
+use url::Url;
+
+use lemmy_apub_lib::traits::ActivityFields;
+
+use crate::{
+  fetcher::object_id::ObjectId,
+  objects::person::ApubPerson,
+  protocol::activities::voting::vote::Vote,
+};
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct UndoVote {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: Vote,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: UndoType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
diff --git a/crates/apub/src/protocol/activities/voting/vote.rs b/crates/apub/src/protocol/activities/voting/vote.rs
new file mode 100644 (file)
index 0000000..fdc87a3
--- /dev/null
@@ -0,0 +1,53 @@
+use crate::{
+  fetcher::{object_id::ObjectId, post_or_comment::PostOrComment},
+  objects::person::ApubPerson,
+};
+use activitystreams::unparsed::Unparsed;
+use anyhow::anyhow;
+use lemmy_apub_lib::traits::ActivityFields;
+use lemmy_utils::LemmyError;
+use serde::{Deserialize, Serialize};
+use std::convert::TryFrom;
+use strum_macros::ToString;
+use url::Url;
+
+#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
+#[serde(rename_all = "camelCase")]
+pub struct Vote {
+  pub(crate) actor: ObjectId<ApubPerson>,
+  pub(crate) to: Vec<Url>,
+  pub(crate) object: ObjectId<PostOrComment>,
+  pub(crate) cc: Vec<Url>,
+  #[serde(rename = "type")]
+  pub(crate) kind: VoteType,
+  pub(crate) id: Url,
+  #[serde(flatten)]
+  pub(crate) unparsed: Unparsed,
+}
+
+#[derive(Clone, Debug, ToString, Deserialize, Serialize)]
+pub enum VoteType {
+  Like,
+  Dislike,
+}
+
+impl TryFrom<i16> for VoteType {
+  type Error = LemmyError;
+
+  fn try_from(value: i16) -> Result<Self, Self::Error> {
+    match value {
+      1 => Ok(VoteType::Like),
+      -1 => Ok(VoteType::Dislike),
+      _ => Err(anyhow!("invalid vote value").into()),
+    }
+  }
+}
+
+impl From<&VoteType> for i16 {
+  fn from(value: &VoteType) -> i16 {
+    match value {
+      VoteType::Like => 1,
+      VoteType::Dislike => -1,
+    }
+  }
+}
index 26da4b6fd1addde2251ccb9b9277b60342535710..3b295003a07ed71dbd97ee0fe00a76641d240114 100644 (file)
@@ -1,4 +1,4 @@
-use crate::activities::post::create_or_update::CreateOrUpdatePost;
+use crate::protocol::activities::create_or_update::post::CreateOrUpdatePost;
 use activitystreams::collection::kind::OrderedCollectionType;
 use serde::{Deserialize, Serialize};
 use url::Url;
index f4ad9e23407d737aeb0c3ebfe3fc4e514baa6e3d..f587dba7e45f0d5cc4db64d141a108030d3f7bb9 100644 (file)
@@ -4,6 +4,7 @@ use url::Url;
 
 use lemmy_apub_lib::values::MediaTypeMarkdown;
 
+pub mod activities;
 pub(crate) mod collections;
 pub(crate) mod objects;