]> Untitled Git - lemmy.git/commitdiff
Add SendActivity trait so that api crates compile in parallel with lemmy_apub
authorFelix Ableitner <me@nutomic.com>
Mon, 28 Nov 2022 14:29:33 +0000 (15:29 +0100)
committerFelix Ableitner <me@nutomic.com>
Fri, 2 Dec 2022 09:46:49 +0000 (10:46 +0100)
180 files changed:
Cargo.lock
Cargo.toml
api_tests/src/community.spec.ts
api_tests/src/follow.spec.ts
crates/api/Cargo.toml
crates/api/src/comment/like.rs
crates/api/src/comment/save.rs
crates/api/src/comment_report/create.rs
crates/api/src/comment_report/list.rs
crates/api/src/comment_report/resolve.rs
crates/api/src/community/add_mod.rs
crates/api/src/community/ban.rs
crates/api/src/community/block.rs
crates/api/src/community/follow.rs
crates/api/src/community/hide.rs
crates/api/src/community/transfer.rs
crates/api/src/lib.rs
crates/api/src/local_user/add_admin.rs
crates/api/src/local_user/ban_person.rs
crates/api/src/local_user/block.rs
crates/api/src/local_user/change_password.rs
crates/api/src/local_user/change_password_after_reset.rs
crates/api/src/local_user/get_captcha.rs
crates/api/src/local_user/list_banned.rs
crates/api/src/local_user/login.rs
crates/api/src/local_user/notifications/list_mentions.rs
crates/api/src/local_user/notifications/list_replies.rs
crates/api/src/local_user/notifications/mark_all_read.rs
crates/api/src/local_user/notifications/mark_mention_read.rs
crates/api/src/local_user/notifications/mark_reply_read.rs
crates/api/src/local_user/notifications/unread_count.rs
crates/api/src/local_user/report_count.rs
crates/api/src/local_user/reset_password.rs
crates/api/src/local_user/save_settings.rs
crates/api/src/local_user/verify_email.rs
crates/api/src/post/get_link_metadata.rs
crates/api/src/post/like.rs
crates/api/src/post/lock.rs
crates/api/src/post/mark_read.rs
crates/api/src/post/save.rs
crates/api/src/post/sticky.rs
crates/api/src/post_report/create.rs
crates/api/src/post_report/list.rs
crates/api/src/post_report/resolve.rs
crates/api/src/private_message/mark_read.rs
crates/api/src/private_message_report/create.rs
crates/api/src/private_message_report/list.rs
crates/api/src/private_message_report/resolve.rs
crates/api/src/site/leave_admin.rs
crates/api/src/site/mod.rs
crates/api/src/site/mod_log.rs
crates/api/src/site/purge/comment.rs
crates/api/src/site/purge/community.rs
crates/api/src/site/purge/person.rs
crates/api/src/site/purge/post.rs
crates/api/src/site/registration_applications/approve.rs
crates/api/src/site/registration_applications/list.rs
crates/api/src/site/registration_applications/unread_count.rs
crates/api/src/websocket.rs
crates/api_common/src/context.rs [new file with mode: 0644]
crates/api_common/src/lib.rs
crates/api_common/src/person.rs
crates/api_common/src/utils.rs
crates/api_common/src/websocket/chat_server.rs
crates/api_common/src/websocket/mod.rs
crates/api_common/src/websocket/routes.rs
crates/api_common/src/websocket/send.rs
crates/api_crud/Cargo.toml
crates/api_crud/src/comment/create.rs
crates/api_crud/src/comment/delete.rs
crates/api_crud/src/comment/mod.rs
crates/api_crud/src/comment/read.rs
crates/api_crud/src/comment/remove.rs
crates/api_crud/src/comment/update.rs
crates/api_crud/src/community/create.rs
crates/api_crud/src/community/delete.rs
crates/api_crud/src/community/list.rs
crates/api_crud/src/community/mod.rs
crates/api_crud/src/community/remove.rs
crates/api_crud/src/community/update.rs
crates/api_crud/src/lib.rs
crates/api_crud/src/post/create.rs
crates/api_crud/src/post/delete.rs
crates/api_crud/src/post/mod.rs
crates/api_crud/src/post/read.rs
crates/api_crud/src/post/remove.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/read.rs
crates/api_crud/src/private_message/update.rs
crates/api_crud/src/site/create.rs
crates/api_crud/src/site/read.rs
crates/api_crud/src/site/update.rs
crates/api_crud/src/user/create.rs
crates/api_crud/src/user/delete.rs
crates/api_crud/src/user/mod.rs
crates/apub/src/activities/block/block_user.rs
crates/apub/src/activities/block/mod.rs
crates/apub/src/activities/block/undo_block_user.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/mod.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/report.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/create_or_update/comment.rs
crates/apub/src/activities/create_or_update/mod.rs
crates/apub/src/activities/create_or_update/post.rs
crates/apub/src/activities/create_or_update/private_message.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/delete_user.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
crates/apub/src/activities/mod.rs
crates/apub/src/activities/unfederated.rs [new file with mode: 0644]
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
crates/apub/src/api/list_comments.rs [moved from crates/api_crud/src/comment/list.rs with 94% similarity]
crates/apub/src/api/list_posts.rs [moved from crates/api_crud/src/post/list.rs with 93% similarity]
crates/apub/src/api/mod.rs [new file with mode: 0644]
crates/apub/src/api/read_community.rs [moved from crates/api_crud/src/community/read.rs with 92% similarity]
crates/apub/src/api/read_person.rs [moved from crates/api_crud/src/user/read.rs with 95% similarity]
crates/apub/src/api/resolve_object.rs [moved from crates/api/src/site/resolve_object.rs with 93% similarity]
crates/apub/src/api/search.rs [moved from crates/api/src/site/search.rs with 97% similarity]
crates/apub/src/collections/community_moderators.rs
crates/apub/src/collections/community_outbox.rs
crates/apub/src/collections/mod.rs
crates/apub/src/fetcher/mod.rs
crates/apub/src/fetcher/post_or_comment.rs
crates/apub/src/fetcher/search.rs
crates/apub/src/fetcher/user_or_community.rs
crates/apub/src/fetcher/webfinger.rs
crates/apub/src/http/comment.rs
crates/apub/src/http/community.rs
crates/apub/src/http/mod.rs
crates/apub/src/http/person.rs
crates/apub/src/http/post.rs
crates/apub/src/http/site.rs
crates/apub/src/lib.rs
crates/apub/src/mentions.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/instance.rs
crates/apub/src/objects/mod.rs
crates/apub/src/objects/person.rs
crates/apub/src/objects/post.rs
crates/apub/src/objects/private_message.rs
crates/apub/src/protocol/activities/block/block_user.rs
crates/apub/src/protocol/activities/block/undo_block_user.rs
crates/apub/src/protocol/activities/community/add_mod.rs
crates/apub/src/protocol/activities/community/remove_mod.rs
crates/apub/src/protocol/activities/community/report.rs
crates/apub/src/protocol/activities/community/update.rs
crates/apub/src/protocol/activities/create_or_update/note.rs
crates/apub/src/protocol/activities/create_or_update/page.rs
crates/apub/src/protocol/activities/deletion/delete.rs
crates/apub/src/protocol/activities/deletion/undo_delete.rs
crates/apub/src/protocol/activities/voting/undo_vote.rs
crates/apub/src/protocol/activities/voting/vote.rs
crates/apub/src/protocol/collections/group_followers.rs
crates/apub/src/protocol/mod.rs
crates/apub/src/protocol/objects/group.rs
crates/apub/src/protocol/objects/note.rs
crates/apub/src/protocol/objects/page.rs
crates/db_schema/src/impls/site.rs
crates/routes/Cargo.toml
crates/routes/src/feeds.rs
crates/routes/src/images.rs
crates/routes/src/nodeinfo.rs
crates/routes/src/webfinger.rs
src/api_routes.rs
src/code_migrations.rs
src/main.rs

index 2d1f70bc63d77752eb88c68b0a9f4ac35cbc79dd..5f68a511e5a032b09f7595b332f09c11dc5d46c8 100644 (file)
@@ -2034,7 +2034,6 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
 name = "lemmy_api"
 version = "0.16.5"
 dependencies = [
- "activitypub_federation",
  "actix-web",
  "anyhow",
  "async-trait",
@@ -2044,7 +2043,6 @@ dependencies = [
  "chrono",
  "diesel",
  "lemmy_api_common",
- "lemmy_apub",
  "lemmy_db_schema",
  "lemmy_db_views",
  "lemmy_db_views_actor",
@@ -2103,7 +2101,6 @@ dependencies = [
  "async-trait",
  "bcrypt",
  "lemmy_api_common",
- "lemmy_apub",
  "lemmy_db_schema",
  "lemmy_db_views",
  "lemmy_db_views_actor",
@@ -2274,6 +2271,7 @@ dependencies = [
  "reqwest-retry",
  "reqwest-tracing",
  "serde",
+ "serde_json",
  "tracing",
  "tracing-actix-web",
  "tracing-error",
index 16ca864f41e97af2ff0e31215f7a336b027bc187..e83f0c837cabca1ef52b59d760a555c1b6ee9d90 100644 (file)
@@ -135,6 +135,7 @@ clokwerk = { workspace = true }
 doku = { workspace = true }
 parking_lot = { workspace = true }
 reqwest-retry = { workspace = true }
+serde_json = { workspace = true }
 tracing-opentelemetry = { workspace = true, optional = true }
 opentelemetry = { workspace = true, optional = true }
 console-subscriber = { version = "0.1.8", optional = true }
index 0ed50ec484672becec82ff5257c0ac288eaf4965..453ea5660b7a95a0ec73f5a03f052789d7411812 100644 (file)
@@ -187,12 +187,15 @@ test("Admin actions in remote community are not federated to origin", async () =
   let gammaCommunity = (
     await resolveCommunity(gamma, communityRes.community.actor_id)
   ).community.unwrap();
-  let gammaFollow = await followCommunity(
+  await followCommunity(
     gamma,
     true,
     gammaCommunity.community.id
   );
-  expect(gammaFollow.community_view.subscribed).toBe("Subscribed");
+  gammaCommunity = (
+    await resolveCommunity(gamma, communityRes.community.actor_id)
+  ).community.unwrap();
+  expect(gammaCommunity.subscribed).toBe("Subscribed");
   let gammaPost = (await createPost(gamma, gammaCommunity.community.id))
     .post_view;
   expect(gammaPost.post.id).toBeDefined();
index f80b40de858d5e7b7427d68b48984aa3b4f3f648..630e25f2210978f40ab7417f991c393bdb728152 100644 (file)
@@ -20,12 +20,13 @@ afterAll(async () => {
 
 test("Follow federated community", async () => {
   let betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
-  let follow = await followCommunity(alpha, true, betaCommunity.community.id);
+  await followCommunity(alpha, true, betaCommunity.community.id);
+  betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
 
   // Make sure the follow response went through
-  expect(follow.community_view.community.local).toBe(false);
-  expect(follow.community_view.community.name).toBe("main");
-  expect(follow.community_view.subscribed).toBe(SubscribedType.Subscribed);
+  expect(betaCommunity.community.local).toBe(false);
+  expect(betaCommunity.community.name).toBe("main");
+  expect(betaCommunity.subscribed).toBe(SubscribedType.Subscribed);
 
   // Check it from local
   let site = await getSite(alpha);
index 17c0127b4e83e659a236742b3bcc542d0b06c9d5..f7f1b0bf3a02e70391ddc9c88f0d823123091965 100644 (file)
@@ -14,14 +14,12 @@ path = "src/lib.rs"
 doctest = false
 
 [dependencies]
-lemmy_apub = { workspace = true }
 lemmy_utils = { workspace = true }
 lemmy_db_schema = { workspace = true, features = ["full"] }
 lemmy_db_views = { workspace = true, features = ["full"] }
 lemmy_db_views_moderator = { workspace = true, features = ["full"] }
 lemmy_db_views_actor = { workspace = true, features = ["full"] }
 lemmy_api_common = { workspace = true, features = ["full"] }
-activitypub_federation = { workspace = true }
 diesel = { workspace = true }
 bcrypt = { workspace = true }
 chrono = { workspace = true }
index 1ba6ec791704dfc2797057aff3b7df40822ef4f2..fba61ed13ee83169b8b679e5c0c5dfc7d6087201 100644 (file)
@@ -2,16 +2,9 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{CommentResponse, CreateCommentLike},
+  context::LemmyContext,
   utils::{check_community_ban, check_downvotes_enabled, get_local_user_view_from_jwt},
   websocket::{send::send_comment_ws_message, UserOperation},
-  LemmyContext,
-};
-use lemmy_apub::{
-  fetcher::post_or_comment::PostOrComment,
-  protocol::activities::voting::{
-    undo_vote::UndoVote,
-    vote::{Vote, VoteType},
-  },
 };
 use lemmy_db_schema::{
   newtypes::LocalUserId,
@@ -24,7 +17,6 @@ use lemmy_db_schema::{
 };
 use lemmy_db_views::structs::{CommentView, LocalUserView};
 use lemmy_utils::{error::LemmyError, ConnectionId};
-use std::convert::TryInto;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for CreateCommentLike {
@@ -78,33 +70,12 @@ impl Perform for CreateCommentLike {
     CommentLike::remove(context.pool(), person_id, comment_id).await?;
 
     // Only add the like if the score isnt 0
-    let comment = orig_comment.comment;
-    let object = PostOrComment::Comment(Box::new(comment.into()));
     let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
     if do_add {
       let like_form2 = like_form.clone();
       CommentLike::like(context.pool(), &like_form2)
         .await
         .map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
-
-      Vote::send(
-        &object,
-        &local_user_view.person.clone().into(),
-        orig_comment.community.id,
-        like_form.score.try_into()?,
-        context,
-      )
-      .await?;
-    } else {
-      // API doesn't distinguish between Undo/Like and Undo/Dislike
-      UndoVote::send(
-        &object,
-        &local_user_view.person.clone().into(),
-        orig_comment.community.id,
-        VoteType::Like,
-        context,
-      )
-      .await?;
     }
 
     send_comment_ws_message(
index cc6955de04c52480308a1c78b9c98be6ba5372dc..03051f6cc8afcc068f4e4a7cde13f0df589fdcd2 100644 (file)
@@ -2,8 +2,8 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{CommentResponse, SaveComment},
+  context::LemmyContext,
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::comment::{CommentSaved, CommentSavedForm},
index 99c653e231bd949ce7db36d3dd334ca2fbe10757..bf3fec0a144869df1043afff5f714e3e7f007cab 100644 (file)
@@ -1,13 +1,11 @@
 use crate::{check_report_reason, Perform};
-use activitypub_federation::core::object_id::ObjectId;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{CommentReportResponse, CreateCommentReport},
+  context::LemmyContext,
   utils::{check_community_ban, get_local_user_view_from_jwt},
   websocket::{messages::SendModRoomMessage, UserOperation},
-  LemmyContext,
 };
-use lemmy_apub::protocol::activities::community::report::Report;
 use lemmy_db_schema::{
   source::{
     comment_report::{CommentReport, CommentReportForm},
@@ -67,15 +65,6 @@ impl Perform for CreateCommentReport {
       websocket_id,
     });
 
-    Report::send(
-      ObjectId::new(comment_view.comment.ap_id),
-      &local_user_view.person.into(),
-      ObjectId::new(comment_view.community.actor_id),
-      reason.to_string(),
-      context,
-    )
-    .await?;
-
     Ok(res)
   }
 }
index b99716e88ac1cb2e95795ef8d02a8ab7cf7b8d72..8aa3fcbcd87a02c9013c518b24301d2736be70a1 100644 (file)
@@ -2,8 +2,8 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{ListCommentReports, ListCommentReportsResponse},
+  context::LemmyContext,
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_views::comment_report_view::CommentReportQuery;
 use lemmy_utils::{error::LemmyError, ConnectionId};
index 16598ffa9724f8b7e479d0fc00f8fb55de96adff..9df11fc23876f2bcc0d2c1cd93c40b76826adfdf 100644 (file)
@@ -2,9 +2,9 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{CommentReportResponse, ResolveCommentReport},
+  context::LemmyContext,
   utils::{get_local_user_view_from_jwt, is_mod_or_admin},
   websocket::{messages::SendModRoomMessage, UserOperation},
-  LemmyContext,
 };
 use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
 use lemmy_db_views::structs::CommentReportView;
index d307a672d51410ce7a37a31907f833695c1af820..ce3082f7144e796f6d2b7db907e88b70d3d8c742 100644 (file)
@@ -2,19 +2,14 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{AddModToCommunity, AddModToCommunityResponse},
+  context::LemmyContext,
   utils::{get_local_user_view_from_jwt, is_mod_or_admin},
   websocket::{messages::SendCommunityRoomMessage, UserOperation},
-  LemmyContext,
-};
-use lemmy_apub::{
-  objects::{community::ApubCommunity, person::ApubPerson},
-  protocol::activities::community::{add_mod::AddMod, remove_mod::RemoveMod},
 };
 use lemmy_db_schema::{
   source::{
     community::{Community, CommunityModerator, CommunityModeratorForm},
     moderator::{ModAddCommunity, ModAddCommunityForm},
-    person::Person,
   },
   traits::{Crud, Joinable},
 };
@@ -69,28 +64,6 @@ impl Perform for AddModToCommunity {
 
     ModAddCommunity::create(context.pool(), &form).await?;
 
-    // Send to federated instances
-    let updated_mod_id = data.person_id;
-    let updated_mod: ApubPerson = Person::read(context.pool(), updated_mod_id).await?.into();
-    let community: ApubCommunity = community.into();
-    if data.added {
-      AddMod::send(
-        &community,
-        &updated_mod,
-        &local_user_view.person.into(),
-        context,
-      )
-      .await?;
-    } else {
-      RemoveMod::send(
-        &community,
-        &updated_mod,
-        &local_user_view.person.into(),
-        context,
-      )
-      .await?;
-    }
-
     // Note: in case a remote mod is added, this returns the old moderators list, it will only get
     //       updated once we receive an activity from the community (like `Announce/Add/Moderator`)
     let community_id = data.community_id;
index 018ccd012e6bb22a2090348177338c7621cddc19..fb5e7fcfefce7c5c54bccb78875ddfc6edec316d 100644 (file)
@@ -2,26 +2,19 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{BanFromCommunity, BanFromCommunityResponse},
+  context::LemmyContext,
   utils::{get_local_user_view_from_jwt, is_mod_or_admin, remove_user_data_in_community},
   websocket::{messages::SendCommunityRoomMessage, UserOperation},
-  LemmyContext,
-};
-use lemmy_apub::{
-  activities::block::SiteOrCommunity,
-  objects::{community::ApubCommunity, person::ApubPerson},
-  protocol::activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
 };
 use lemmy_db_schema::{
   source::{
     community::{
-      Community,
       CommunityFollower,
       CommunityFollowerForm,
       CommunityPersonBan,
       CommunityPersonBanForm,
     },
     moderator::{ModBanFromCommunity, ModBanFromCommunityForm},
-    person::Person,
   },
   traits::{Bannable, Crud, Followable},
 };
@@ -56,9 +49,6 @@ impl Perform for BanFromCommunity {
       expires: Some(expires),
     };
 
-    let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
-    let banned_person: ApubPerson = Person::read(context.pool(), banned_person_id).await?.into();
-
     if data.ban {
       CommunityPersonBan::ban(context.pool(), &community_user_ban_form)
         .await
@@ -74,29 +64,10 @@ impl Perform for BanFromCommunity {
       CommunityFollower::unfollow(context.pool(), &community_follower_form)
         .await
         .ok();
-
-      BlockUser::send(
-        &SiteOrCommunity::Community(community),
-        &banned_person,
-        &local_user_view.person.clone().into(),
-        remove_data,
-        data.reason.clone(),
-        expires,
-        context,
-      )
-      .await?;
     } else {
       CommunityPersonBan::unban(context.pool(), &community_user_ban_form)
         .await
         .map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
-      UndoBlockUser::send(
-        &SiteOrCommunity::Community(community),
-        &banned_person,
-        &local_user_view.person.clone().into(),
-        data.reason.clone(),
-        context,
-      )
-      .await?;
     }
 
     // Remove/Restore their data if that's desired
index 6c6efc2131a5d67b91c150c9d641fc3f8ba67e0d..914b5238e5c1bdb769c32ba4c33583c529c78133 100644 (file)
@@ -2,16 +2,15 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{BlockCommunity, BlockCommunityResponse},
+  context::LemmyContext,
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
-use lemmy_apub::protocol::activities::following::undo_follow::UndoFollow;
 use lemmy_db_schema::{
   source::{
-    community::{Community, CommunityFollower, CommunityFollowerForm},
+    community::{CommunityFollower, CommunityFollowerForm},
     community_block::{CommunityBlock, CommunityBlockForm},
   },
-  traits::{Blockable, Crud, Followable},
+  traits::{Blockable, Followable},
 };
 use lemmy_db_views_actor::structs::CommunityView;
 use lemmy_utils::{error::LemmyError, ConnectionId};
@@ -52,8 +51,6 @@ impl Perform for BlockCommunity {
       CommunityFollower::unfollow(context.pool(), &community_follower_form)
         .await
         .ok();
-      let community = Community::read(context.pool(), community_id).await?;
-      UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await?;
     } else {
       CommunityBlock::unblock(context.pool(), &community_block_form)
         .await
index 51d5ad9b61ba7e91317c64c23f4e02bbb360c8b6..dedfc97129f8570677702fcd64a0ce1e34edb698 100644 (file)
@@ -2,15 +2,8 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{CommunityResponse, FollowCommunity},
+  context::LemmyContext,
   utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
-  LemmyContext,
-};
-use lemmy_apub::{
-  objects::community::ApubCommunity,
-  protocol::activities::following::{
-    follow::Follow as FollowCommunityApub,
-    undo_follow::UndoFollow,
-  },
 };
 use lemmy_db_schema::{
   source::community::{Community, CommunityFollower, CommunityFollowerForm},
@@ -34,33 +27,22 @@ impl Perform for FollowCommunity {
       get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
 
     let community_id = data.community_id;
-    let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
+    let community = Community::read(context.pool(), community_id).await?;
     let community_follower_form = CommunityFollowerForm {
       community_id: data.community_id,
       person_id: local_user_view.person.id,
       pending: false,
     };
 
-    if community.local {
-      if data.follow {
-        check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
-        check_community_deleted_or_removed(community_id, context.pool()).await?;
+    if community.local && data.follow {
+      check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
+      check_community_deleted_or_removed(community_id, context.pool()).await?;
 
-        CommunityFollower::follow(context.pool(), &community_follower_form)
-          .await
-          .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
-      } else {
-        CommunityFollower::unfollow(context.pool(), &community_follower_form)
-          .await
-          .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
-      }
-    } else if data.follow {
-      // Dont actually add to the community followers here, because you need
-      // to wait for the accept
-      FollowCommunityApub::send(&local_user_view.person.clone().into(), &community, context)
-        .await?;
-    } else {
-      UndoFollow::send(&local_user_view.person.clone().into(), &community, context).await?;
+      CommunityFollower::follow(context.pool(), &community_follower_form)
+        .await
+        .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
+    }
+    if !data.follow {
       CommunityFollower::unfollow(context.pool(), &community_follower_form)
         .await
         .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
index 54a08135af2069d243981a2a83f99dfcbe49ecab..94ce7d745134dddd9645aa8907334f4b9c5b444b 100644 (file)
@@ -2,11 +2,10 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{CommunityResponse, HideCommunity},
+  context::LemmyContext,
   utils::{get_local_user_view_from_jwt, is_admin},
   websocket::{send::send_community_ws_message, UserOperationCrud},
-  LemmyContext,
 };
-use lemmy_apub::protocol::activities::community::update::UpdateCommunity;
 use lemmy_db_schema::{
   source::{
     community::{Community, CommunityUpdateForm},
@@ -45,19 +44,12 @@ impl Perform for HideCommunity {
     };
 
     let community_id = data.community_id;
-    let updated_community = Community::update(context.pool(), community_id, &community_form)
+    Community::update(context.pool(), community_id, &community_form)
       .await
       .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?;
 
     ModHideCommunity::create(context.pool(), &mod_hide_community_form).await?;
 
-    UpdateCommunity::send(
-      updated_community.into(),
-      &local_user_view.person.into(),
-      context,
-    )
-    .await?;
-
     let op = UserOperationCrud::EditCommunity;
     send_community_ws_message(data.community_id, op, websocket_id, None, context).await
   }
index bb69de0928cab08bea53a6f764c00422f395b705..7ca174e4ccdc802e7ed71c76446c2c221a89fe51 100644 (file)
@@ -3,8 +3,8 @@ use actix_web::web::Data;
 use anyhow::Context;
 use lemmy_api_common::{
   community::{GetCommunityResponse, TransferCommunity},
+  context::LemmyContext,
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index 0473f1e88fbf642f47e43c6eb8363138b4e1b515..5904a9b9b1df48f2a8ea695f3c36ff2dbb0f0dcf 100644 (file)
@@ -1,81 +1,8 @@
-use actix_web::{web, web::Data};
+use actix_web::web::Data;
 use captcha::Captcha;
-use lemmy_api_common::{
-  comment::{
-    CreateCommentLike,
-    CreateCommentReport,
-    ListCommentReports,
-    ResolveCommentReport,
-    SaveComment,
-  },
-  community::{
-    AddModToCommunity,
-    BanFromCommunity,
-    BlockCommunity,
-    FollowCommunity,
-    TransferCommunity,
-  },
-  person::{
-    AddAdmin,
-    BanPerson,
-    BlockPerson,
-    ChangePassword,
-    GetBannedPersons,
-    GetCaptcha,
-    GetPersonMentions,
-    GetReplies,
-    GetReportCount,
-    GetUnreadCount,
-    Login,
-    MarkAllAsRead,
-    MarkCommentReplyAsRead,
-    MarkPersonMentionAsRead,
-    PasswordChangeAfterReset,
-    PasswordReset,
-    SaveUserSettings,
-    VerifyEmail,
-  },
-  post::{
-    CreatePostLike,
-    CreatePostReport,
-    GetSiteMetadata,
-    ListPostReports,
-    LockPost,
-    MarkPostAsRead,
-    ResolvePostReport,
-    SavePost,
-    StickyPost,
-  },
-  private_message::{
-    CreatePrivateMessageReport,
-    ListPrivateMessageReports,
-    MarkPrivateMessageAsRead,
-    ResolvePrivateMessageReport,
-  },
-  site::{
-    ApproveRegistrationApplication,
-    GetModlog,
-    GetUnreadRegistrationApplicationCount,
-    LeaveAdmin,
-    ListRegistrationApplications,
-    PurgeComment,
-    PurgeCommunity,
-    PurgePerson,
-    PurgePost,
-    ResolveObject,
-    Search,
-  },
-  utils::local_site_to_slur_regex,
-  websocket::{
-    serialize_websocket_message,
-    structs::{CommunityJoin, ModJoin, PostJoin, UserJoin},
-    UserOperation,
-  },
-  LemmyContext,
-};
+use lemmy_api_common::{context::LemmyContext, utils::local_site_to_slur_regex};
 use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_utils::{error::LemmyError, utils::check_slurs, ConnectionId};
-use serde::Deserialize;
 
 mod comment;
 mod comment_report;
@@ -99,182 +26,6 @@ pub trait Perform {
   ) -> Result<Self::Response, LemmyError>;
 }
 
-pub async fn match_websocket_operation(
-  context: LemmyContext,
-  id: ConnectionId,
-  op: UserOperation,
-  data: &str,
-) -> Result<String, LemmyError> {
-  match op {
-    // User ops
-    UserOperation::Login => do_websocket_operation::<Login>(context, id, op, data).await,
-    UserOperation::GetCaptcha => do_websocket_operation::<GetCaptcha>(context, id, op, data).await,
-    UserOperation::GetReplies => do_websocket_operation::<GetReplies>(context, id, op, data).await,
-    UserOperation::AddAdmin => do_websocket_operation::<AddAdmin>(context, id, op, data).await,
-    UserOperation::GetUnreadRegistrationApplicationCount => {
-      do_websocket_operation::<GetUnreadRegistrationApplicationCount>(context, id, op, data).await
-    }
-    UserOperation::ListRegistrationApplications => {
-      do_websocket_operation::<ListRegistrationApplications>(context, id, op, data).await
-    }
-    UserOperation::ApproveRegistrationApplication => {
-      do_websocket_operation::<ApproveRegistrationApplication>(context, id, op, data).await
-    }
-    UserOperation::BanPerson => do_websocket_operation::<BanPerson>(context, id, op, data).await,
-    UserOperation::GetBannedPersons => {
-      do_websocket_operation::<GetBannedPersons>(context, id, op, data).await
-    }
-    UserOperation::BlockPerson => {
-      do_websocket_operation::<BlockPerson>(context, id, op, data).await
-    }
-    UserOperation::GetPersonMentions => {
-      do_websocket_operation::<GetPersonMentions>(context, id, op, data).await
-    }
-    UserOperation::MarkPersonMentionAsRead => {
-      do_websocket_operation::<MarkPersonMentionAsRead>(context, id, op, data).await
-    }
-    UserOperation::MarkCommentReplyAsRead => {
-      do_websocket_operation::<MarkCommentReplyAsRead>(context, id, op, data).await
-    }
-    UserOperation::MarkAllAsRead => {
-      do_websocket_operation::<MarkAllAsRead>(context, id, op, data).await
-    }
-    UserOperation::PasswordReset => {
-      do_websocket_operation::<PasswordReset>(context, id, op, data).await
-    }
-    UserOperation::PasswordChange => {
-      do_websocket_operation::<PasswordChangeAfterReset>(context, id, op, data).await
-    }
-    UserOperation::UserJoin => do_websocket_operation::<UserJoin>(context, id, op, data).await,
-    UserOperation::PostJoin => do_websocket_operation::<PostJoin>(context, id, op, data).await,
-    UserOperation::CommunityJoin => {
-      do_websocket_operation::<CommunityJoin>(context, id, op, data).await
-    }
-    UserOperation::ModJoin => do_websocket_operation::<ModJoin>(context, id, op, data).await,
-    UserOperation::SaveUserSettings => {
-      do_websocket_operation::<SaveUserSettings>(context, id, op, data).await
-    }
-    UserOperation::ChangePassword => {
-      do_websocket_operation::<ChangePassword>(context, id, op, data).await
-    }
-    UserOperation::GetReportCount => {
-      do_websocket_operation::<GetReportCount>(context, id, op, data).await
-    }
-    UserOperation::GetUnreadCount => {
-      do_websocket_operation::<GetUnreadCount>(context, id, op, data).await
-    }
-    UserOperation::VerifyEmail => {
-      do_websocket_operation::<VerifyEmail>(context, id, op, data).await
-    }
-
-    // Private Message ops
-    UserOperation::MarkPrivateMessageAsRead => {
-      do_websocket_operation::<MarkPrivateMessageAsRead>(context, id, op, data).await
-    }
-    UserOperation::CreatePrivateMessageReport => {
-      do_websocket_operation::<CreatePrivateMessageReport>(context, id, op, data).await
-    }
-    UserOperation::ResolvePrivateMessageReport => {
-      do_websocket_operation::<ResolvePrivateMessageReport>(context, id, op, data).await
-    }
-    UserOperation::ListPrivateMessageReports => {
-      do_websocket_operation::<ListPrivateMessageReports>(context, id, op, data).await
-    }
-
-    // Site ops
-    UserOperation::GetModlog => do_websocket_operation::<GetModlog>(context, id, op, data).await,
-    UserOperation::PurgePerson => {
-      do_websocket_operation::<PurgePerson>(context, id, op, data).await
-    }
-    UserOperation::PurgeCommunity => {
-      do_websocket_operation::<PurgeCommunity>(context, id, op, data).await
-    }
-    UserOperation::PurgePost => do_websocket_operation::<PurgePost>(context, id, op, data).await,
-    UserOperation::PurgeComment => {
-      do_websocket_operation::<PurgeComment>(context, id, op, data).await
-    }
-    UserOperation::Search => do_websocket_operation::<Search>(context, id, op, data).await,
-    UserOperation::ResolveObject => {
-      do_websocket_operation::<ResolveObject>(context, id, op, data).await
-    }
-    UserOperation::TransferCommunity => {
-      do_websocket_operation::<TransferCommunity>(context, id, op, data).await
-    }
-    UserOperation::LeaveAdmin => do_websocket_operation::<LeaveAdmin>(context, id, op, data).await,
-
-    // Community ops
-    UserOperation::FollowCommunity => {
-      do_websocket_operation::<FollowCommunity>(context, id, op, data).await
-    }
-    UserOperation::BlockCommunity => {
-      do_websocket_operation::<BlockCommunity>(context, id, op, data).await
-    }
-    UserOperation::BanFromCommunity => {
-      do_websocket_operation::<BanFromCommunity>(context, id, op, data).await
-    }
-    UserOperation::AddModToCommunity => {
-      do_websocket_operation::<AddModToCommunity>(context, id, op, data).await
-    }
-
-    // Post ops
-    UserOperation::LockPost => do_websocket_operation::<LockPost>(context, id, op, data).await,
-    UserOperation::StickyPost => do_websocket_operation::<StickyPost>(context, id, op, data).await,
-    UserOperation::CreatePostLike => {
-      do_websocket_operation::<CreatePostLike>(context, id, op, data).await
-    }
-    UserOperation::MarkPostAsRead => {
-      do_websocket_operation::<MarkPostAsRead>(context, id, op, data).await
-    }
-    UserOperation::SavePost => do_websocket_operation::<SavePost>(context, id, op, data).await,
-    UserOperation::CreatePostReport => {
-      do_websocket_operation::<CreatePostReport>(context, id, op, data).await
-    }
-    UserOperation::ListPostReports => {
-      do_websocket_operation::<ListPostReports>(context, id, op, data).await
-    }
-    UserOperation::ResolvePostReport => {
-      do_websocket_operation::<ResolvePostReport>(context, id, op, data).await
-    }
-    UserOperation::GetSiteMetadata => {
-      do_websocket_operation::<GetSiteMetadata>(context, id, op, data).await
-    }
-
-    // Comment ops
-    UserOperation::SaveComment => {
-      do_websocket_operation::<SaveComment>(context, id, op, data).await
-    }
-    UserOperation::CreateCommentLike => {
-      do_websocket_operation::<CreateCommentLike>(context, id, op, data).await
-    }
-    UserOperation::CreateCommentReport => {
-      do_websocket_operation::<CreateCommentReport>(context, id, op, data).await
-    }
-    UserOperation::ListCommentReports => {
-      do_websocket_operation::<ListCommentReports>(context, id, op, data).await
-    }
-    UserOperation::ResolveCommentReport => {
-      do_websocket_operation::<ResolveCommentReport>(context, id, op, data).await
-    }
-  }
-}
-
-async fn do_websocket_operation<'a, 'b, Data>(
-  context: LemmyContext,
-  id: ConnectionId,
-  op: UserOperation,
-  data: &str,
-) -> Result<String, LemmyError>
-where
-  for<'de> Data: Deserialize<'de> + 'a,
-  Data: Perform,
-{
-  let parsed_data: Data = serde_json::from_str(data)?;
-  let res = parsed_data
-    .perform(&web::Data::new(context), Some(id))
-    .await?;
-  serialize_websocket_message(&op, &res)
-}
-
 /// Converts the captcha to a base64 encoded wav audio file
 pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> String {
   let letters = captcha.as_wav();
index 8091f97e4be03039223ec185ca310c183ea25b08..78357f0c58792d65386dc998d1869aee695b5d8b 100644 (file)
@@ -1,10 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{AddAdmin, AddAdminResponse},
   utils::{get_local_user_view_from_jwt, is_admin},
   websocket::{messages::SendAllMessage, UserOperation},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index a848175e45e7c63cf48ef107a7f140a0f6d399aa..0bb2523497b4cb70a28dc5c4e124b2d5dbff67b1 100644 (file)
@@ -1,14 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{BanPerson, BanPersonResponse},
   utils::{get_local_user_view_from_jwt, is_admin, remove_user_data},
   websocket::{messages::SendAllMessage, UserOperation},
-  LemmyContext,
-};
-use lemmy_apub::{
-  activities::block::SiteOrCommunity,
-  protocol::activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
 };
 use lemmy_db_schema::{
   source::{
@@ -17,7 +13,6 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_db_views::structs::SiteView;
 use lemmy_db_views_actor::structs::PersonViewSafe;
 use lemmy_utils::{error::LemmyError, utils::naive_from_unix, ConnectionId};
 
@@ -79,32 +74,6 @@ impl Perform for BanPerson {
     let person_id = data.person_id;
     let person_view = PersonViewSafe::read(context.pool(), person_id).await?;
 
-    let site = SiteOrCommunity::Site(SiteView::read_local(context.pool()).await?.site.into());
-    // if the action affects a local user, federate to other instances
-    if person.local {
-      if ban {
-        BlockUser::send(
-          &site,
-          &person.into(),
-          &local_user_view.person.into(),
-          remove_data,
-          data.reason.clone(),
-          expires,
-          context,
-        )
-        .await?;
-      } else {
-        UndoBlockUser::send(
-          &site,
-          &person.into(),
-          &local_user_view.person.into(),
-          data.reason.clone(),
-          context,
-        )
-        .await?;
-      }
-    }
-
     let res = BanPersonResponse {
       person_view,
       banned: data.ban,
index 798d367748c869e2ab55bf479e1ef20819b99155..b57ecd551eb3f5f3a0b68850510cef87f783b786 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{BlockPerson, BlockPersonResponse},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::person_block::{PersonBlock, PersonBlockForm},
index e4e9004ea0b618f58cb200cf6c30fe721f3d681c..2d0fd30e53763ae18f9303bfa263e0620f0b8ee7 100644 (file)
@@ -2,9 +2,9 @@ use crate::Perform;
 use actix_web::web::Data;
 use bcrypt::verify;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{ChangePassword, LoginResponse},
   utils::{get_local_user_view_from_jwt, password_length_check},
-  LemmyContext,
 };
 use lemmy_db_schema::source::local_user::LocalUser;
 use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
index f9556b533af4933141c7de05a2b881daf168b38f..c6de10d7ac5569afbc15335123e15ad157eeca48 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{LoginResponse, PasswordChangeAfterReset},
   utils::password_length_check,
-  LemmyContext,
 };
 use lemmy_db_schema::source::{
   local_user::LocalUser,
index 5eacc4fd8ee63b145b70d85b54853c79a2d15b83..50a2bdba2d8f79cb06f94fa734c3689fe930c618 100644 (file)
@@ -3,9 +3,9 @@ use actix_web::web::Data;
 use captcha::{gen, Difficulty};
 use chrono::Duration;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{CaptchaResponse, GetCaptcha, GetCaptchaResponse},
   websocket::messages::CaptchaItem,
-  LemmyContext,
 };
 use lemmy_db_schema::{source::local_site::LocalSite, utils::naive_now};
 use lemmy_utils::{error::LemmyError, ConnectionId};
index 31d4e3be6875f17f6a9168b169c278296537aecc..60eb32b35ec4251126a8886684fbf3cb00449b51 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{BannedPersonsResponse, GetBannedPersons},
   utils::{get_local_user_view_from_jwt, is_admin},
-  LemmyContext,
 };
 use lemmy_db_views_actor::structs::PersonViewSafe;
 use lemmy_utils::{error::LemmyError, ConnectionId};
index dac0d9bf5f2907f6951dc14df4698f4255f84305..c60c0dcdf44a53a526315e2a4478a99bc782ad68 100644 (file)
@@ -2,9 +2,9 @@ use crate::Perform;
 use actix_web::web::Data;
 use bcrypt::verify;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{Login, LoginResponse},
   utils::{check_registration_application, check_user_valid},
-  LemmyContext,
 };
 use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_db_views::structs::LocalUserView;
index 5e3b63e7a9c4546eaf7ea917a0b03475f5c70633..c03e9d1679d6fa6b19633fb0969aa5d54e64c455 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{GetPersonMentions, GetPersonMentionsResponse},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_views_actor::person_mention_view::PersonMentionQuery;
 use lemmy_utils::{error::LemmyError, ConnectionId};
index 375864b5888db52f9e9dae1be0dfec0c1c8662f3..585db5e95d0a304e6bdce8bbe92855d0f3e4f611 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{GetReplies, GetRepliesResponse},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery;
 use lemmy_utils::{error::LemmyError, ConnectionId};
index 9f8926dc39562729145770d87a77cd67ddf46e5a..2515715bdcc356e7db93a87cf9f75f7bd2e3996c 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{GetRepliesResponse, MarkAllAsRead},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_schema::source::{
   comment_reply::CommentReply,
index 655f788465b58787a325ae12d915f27748addce4..a3a75d929d84d5f3616ccf0edd3095ab4f645a02 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{MarkPersonMentionAsRead, PersonMentionResponse},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::person_mention::{PersonMention, PersonMentionUpdateForm},
index fa3367e33262dd496e1725b83447ede52248167b..3921e769df50f995352e5abbb9a717dd1a491316 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{CommentReplyResponse, MarkCommentReplyAsRead},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::comment_reply::{CommentReply, CommentReplyUpdateForm},
index 442977a2c034537ff0320d0a7d0e7490b77266e4..715ccd286ec3c18c62fe34b60880c73f25e4cf4b 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{GetUnreadCount, GetUnreadCountResponse},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_views::structs::PrivateMessageView;
 use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
index 7dd63b7ad55f8555782ef91006469e983cc00bd4..b59a06490d12de616671f156d33cdd4bfec7d25e 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{GetReportCount, GetReportCountResponse},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_views::structs::{CommentReportView, PostReportView, PrivateMessageReportView};
 use lemmy_utils::{error::LemmyError, ConnectionId};
index 8def6d3c67027fb7ce81005a48e494be30a5a9f0..5d0e9d88bb3840209602b8d639f60c5efa1b48c7 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{PasswordReset, PasswordResetResponse},
   utils::send_password_reset_email,
-  LemmyContext,
 };
 use lemmy_db_views::structs::LocalUserView;
 use lemmy_utils::{error::LemmyError, ConnectionId};
index 807e8262d7261314adbc520cf3cee0d01b25b753..6672a67b038067775a64ac3c95e19c68a4ff7d35 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{LoginResponse, SaveUserSettings},
   utils::{get_local_user_view_from_jwt, send_verification_email},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index 238692ff02b728669609f4472647dcefd3d72fc0..fb82b716bb543c0d2d5c2a8130e60667f96b9ae0 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{VerifyEmail, VerifyEmailResponse},
   utils::send_email_verification_success,
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index aae211a50ccb8e92225b221a58cd3f3465841771..eaf111eba7beb1f5629bbebeeea853ca605b4e51 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{GetSiteMetadata, GetSiteMetadataResponse},
   request::fetch_site_metadata,
-  LemmyContext,
 };
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
index d15e649b9be913e1b980557282580cf9d9a102cd..59135ff216f89db3f75a9d0ba4dc32068a5a662d 100644 (file)
@@ -1,6 +1,7 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{CreatePostLike, PostResponse},
   utils::{
     check_community_ban,
@@ -10,15 +11,6 @@ use lemmy_api_common::{
     mark_post_as_read,
   },
   websocket::{send::send_post_ws_message, UserOperation},
-  LemmyContext,
-};
-use lemmy_apub::{
-  fetcher::post_or_comment::PostOrComment,
-  objects::post::ApubPost,
-  protocol::activities::voting::{
-    undo_vote::UndoVote,
-    vote::{Vote, VoteType},
-  },
 };
 use lemmy_db_schema::{
   source::{
@@ -49,7 +41,7 @@ impl Perform for CreatePostLike {
 
     // Check for a community ban
     let post_id = data.post_id;
-    let post: ApubPost = Post::read(context.pool(), post_id).await?.into();
+    let post = Post::read(context.pool(), post_id).await?;
 
     check_community_ban(local_user_view.person.id, post.community_id, context.pool()).await?;
     check_community_deleted_or_removed(post.community_id, context.pool()).await?;
@@ -65,9 +57,6 @@ impl Perform for CreatePostLike {
 
     PostLike::remove(context.pool(), person_id, post_id).await?;
 
-    let community_id = post.community_id;
-    let object = PostOrComment::Post(Box::new(post));
-
     // Only add the like if the score isnt 0
     let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
     if do_add {
@@ -75,25 +64,6 @@ impl Perform for CreatePostLike {
       PostLike::like(context.pool(), &like_form2)
         .await
         .map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;
-
-      Vote::send(
-        &object,
-        &local_user_view.person.clone().into(),
-        community_id,
-        like_form.score.try_into()?,
-        context,
-      )
-      .await?;
-    } else {
-      // API doesn't distinguish between Undo/Like and Undo/Dislike
-      UndoVote::send(
-        &object,
-        &local_user_view.person.clone().into(),
-        community_id,
-        VoteType::Like,
-        context,
-      )
-      .await?;
     }
 
     // Mark the post as read
index 4348971fe4e4d0f654ea650f0d8dafade11d3568..c5fa2a0f55183a56508dd3695741609c8ad6d95b 100644 (file)
@@ -1,6 +1,7 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{LockPost, PostResponse},
   utils::{
     check_community_ban,
@@ -9,11 +10,6 @@ use lemmy_api_common::{
     is_mod_or_admin,
   },
   websocket::{send::send_post_ws_message, UserOperation},
-  LemmyContext,
-};
-use lemmy_apub::{
-  objects::post::ApubPost,
-  protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
 };
 use lemmy_db_schema::{
   source::{
@@ -60,13 +56,12 @@ impl Perform for LockPost {
     // Update the post
     let post_id = data.post_id;
     let locked = data.locked;
-    let updated_post: ApubPost = Post::update(
+    Post::update(
       context.pool(),
       post_id,
       &PostUpdateForm::builder().locked(Some(locked)).build(),
     )
-    .await?
-    .into();
+    .await?;
 
     // Mod tables
     let form = ModLockPostForm {
@@ -76,15 +71,6 @@ impl Perform for LockPost {
     };
     ModLockPost::create(context.pool(), &form).await?;
 
-    // apub updates
-    CreateOrUpdatePage::send(
-      updated_post,
-      &local_user_view.person.clone().into(),
-      CreateOrUpdateType::Update,
-      context,
-    )
-    .await?;
-
     send_post_ws_message(
       data.post_id,
       UserOperation::LockPost,
index 228fdac0de7f04e038e0f09d1e222d327dcfb6d9..9fdf01b1281a4a44c15100a144594ffa3781e8ed 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{MarkPostAsRead, PostResponse},
   utils::{get_local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread},
-  LemmyContext,
 };
 use lemmy_db_views::structs::PostView;
 use lemmy_utils::{error::LemmyError, ConnectionId};
index 9e8ca9ce1d4b867d70f14d0c68b816b391a70f3f..b36f844b63793af05dd4361794e52940ac1684d3 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{PostResponse, SavePost},
   utils::{get_local_user_view_from_jwt, mark_post_as_read},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::post::{PostSaved, PostSavedForm},
index ccba5f2c32d165d7ab098edee9f445dafa115b1d..3a8aee7ab99c464edb1df958ae5212719d10a351 100644 (file)
@@ -1,6 +1,7 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{PostResponse, StickyPost},
   utils::{
     check_community_ban,
@@ -9,11 +10,6 @@ use lemmy_api_common::{
     is_mod_or_admin,
   },
   websocket::{send::send_post_ws_message, UserOperation},
-  LemmyContext,
-};
-use lemmy_apub::{
-  objects::post::ApubPost,
-  protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
 };
 use lemmy_db_schema::{
   source::{
@@ -60,13 +56,12 @@ impl Perform for StickyPost {
     // Update the post
     let post_id = data.post_id;
     let stickied = data.stickied;
-    let updated_post: ApubPost = Post::update(
+    Post::update(
       context.pool(),
       post_id,
       &PostUpdateForm::builder().stickied(Some(stickied)).build(),
     )
-    .await?
-    .into();
+    .await?;
 
     // Mod tables
     let form = ModStickyPostForm {
@@ -77,16 +72,6 @@ impl Perform for StickyPost {
 
     ModStickyPost::create(context.pool(), &form).await?;
 
-    // Apub updates
-    // TODO stickied should pry work like locked for ease of use
-    CreateOrUpdatePage::send(
-      updated_post,
-      &local_user_view.person.clone().into(),
-      CreateOrUpdateType::Update,
-      context,
-    )
-    .await?;
-
     send_post_ws_message(
       data.post_id,
       UserOperation::StickyPost,
index 2fd2d08be4b57799367f2b7a0485896f093642b7..71be43623ab7912b757f92c165991e177b3d628d 100644 (file)
@@ -1,13 +1,11 @@
 use crate::{check_report_reason, Perform};
-use activitypub_federation::core::object_id::ObjectId;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{CreatePostReport, PostReportResponse},
   utils::{check_community_ban, get_local_user_view_from_jwt},
   websocket::{messages::SendModRoomMessage, UserOperation},
-  LemmyContext,
 };
-use lemmy_apub::protocol::activities::community::report::Report;
 use lemmy_db_schema::{
   source::{
     local_site::LocalSite,
@@ -67,15 +65,6 @@ impl Perform for CreatePostReport {
       websocket_id,
     });
 
-    Report::send(
-      ObjectId::new(post_view.post.ap_id),
-      &local_user_view.person.into(),
-      ObjectId::new(post_view.community.actor_id),
-      reason.to_string(),
-      context,
-    )
-    .await?;
-
     Ok(res)
   }
 }
index 188a722ffe1c4331b8eafa02661441322e59300c..2feed7ed2ea90c62f04f974e120c3459fea980fa 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{ListPostReports, ListPostReportsResponse},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_views::post_report_view::PostReportQuery;
 use lemmy_utils::{error::LemmyError, ConnectionId};
index 6c3d62f185a5ba328c59adf00aeb324cda6c6383..0e2b9e16a0b857d2b56f817276d625f4926eb7bd 100644 (file)
@@ -1,10 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{PostReportResponse, ResolvePostReport},
   utils::{get_local_user_view_from_jwt, is_mod_or_admin},
   websocket::{messages::SendModRoomMessage, UserOperation},
-  LemmyContext,
 };
 use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
 use lemmy_db_views::structs::PostReportView;
index ba0e70d59749dac71e366f34bfd43490965d746c..9c3c3d8ae06763a8210a67fa60684e227cb80503 100644 (file)
@@ -1,10 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
   utils::get_local_user_view_from_jwt,
   websocket::{send::send_pm_ws_message, UserOperation},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
index 6b923c1024c1f919718837809b276a62d7796a93..66875c614c97febbdc32eacb7d5e545c24f291d5 100644 (file)
@@ -1,10 +1,10 @@
 use crate::{check_report_reason, Perform};
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
   utils::get_local_user_view_from_jwt,
   websocket::{messages::SendModRoomMessage, UserOperation},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   newtypes::CommunityId,
index 17fc438ff2ba30a48779060d6d67700fc6d62253..98c2d92698c1790533a45c6048e5b4fef8657bdb 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse},
   utils::{get_local_user_view_from_jwt, is_admin},
-  LemmyContext,
 };
 use lemmy_db_views::private_message_report_view::PrivateMessageReportQuery;
 use lemmy_utils::{error::LemmyError, ConnectionId};
index eeda4ed4246747fe4a2d97aa230b3451394bb960..2a3f677ad8eb48dea53d66de0e290cce1607ca40 100644 (file)
@@ -1,10 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
   utils::{get_local_user_view_from_jwt, is_admin},
   websocket::{messages::SendModRoomMessage, UserOperation},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   newtypes::CommunityId,
index 4674f43bfaf0fd274ad3cf58a59af8170c02dfd8..7a75db51dc239464cf0b3a7dff8ede8fdbf99727 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{GetSiteResponse, LeaveAdmin},
   utils::{get_local_user_view_from_jwt, is_admin},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index 531c0508590d4f3ca7c20c1a374c4b82dda527a1..4e3694ce4640172d7a1b3d6e01021bc52d9e23b8 100644 (file)
@@ -2,5 +2,3 @@ mod leave_admin;
 mod mod_log;
 mod purge;
 mod registration_applications;
-mod resolve_object;
-mod search;
index 85bfc40ce456713192784e408beb6070f17a036a..5e1c71a701e2d4969b75aedfb4eb57d8a4aa5b57 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{GetModlog, GetModlogResponse},
   utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin, is_mod_or_admin},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   newtypes::{CommunityId, PersonId},
index 54f3c0edf9eba6c960a8d96c65dae41d0d0149b0..71d2c7889979422b76204f4a7f1f1b2919b12ab4 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{PurgeComment, PurgeItemResponse},
   utils::{get_local_user_view_from_jwt, is_admin},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index c70c8c0a7e2cd3078af1b25e46471143fa54a033..e3a673b74f6d244b5cf8fdc4056fe1b846b66925 100644 (file)
@@ -1,10 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   request::purge_image_from_pictrs,
   site::{PurgeCommunity, PurgeItemResponse},
   utils::{get_local_user_view_from_jwt, is_admin, purge_image_posts_for_community},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index 8a5f6ac09885566870c42a574e35a8dc756fd1a3..658e50b6dc32fbfa3b040d486207972e28c820d0 100644 (file)
@@ -1,10 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   request::purge_image_from_pictrs,
   site::{PurgeItemResponse, PurgePerson},
   utils::{get_local_user_view_from_jwt, is_admin, purge_image_posts_for_person},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index b3ec28eace886b9951831d4df3a867c456918ea1..aa2e74839cbaa4d230c961948185105ff10d67da 100644 (file)
@@ -1,10 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   request::purge_image_from_pictrs,
   site::{PurgeItemResponse, PurgePost},
   utils::{get_local_user_view_from_jwt, is_admin},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index c5089b5d5228e0a3da2bc541b3abc7071037668d..61a6868995079374a72742cfa11cce2143b455a7 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{ApproveRegistrationApplication, RegistrationApplicationResponse},
   utils::{get_local_user_view_from_jwt, is_admin, send_application_approved_email},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index 1ce709b35698b2846127d9d7cba2e659d3e44dac..7be2e2e8e5580fb71a5ece2297e24622e940356f 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{ListRegistrationApplications, ListRegistrationApplicationsResponse},
   utils::{get_local_user_view_from_jwt, is_admin},
-  LemmyContext,
 };
 use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
index a22d14e956196cdd2fb75599abc701f6317665a0..fe33d17c8f19677e80ee4cbdbff3bfb877c00156 100644 (file)
@@ -1,9 +1,9 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse},
   utils::{get_local_user_view_from_jwt, is_admin},
-  LemmyContext,
 };
 use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_db_views::structs::RegistrationApplicationView;
index 0e0c015a1b78ce78c2664e4f50b55a64c88193b2..ca755bde939efd9409a8a272acf4681564e264fd 100644 (file)
@@ -1,6 +1,7 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   utils::get_local_user_view_from_jwt,
   websocket::{
     messages::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
@@ -15,7 +16,6 @@ use lemmy_api_common::{
       UserJoinResponse,
     },
   },
-  LemmyContext,
 };
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
diff --git a/crates/api_common/src/context.rs b/crates/api_common/src/context.rs
new file mode 100644 (file)
index 0000000..e552af5
--- /dev/null
@@ -0,0 +1,68 @@
+use crate::websocket::chat_server::ChatServer;
+use actix::Addr;
+use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
+use lemmy_utils::{
+  rate_limit::RateLimitCell,
+  settings::{structs::Settings, SETTINGS},
+};
+use reqwest_middleware::ClientWithMiddleware;
+
+pub struct LemmyContext {
+  pool: DbPool,
+  chat_server: Addr<ChatServer>,
+  client: ClientWithMiddleware,
+  settings: Settings,
+  secret: Secret,
+  rate_limit_cell: RateLimitCell,
+}
+
+impl LemmyContext {
+  pub fn create(
+    pool: DbPool,
+    chat_server: Addr<ChatServer>,
+    client: ClientWithMiddleware,
+    settings: Settings,
+    secret: Secret,
+    rate_limit_cell: RateLimitCell,
+  ) -> LemmyContext {
+    LemmyContext {
+      pool,
+      chat_server,
+      client,
+      settings,
+      secret,
+      rate_limit_cell,
+    }
+  }
+  pub fn pool(&self) -> &DbPool {
+    &self.pool
+  }
+  pub fn chat_server(&self) -> &Addr<ChatServer> {
+    &self.chat_server
+  }
+  pub fn client(&self) -> &ClientWithMiddleware {
+    &self.client
+  }
+  pub fn settings(&self) -> &'static Settings {
+    &SETTINGS
+  }
+  pub fn secret(&self) -> &Secret {
+    &self.secret
+  }
+  pub fn settings_updated_channel(&self) -> &RateLimitCell {
+    &self.rate_limit_cell
+  }
+}
+
+impl Clone for LemmyContext {
+  fn clone(&self) -> Self {
+    LemmyContext {
+      pool: self.pool.clone(),
+      chat_server: self.chat_server.clone(),
+      client: self.client.clone(),
+      settings: self.settings.clone(),
+      secret: self.secret.clone(),
+      rate_limit_cell: self.rate_limit_cell.clone(),
+    }
+  }
+}
index 990780e151760209d2dc69fb3a2758fe6c033c46..29686aba6d6bfb521d912166c274f0038e271e34 100644 (file)
@@ -1,5 +1,7 @@
 pub mod comment;
 pub mod community;
+#[cfg(feature = "full")]
+pub mod context;
 pub mod person;
 pub mod post;
 pub mod private_message;
@@ -9,6 +11,7 @@ pub mod sensitive;
 pub mod site;
 #[cfg(feature = "full")]
 pub mod utils;
+#[cfg(feature = "full")]
 pub mod websocket;
 
 #[macro_use]
@@ -17,138 +20,3 @@ pub extern crate lemmy_db_schema;
 pub extern crate lemmy_db_views;
 pub extern crate lemmy_db_views_actor;
 pub extern crate lemmy_db_views_moderator;
-
-use crate::websocket::chat_server::ChatServer;
-use actix::Addr;
-use anyhow::Context;
-use lemmy_db_schema::{newtypes::DbUrl, source::secret::Secret, utils::DbPool};
-use lemmy_utils::{
-  error::LemmyError,
-  location_info,
-  rate_limit::RateLimitCell,
-  settings::{structs::Settings, SETTINGS},
-};
-use reqwest_middleware::ClientWithMiddleware;
-use url::{ParseError, Url};
-
-pub struct LemmyContext {
-  pool: DbPool,
-  chat_server: Addr<ChatServer>,
-  client: ClientWithMiddleware,
-  settings: Settings,
-  secret: Secret,
-  rate_limit_cell: RateLimitCell,
-}
-
-impl LemmyContext {
-  pub fn create(
-    pool: DbPool,
-    chat_server: Addr<ChatServer>,
-    client: ClientWithMiddleware,
-    settings: Settings,
-    secret: Secret,
-    settings_updated_channel: RateLimitCell,
-  ) -> LemmyContext {
-    LemmyContext {
-      pool,
-      chat_server,
-      client,
-      settings,
-      secret,
-      rate_limit_cell: settings_updated_channel,
-    }
-  }
-  pub fn pool(&self) -> &DbPool {
-    &self.pool
-  }
-  pub fn chat_server(&self) -> &Addr<ChatServer> {
-    &self.chat_server
-  }
-  pub fn client(&self) -> &ClientWithMiddleware {
-    &self.client
-  }
-  pub fn settings(&self) -> &'static Settings {
-    &SETTINGS
-  }
-  pub fn secret(&self) -> &Secret {
-    &self.secret
-  }
-  pub fn settings_updated_channel(&self) -> &RateLimitCell {
-    &self.rate_limit_cell
-  }
-}
-
-impl Clone for LemmyContext {
-  fn clone(&self) -> Self {
-    LemmyContext {
-      pool: self.pool.clone(),
-      chat_server: self.chat_server.clone(),
-      client: self.client.clone(),
-      settings: self.settings.clone(),
-      secret: self.secret.clone(),
-      rate_limit_cell: self.rate_limit_cell.clone(),
-    }
-  }
-}
-
-pub enum EndpointType {
-  Community,
-  Person,
-  Post,
-  Comment,
-  PrivateMessage,
-}
-
-/// Generates an apub endpoint for a given domain, IE xyz.tld
-pub fn generate_local_apub_endpoint(
-  endpoint_type: EndpointType,
-  name: &str,
-  domain: &str,
-) -> Result<DbUrl, ParseError> {
-  let point = match endpoint_type {
-    EndpointType::Community => "c",
-    EndpointType::Person => "u",
-    EndpointType::Post => "post",
-    EndpointType::Comment => "comment",
-    EndpointType::PrivateMessage => "private_message",
-  };
-
-  Ok(Url::parse(&format!("{}/{}/{}", domain, point, name))?.into())
-}
-
-pub fn generate_followers_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
-  Ok(Url::parse(&format!("{}/followers", actor_id))?.into())
-}
-
-pub fn generate_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
-  Ok(Url::parse(&format!("{}/inbox", actor_id))?.into())
-}
-
-pub fn generate_site_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
-  let mut actor_id: Url = actor_id.clone().into();
-  actor_id.set_path("site_inbox");
-  Ok(actor_id.into())
-}
-
-pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError> {
-  let actor_id: Url = actor_id.clone().into();
-  let url = format!(
-    "{}://{}{}/inbox",
-    &actor_id.scheme(),
-    &actor_id.host_str().context(location_info!())?,
-    if let Some(port) = actor_id.port() {
-      format!(":{}", port)
-    } else {
-      String::new()
-    },
-  );
-  Ok(Url::parse(&url)?.into())
-}
-
-pub fn generate_outbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
-  Ok(Url::parse(&format!("{}/outbox", actor_id))?.into())
-}
-
-pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
-  Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
-}
index 8c4131dd64fcfd085c2d10afaaa70203135c5823..897dd998ec7d8f98927e748e3fa02ba802900a10 100644 (file)
@@ -268,7 +268,7 @@ pub struct GetUnreadCountResponse {
   pub private_messages: i64,
 }
 
-#[derive(Serialize, Deserialize, Clone, Default)]
+#[derive(Serialize, Deserialize, Clone, Default, Debug)]
 pub struct VerifyEmail {
   pub token: String,
 }
index 1e863e855c4ec266ddae4865df5ef640ea7ed545..c85344992075cc5742d2612feea7d29ef2b61042 100644 (file)
@@ -1,8 +1,9 @@
 use crate::{request::purge_image_from_pictrs, sensitive::Sensitive, site::FederatedInstances};
+use anyhow::Context;
 use chrono::NaiveDateTime;
 use lemmy_db_schema::{
   impls::person::is_banned,
-  newtypes::{CommunityId, LocalUserId, PersonId, PostId},
+  newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId},
   source::{
     comment::{Comment, CommentUpdateForm},
     community::{Community, CommunityUpdateForm},
@@ -34,6 +35,7 @@ use lemmy_utils::{
   claims::Claims,
   email::{send_email, translations::Lang},
   error::LemmyError,
+  location_info,
   rate_limit::RateLimitConfig,
   settings::structs::Settings,
   utils::{build_slur_regex, generate_random_string},
@@ -43,6 +45,7 @@ use reqwest_middleware::ClientWithMiddleware;
 use rosetta_i18n::{Language, LanguageId};
 use std::str::FromStr;
 use tracing::warn;
+use url::{ParseError, Url};
 
 #[tracing::instrument(skip_all)]
 pub async fn is_mod_or_admin(
@@ -743,3 +746,65 @@ mod tests {
     assert!(honeypot_check(&Some("message".to_string())).is_err());
   }
 }
+
+pub enum EndpointType {
+  Community,
+  Person,
+  Post,
+  Comment,
+  PrivateMessage,
+}
+
+/// Generates an apub endpoint for a given domain, IE xyz.tld
+pub fn generate_local_apub_endpoint(
+  endpoint_type: EndpointType,
+  name: &str,
+  domain: &str,
+) -> Result<DbUrl, ParseError> {
+  let point = match endpoint_type {
+    EndpointType::Community => "c",
+    EndpointType::Person => "u",
+    EndpointType::Post => "post",
+    EndpointType::Comment => "comment",
+    EndpointType::PrivateMessage => "private_message",
+  };
+
+  Ok(Url::parse(&format!("{}/{}/{}", domain, point, name))?.into())
+}
+
+pub fn generate_followers_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
+  Ok(Url::parse(&format!("{}/followers", actor_id))?.into())
+}
+
+pub fn generate_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
+  Ok(Url::parse(&format!("{}/inbox", actor_id))?.into())
+}
+
+pub fn generate_site_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
+  let mut actor_id: Url = actor_id.clone().into();
+  actor_id.set_path("site_inbox");
+  Ok(actor_id.into())
+}
+
+pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError> {
+  let actor_id: Url = actor_id.clone().into();
+  let url = format!(
+    "{}://{}{}/inbox",
+    &actor_id.scheme(),
+    &actor_id.host_str().context(location_info!())?,
+    if let Some(port) = actor_id.port() {
+      format!(":{}", port)
+    } else {
+      String::new()
+    },
+  );
+  Ok(Url::parse(&url)?.into())
+}
+
+pub fn generate_outbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
+  Ok(Url::parse(&format!("{}/outbox", actor_id))?.into())
+}
+
+pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
+  Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
+}
index c8f59e3d21bc317852d049d99dd56e9542258161..b669a4fd30fd7bfe21326362df9c91b54b7abf73 100644 (file)
@@ -1,14 +1,15 @@
 use crate::{
   comment::CommentResponse,
+  context::LemmyContext,
   post::PostResponse,
   websocket::{
     messages::{CaptchaItem, StandardMessage, WsMessage},
     serialize_websocket_message,
     OperationType,
     UserOperation,
+    UserOperationApub,
     UserOperationCrud,
   },
-  LemmyContext,
 };
 use actix::prelude::*;
 use anyhow::Context as acontext;
@@ -50,6 +51,13 @@ type MessageHandlerCrudType = fn(
   data: &str,
 ) -> Pin<Box<dyn Future<Output = Result<String, LemmyError>> + '_>>;
 
+type MessageHandlerApubType = fn(
+  context: LemmyContext,
+  id: ConnectionId,
+  op: UserOperationApub,
+  data: &str,
+) -> Pin<Box<dyn Future<Output = Result<String, LemmyError>> + '_>>;
+
 /// `ChatServer` manages chat rooms and responsible for coordinating chat
 /// session.
 pub struct ChatServer {
@@ -84,6 +92,7 @@ pub struct ChatServer {
 
   message_handler: MessageHandlerType,
   message_handler_crud: MessageHandlerCrudType,
+  message_handler_apub: MessageHandlerApubType,
 
   /// An HTTP Client
   client: ClientWithMiddleware,
@@ -105,6 +114,7 @@ impl ChatServer {
     pool: DbPool,
     message_handler: MessageHandlerType,
     message_handler_crud: MessageHandlerCrudType,
+    message_handler_apub: MessageHandlerApubType,
     client: ClientWithMiddleware,
     settings: Settings,
     secret: Secret,
@@ -121,6 +131,7 @@ impl ChatServer {
       captchas: Vec::new(),
       message_handler,
       message_handler_crud,
+      message_handler_apub,
       client,
       settings,
       secret,
@@ -453,16 +464,17 @@ impl ChatServer {
       None => IpAddr("blank_ip".to_string()),
     };
 
-    let context = LemmyContext {
-      pool: self.pool.clone(),
-      chat_server: ctx.address(),
-      client: self.client.clone(),
-      settings: self.settings.clone(),
-      secret: self.secret.clone(),
-      rate_limit_cell: self.rate_limit_cell.clone(),
-    };
+    let context = LemmyContext::create(
+      self.pool.clone(),
+      ctx.address(),
+      self.client.clone(),
+      self.settings.clone(),
+      self.secret.clone(),
+      self.rate_limit_cell.clone(),
+    );
     let message_handler_crud = self.message_handler_crud;
     let message_handler = self.message_handler;
+    let message_handler_apub = self.message_handler_apub;
     let rate_limiter = self.rate_limit_cell.clone();
     async move {
       let json: Value = serde_json::from_str(&msg.msg)?;
@@ -482,15 +494,21 @@ impl ChatServer {
         };
         let fut = (message_handler_crud)(context, msg.id, user_operation_crud, data);
         (passed, fut)
-      } else {
-        let user_operation = UserOperation::from_str(op)?;
+      } else if let Ok(user_operation) = UserOperation::from_str(op) {
         let passed = match user_operation {
           UserOperation::GetCaptcha => rate_limiter.post().check(ip),
-          UserOperation::Search => rate_limiter.search().check(ip),
           _ => rate_limiter.message().check(ip),
         };
         let fut = (message_handler)(context, msg.id, user_operation, data);
         (passed, fut)
+      } else {
+        let user_operation = UserOperationApub::from_str(op)?;
+        let passed = match user_operation {
+          UserOperationApub::Search => rate_limiter.search().check(ip),
+          _ => rate_limiter.message().check(ip),
+        };
+        let fut = (message_handler_apub)(context, msg.id, user_operation, data);
+        (passed, fut)
       };
 
       // if rate limit passed, execute api call future
index d1e30f44814f91592adc554d3de154bcb892c5c2..430027cfaebabf15055b4f9ed31953a3c2e09aa5 100644 (file)
@@ -63,8 +63,6 @@ pub enum UserOperation {
   ApproveRegistrationApplication,
   BanPerson,
   GetBannedPersons,
-  Search,
-  ResolveObject,
   MarkAllAsRead,
   SaveUserSettings,
   TransferCommunity,
@@ -98,27 +96,23 @@ pub enum UserOperationCrud {
   // Community
   CreateCommunity,
   ListCommunities,
-  GetCommunity,
   EditCommunity,
   DeleteCommunity,
   RemoveCommunity,
   // Post
   CreatePost,
   GetPost,
-  GetPosts,
   EditPost,
   DeletePost,
   RemovePost,
   // Comment
   CreateComment,
   GetComment,
-  GetComments,
   EditComment,
   DeleteComment,
   RemoveComment,
   // User
   Register,
-  GetPersonDetails,
   DeleteAccount,
   // Private Message
   CreatePrivateMessage,
@@ -127,8 +121,20 @@ pub enum UserOperationCrud {
   DeletePrivateMessage,
 }
 
+#[derive(EnumString, Display, Debug, Clone)]
+pub enum UserOperationApub {
+  GetPosts,
+  GetCommunity,
+  GetComments,
+  GetPersonDetails,
+  Search,
+  ResolveObject,
+}
+
 pub trait OperationType {}
 
 impl OperationType for UserOperationCrud {}
 
 impl OperationType for UserOperation {}
+
+impl OperationType for UserOperationApub {}
index 7b500ce4c49a6c2e46ec5fbb2bf4e5d7e5520ac7..936dc9998c2b495caa14f9782d48001b0de27e83 100644 (file)
@@ -1,9 +1,9 @@
 use crate::{
+  context::LemmyContext,
   websocket::{
     chat_server::ChatServer,
     messages::{Connect, Disconnect, StandardMessage, WsMessage},
   },
-  LemmyContext,
 };
 use actix::prelude::*;
 use actix_web::{web, Error, HttpRequest, HttpResponse};
index 6f3506aee6c927fb68afa43ed1cf41c9f450645f..cd53955f9f42791d602668e871c2883f0135cd79 100644 (file)
@@ -1,6 +1,7 @@
 use crate::{
   comment::CommentResponse,
   community::CommunityResponse,
+  context::LemmyContext,
   post::PostResponse,
   private_message::PrivateMessageResponse,
   utils::{check_person_block, get_interface_language, send_email_to_user},
@@ -8,7 +9,6 @@ use crate::{
     messages::{SendComment, SendCommunityRoomMessage, SendPost, SendUserRoomMessage},
     OperationType,
   },
-  LemmyContext,
 };
 use lemmy_db_schema::{
   newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId},
index 7a16aed5c6c0658aefb75ce8ec637ee1c7302267..2d1774463c1a1515fc5d32a1941856d064b91db5 100644 (file)
@@ -9,7 +9,6 @@ documentation.workspace = true
 repository.workspace = true
 
 [dependencies]
-lemmy_apub = { workspace = true }
 lemmy_utils = { workspace = true }
 lemmy_db_schema = { workspace = true, features = ["full"] }
 lemmy_db_views = { workspace = true, features = ["full"] }
index 5d9603ac320e5859239d79c06b58ed5fd5c6f5cb..8c61a0444cfb23cf3422b9eda7f3b07134fb3a36 100644 (file)
@@ -2,25 +2,21 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{CommentResponse, CreateComment},
-  generate_local_apub_endpoint,
+  context::LemmyContext,
   utils::{
     check_community_ban,
     check_community_deleted_or_removed,
     check_post_deleted_or_removed,
+    generate_local_apub_endpoint,
     get_local_user_view_from_jwt,
     get_post,
     local_site_to_slur_regex,
+    EndpointType,
   },
   websocket::{
     send::{send_comment_ws_message, send_local_notifs},
     UserOperationCrud,
   },
-  EndpointType,
-  LemmyContext,
-};
-use lemmy_apub::{
-  objects::comment::ApubComment,
-  protocol::activities::{create_or_update::note::CreateOrUpdateNote, CreateOrUpdateType},
 };
 use lemmy_db_schema::{
   source::{
@@ -157,16 +153,6 @@ impl PerformCrud for CreateComment {
       .await
       .map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
 
-    let apub_comment: ApubComment = updated_comment.into();
-    CreateOrUpdateNote::send(
-      apub_comment.clone(),
-      &local_user_view.person.clone().into(),
-      CreateOrUpdateType::Create,
-      context,
-      &mut 0,
-    )
-    .await?;
-
     // If its a reply, mark the parent as read
     if let Some(parent) = parent_opt {
       let parent_id = parent.id;
index f14d0d415902bc406d3f79e5a565eeb284ecc7c2..211d04776747bdf06b8090f61d2260560686bee8 100644 (file)
@@ -2,18 +2,16 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{CommentResponse, DeleteComment},
+  context::LemmyContext,
   utils::{check_community_ban, get_local_user_view_from_jwt},
   websocket::{
     send::{send_comment_ws_message, send_local_notifs},
     UserOperationCrud,
   },
-  LemmyContext,
 };
-use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
 use lemmy_db_schema::{
   source::{
     comment::{Comment, CommentUpdateForm},
-    community::Community,
     post::Post,
   },
   traits::Crud,
@@ -88,19 +86,6 @@ impl PerformCrud for DeleteComment {
     )
     .await?;
 
-    // Send the apub message
-    let community = Community::read(context.pool(), orig_comment.post.community_id).await?;
-    let deletable = DeletableObjects::Comment(Box::new(updated_comment.clone().into()));
-    send_apub_delete_in_community(
-      local_user_view.person,
-      community,
-      deletable,
-      None,
-      deleted,
-      context,
-    )
-    .await?;
-
     Ok(res)
   }
 }
index 1e8328034d89d61d25e563985ddb8618a153f58b..d3d789a02ab30217a8be7e11ee3dee5b707360cf 100644 (file)
@@ -1,6 +1,5 @@
 mod create;
 mod delete;
-mod list;
 mod read;
 mod remove;
 mod update;
index 98b3431c29c143926738e67c9c8d542761518f2e..c0136f06cb28b8e24cbb9449bd9151eb96936bc3 100644 (file)
@@ -2,8 +2,8 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{CommentResponse, GetComment},
+  context::LemmyContext,
   utils::{check_private_instance, get_local_user_view_from_jwt_opt},
-  LemmyContext,
 };
 use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_db_views::structs::CommentView;
index 09e5fdfcaca55739c37a1c0b1b26bf498910269d..1032f54c9f985614bd8961ff82184e6219a4ba7b 100644 (file)
@@ -2,18 +2,16 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{CommentResponse, RemoveComment},
+  context::LemmyContext,
   utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin},
   websocket::{
     send::{send_comment_ws_message, send_local_notifs},
     UserOperationCrud,
   },
-  LemmyContext,
 };
-use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
 use lemmy_db_schema::{
   source::{
     comment::{Comment, CommentUpdateForm},
-    community::Community,
     moderator::{ModRemoveComment, ModRemoveCommentForm},
     post::Post,
   },
@@ -96,19 +94,6 @@ impl PerformCrud for RemoveComment {
     )
     .await?;
 
-    // Send the apub message
-    let community = Community::read(context.pool(), orig_comment.post.community_id).await?;
-    let deletable = DeletableObjects::Comment(Box::new(updated_comment.clone().into()));
-    send_apub_delete_in_community(
-      local_user_view.person,
-      community,
-      deletable,
-      data.reason.clone().or_else(|| Some(String::new())),
-      removed,
-      context,
-    )
-    .await?;
-
     Ok(res)
   }
 }
index d1fcccd9c943d91a3fd6192206c408e97a8650fc..88de41158ea44863992c69172f69421938cdb715 100644 (file)
@@ -2,6 +2,7 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{CommentResponse, EditComment},
+  context::LemmyContext,
   utils::{
     check_community_ban,
     check_community_deleted_or_removed,
@@ -14,11 +15,6 @@ use lemmy_api_common::{
     send::{send_comment_ws_message, send_local_notifs},
     UserOperationCrud,
   },
-  LemmyContext,
-};
-use lemmy_apub::protocol::activities::{
-  create_or_update::note::CreateOrUpdateNote,
-  CreateOrUpdateType,
 };
 use lemmy_db_schema::{
   source::{
@@ -114,16 +110,6 @@ impl PerformCrud for EditComment {
     )
     .await?;
 
-    // Send the apub update
-    CreateOrUpdateNote::send(
-      updated_comment.into(),
-      &local_user_view.person.into(),
-      CreateOrUpdateType::Update,
-      context,
-      &mut 0,
-    )
-    .await?;
-
     send_comment_ws_message(
       data.comment_id,
       UserOperationCrud::EditComment,
index 11a30766831cfa98162b2fef460114f53a283aeb..cf894edbd62abd0d00d8623f6ab4a809e9127b33 100644 (file)
@@ -1,17 +1,20 @@
 use crate::PerformCrud;
-use activitypub_federation::core::{object_id::ObjectId, signatures::generate_actor_keypair};
+use activitypub_federation::core::signatures::generate_actor_keypair;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{CommunityResponse, CreateCommunity},
-  generate_followers_url,
-  generate_inbox_url,
-  generate_local_apub_endpoint,
-  generate_shared_inbox_url,
-  utils::{get_local_user_view_from_jwt, is_admin, local_site_to_slur_regex},
-  EndpointType,
-  LemmyContext,
+  context::LemmyContext,
+  utils::{
+    generate_followers_url,
+    generate_inbox_url,
+    generate_local_apub_endpoint,
+    generate_shared_inbox_url,
+    get_local_user_view_from_jwt,
+    is_admin,
+    local_site_to_slur_regex,
+    EndpointType,
+  },
 };
-use lemmy_apub::objects::community::ApubCommunity;
 use lemmy_db_schema::{
   source::community::{
     Community,
@@ -21,7 +24,7 @@ use lemmy_db_schema::{
     CommunityModerator,
     CommunityModeratorForm,
   },
-  traits::{Crud, Followable, Joinable},
+  traits::{ApubActor, Crud, Followable, Joinable},
   utils::diesel_option_overwrite_to_url_create,
 };
 use lemmy_db_views::structs::SiteView;
@@ -73,9 +76,8 @@ impl PerformCrud for CreateCommunity {
       &data.name,
       &context.settings().get_protocol_and_hostname(),
     )?;
-    let community_actor_id_wrapped = ObjectId::<ApubCommunity>::new(community_actor_id.clone());
-    let community_dupe = community_actor_id_wrapped.dereference_local(context).await;
-    if community_dupe.is_ok() {
+    let community_dupe = Community::read_from_apub_id(context.pool(), &community_actor_id).await?;
+    if community_dupe.is_some() {
       return Err(LemmyError::from_message("community_already_exists"));
     }
 
index 7d3122ab4ed8b539942b70e98d16340e63f987bb..84de55477eac0da1db91b9927046e0fc06bd80a1 100644 (file)
@@ -2,11 +2,10 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{CommunityResponse, DeleteCommunity},
+  context::LemmyContext,
   utils::get_local_user_view_from_jwt,
   websocket::{send::send_community_ws_message, UserOperationCrud},
-  LemmyContext,
 };
-use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
 use lemmy_db_schema::{
   source::community::{Community, CommunityUpdateForm},
   traits::Crud,
@@ -41,7 +40,7 @@ impl PerformCrud for DeleteCommunity {
     // Do the delete
     let community_id = data.community_id;
     let deleted = data.deleted;
-    let updated_community = Community::update(
+    Community::update(
       context.pool(),
       community_id,
       &CommunityUpdateForm::builder()
@@ -60,18 +59,6 @@ impl PerformCrud for DeleteCommunity {
     )
     .await?;
 
-    // Send apub messages
-    let deletable = DeletableObjects::Community(Box::new(updated_community.clone().into()));
-    send_apub_delete_in_community(
-      local_user_view.person,
-      updated_community,
-      deletable,
-      None,
-      deleted,
-      context,
-    )
-    .await?;
-
     Ok(res)
   }
 }
index f77ebce75537bb7da4b24fce3e72525d6940f309..4d2e7046fe42a02f0b29524272f2cef773e41d3f 100644 (file)
@@ -2,8 +2,8 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{ListCommunities, ListCommunitiesResponse},
+  context::LemmyContext,
   utils::{check_private_instance, get_local_user_view_from_jwt_opt},
-  LemmyContext,
 };
 use lemmy_db_schema::{source::local_site::LocalSite, traits::DeleteableOrRemoveable};
 use lemmy_db_views_actor::community_view::CommunityQuery;
index 1e8328034d89d61d25e563985ddb8618a153f58b..3fc7416525e0f98aa34411b85c7be239be89b998 100644 (file)
@@ -1,6 +1,5 @@
 mod create;
 mod delete;
 mod list;
-mod read;
 mod remove;
 mod update;
index 77c2bde30a8d37275bb713d08d778d50847958db..215b39cf4a19e974023e90efb0a3ee2857554353 100644 (file)
@@ -2,11 +2,10 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{CommunityResponse, RemoveCommunity},
+  context::LemmyContext,
   utils::{get_local_user_view_from_jwt, is_admin},
   websocket::{send::send_community_ws_message, UserOperationCrud},
-  LemmyContext,
 };
-use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
 use lemmy_db_schema::{
   source::{
     community::{Community, CommunityUpdateForm},
@@ -36,7 +35,7 @@ impl PerformCrud for RemoveCommunity {
     // Do the remove
     let community_id = data.community_id;
     let removed = data.removed;
-    let updated_community = Community::update(
+    Community::update(
       context.pool(),
       community_id,
       &CommunityUpdateForm::builder()
@@ -66,17 +65,6 @@ impl PerformCrud for RemoveCommunity {
     )
     .await?;
 
-    // Apub messages
-    let deletable = DeletableObjects::Community(Box::new(updated_community.clone().into()));
-    send_apub_delete_in_community(
-      local_user_view.person,
-      updated_community,
-      deletable,
-      data.reason.clone().or_else(|| Some(String::new())),
-      removed,
-      context,
-    )
-    .await?;
     Ok(res)
   }
 }
index 2bde94ea63018adcf2ba40c40045fadc6544f368..9059a4a6f636ac5e490ca8d0e1e72e145e11d1d0 100644 (file)
@@ -2,11 +2,10 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{CommunityResponse, EditCommunity},
+  context::LemmyContext,
   utils::{get_local_user_view_from_jwt, local_site_to_slur_regex},
   websocket::{send::send_community_ws_message, UserOperationCrud},
-  LemmyContext,
 };
-use lemmy_apub::protocol::activities::community::update::UpdateCommunity;
 use lemmy_db_schema::{
   newtypes::PersonId,
   source::{
@@ -74,17 +73,10 @@ impl PerformCrud for EditCommunity {
       .build();
 
     let community_id = data.community_id;
-    let updated_community = Community::update(context.pool(), community_id, &community_form)
+    Community::update(context.pool(), community_id, &community_form)
       .await
       .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
 
-    UpdateCommunity::send(
-      updated_community.into(),
-      &local_user_view.person.into(),
-      context,
-    )
-    .await?;
-
     let op = UserOperationCrud::EditCommunity;
     send_community_ws_message(data.community_id, op, websocket_id, None, context).await
   }
index fde81eddbe01e8e25b024ebd8489e662316721dd..d37dfbee243133ec56a8650f5d6487efb62f8e12 100644 (file)
@@ -1,28 +1,6 @@
-use actix_web::{web, web::Data};
-use lemmy_api_common::{
-  comment::{CreateComment, DeleteComment, EditComment, GetComment, GetComments, RemoveComment},
-  community::{
-    CreateCommunity,
-    DeleteCommunity,
-    EditCommunity,
-    GetCommunity,
-    ListCommunities,
-    RemoveCommunity,
-  },
-  person::{DeleteAccount, GetPersonDetails, Register},
-  post::{CreatePost, DeletePost, EditPost, GetPost, GetPosts, RemovePost},
-  private_message::{
-    CreatePrivateMessage,
-    DeletePrivateMessage,
-    EditPrivateMessage,
-    GetPrivateMessages,
-  },
-  site::{CreateSite, EditSite, GetSite},
-  websocket::{serialize_websocket_message, UserOperationCrud},
-  LemmyContext,
-};
+use actix_web::web::Data;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::{error::LemmyError, ConnectionId};
-use serde::Deserialize;
 
 mod comment;
 mod community;
@@ -41,115 +19,3 @@ pub trait PerformCrud {
     websocket_id: Option<ConnectionId>,
   ) -> Result<Self::Response, LemmyError>;
 }
-
-pub async fn match_websocket_operation_crud(
-  context: LemmyContext,
-  id: ConnectionId,
-  op: UserOperationCrud,
-  data: &str,
-) -> Result<String, LemmyError> {
-  //TODO: handle commented out actions in crud crate
-
-  match op {
-    // User ops
-    UserOperationCrud::Register => do_websocket_operation::<Register>(context, id, op, data).await,
-    UserOperationCrud::GetPersonDetails => {
-      do_websocket_operation::<GetPersonDetails>(context, id, op, data).await
-    }
-    UserOperationCrud::DeleteAccount => {
-      do_websocket_operation::<DeleteAccount>(context, id, op, data).await
-    }
-
-    // Private Message ops
-    UserOperationCrud::CreatePrivateMessage => {
-      do_websocket_operation::<CreatePrivateMessage>(context, id, op, data).await
-    }
-    UserOperationCrud::EditPrivateMessage => {
-      do_websocket_operation::<EditPrivateMessage>(context, id, op, data).await
-    }
-    UserOperationCrud::DeletePrivateMessage => {
-      do_websocket_operation::<DeletePrivateMessage>(context, id, op, data).await
-    }
-    UserOperationCrud::GetPrivateMessages => {
-      do_websocket_operation::<GetPrivateMessages>(context, id, op, data).await
-    }
-
-    // Site ops
-    UserOperationCrud::CreateSite => {
-      do_websocket_operation::<CreateSite>(context, id, op, data).await
-    }
-    UserOperationCrud::EditSite => do_websocket_operation::<EditSite>(context, id, op, data).await,
-    UserOperationCrud::GetSite => do_websocket_operation::<GetSite>(context, id, op, data).await,
-
-    // Community ops
-    UserOperationCrud::GetCommunity => {
-      do_websocket_operation::<GetCommunity>(context, id, op, data).await
-    }
-    UserOperationCrud::ListCommunities => {
-      do_websocket_operation::<ListCommunities>(context, id, op, data).await
-    }
-    UserOperationCrud::CreateCommunity => {
-      do_websocket_operation::<CreateCommunity>(context, id, op, data).await
-    }
-    UserOperationCrud::EditCommunity => {
-      do_websocket_operation::<EditCommunity>(context, id, op, data).await
-    }
-    UserOperationCrud::DeleteCommunity => {
-      do_websocket_operation::<DeleteCommunity>(context, id, op, data).await
-    }
-    UserOperationCrud::RemoveCommunity => {
-      do_websocket_operation::<RemoveCommunity>(context, id, op, data).await
-    }
-
-    // Post ops
-    UserOperationCrud::CreatePost => {
-      do_websocket_operation::<CreatePost>(context, id, op, data).await
-    }
-    UserOperationCrud::GetPost => do_websocket_operation::<GetPost>(context, id, op, data).await,
-    UserOperationCrud::GetPosts => do_websocket_operation::<GetPosts>(context, id, op, data).await,
-    UserOperationCrud::EditPost => do_websocket_operation::<EditPost>(context, id, op, data).await,
-    UserOperationCrud::DeletePost => {
-      do_websocket_operation::<DeletePost>(context, id, op, data).await
-    }
-    UserOperationCrud::RemovePost => {
-      do_websocket_operation::<RemovePost>(context, id, op, data).await
-    }
-
-    // Comment ops
-    UserOperationCrud::CreateComment => {
-      do_websocket_operation::<CreateComment>(context, id, op, data).await
-    }
-    UserOperationCrud::EditComment => {
-      do_websocket_operation::<EditComment>(context, id, op, data).await
-    }
-    UserOperationCrud::DeleteComment => {
-      do_websocket_operation::<DeleteComment>(context, id, op, data).await
-    }
-    UserOperationCrud::RemoveComment => {
-      do_websocket_operation::<RemoveComment>(context, id, op, data).await
-    }
-    UserOperationCrud::GetComment => {
-      do_websocket_operation::<GetComment>(context, id, op, data).await
-    }
-    UserOperationCrud::GetComments => {
-      do_websocket_operation::<GetComments>(context, id, op, data).await
-    }
-  }
-}
-
-async fn do_websocket_operation<'a, 'b, Data>(
-  context: LemmyContext,
-  id: ConnectionId,
-  op: UserOperationCrud,
-  data: &str,
-) -> Result<String, LemmyError>
-where
-  for<'de> Data: Deserialize<'de> + 'a,
-  Data: PerformCrud,
-{
-  let parsed_data: Data = serde_json::from_str(data)?;
-  let res = parsed_data
-    .perform(&web::Data::new(context), Some(id))
-    .await?;
-  serialize_websocket_message(&op, &res)
-}
index 46d4a7f644befeea10225eada2420b994ff186b8..af62135e2a89807443563f3f203c6b4ac0a6b454 100644 (file)
@@ -1,24 +1,20 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
-  generate_local_apub_endpoint,
+  context::LemmyContext,
   post::{CreatePost, PostResponse},
   request::fetch_site_data,
   utils::{
     check_community_ban,
     check_community_deleted_or_removed,
+    generate_local_apub_endpoint,
     get_local_user_view_from_jwt,
     honeypot_check,
     local_site_to_slur_regex,
     mark_post_as_read,
+    EndpointType,
   },
   websocket::{send::send_post_ws_message, UserOperationCrud},
-  EndpointType,
-  LemmyContext,
-};
-use lemmy_apub::{
-  objects::post::ApubPost,
-  protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
 };
 use lemmy_db_schema::{
   impls::actor_language::default_post_language,
@@ -174,15 +170,6 @@ impl PerformCrud for CreatePost {
       }
     }
 
-    let apub_post: ApubPost = updated_post.into();
-    CreateOrUpdatePage::send(
-      apub_post.clone(),
-      &local_user_view.person.clone().into(),
-      CreateOrUpdateType::Create,
-      context,
-    )
-    .await?;
-
     send_post_ws_message(
       inserted_post.id,
       UserOperationCrud::CreatePost,
index de1490b1c51acf07ebc0e4b1ca6c942d9a938c0e..57e5adb15f81b6b054231b7275f70114b688bf86 100644 (file)
@@ -1,17 +1,13 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{DeletePost, PostResponse},
   utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
   websocket::{send::send_post_ws_message, UserOperationCrud},
-  LemmyContext,
 };
-use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
 use lemmy_db_schema::{
-  source::{
-    community::Community,
-    post::{Post, PostUpdateForm},
-  },
+  source::post::{Post, PostUpdateForm},
   traits::Crud,
 };
 use lemmy_utils::{error::LemmyError, ConnectionId};
@@ -54,7 +50,7 @@ impl PerformCrud for DeletePost {
     // Update the post
     let post_id = data.post_id;
     let deleted = data.deleted;
-    let updated_post = Post::update(
+    Post::update(
       context.pool(),
       post_id,
       &PostUpdateForm::builder().deleted(Some(deleted)).build(),
@@ -70,18 +66,6 @@ impl PerformCrud for DeletePost {
     )
     .await?;
 
-    // apub updates
-    let community = Community::read(context.pool(), orig_post.community_id).await?;
-    let deletable = DeletableObjects::Post(Box::new(updated_post.into()));
-    send_apub_delete_in_community(
-      local_user_view.person,
-      community,
-      deletable,
-      None,
-      deleted,
-      context,
-    )
-    .await?;
     Ok(res)
   }
 }
index 1e8328034d89d61d25e563985ddb8618a153f58b..d3d789a02ab30217a8be7e11ee3dee5b707360cf 100644 (file)
@@ -1,6 +1,5 @@
 mod create;
 mod delete;
-mod list;
 mod read;
 mod remove;
 mod update;
index 44d1be63a51a17f4212293b6138621c2905b5e72..c6747c5e8361b5512c23b89220152c883ed377b7 100644 (file)
@@ -1,10 +1,10 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{GetPost, GetPostResponse},
   utils::{check_private_instance, get_local_user_view_from_jwt_opt, mark_post_as_read},
   websocket::messages::GetPostUsersOnline,
-  LemmyContext,
 };
 use lemmy_db_schema::{
   aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
index 525c08a68e5405a7c7e38143ce821a252cbdcff9..66af2ca959f25474d0ab0707edb1720d3b712ffa 100644 (file)
@@ -1,15 +1,13 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{PostResponse, RemovePost},
   utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin},
   websocket::{send::send_post_ws_message, UserOperationCrud},
-  LemmyContext,
 };
-use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
 use lemmy_db_schema::{
   source::{
-    community::Community,
     moderator::{ModRemovePost, ModRemovePostForm},
     post::{Post, PostUpdateForm},
   },
@@ -52,7 +50,7 @@ impl PerformCrud for RemovePost {
     // Update the post
     let post_id = data.post_id;
     let removed = data.removed;
-    let updated_post = Post::update(
+    Post::update(
       context.pool(),
       post_id,
       &PostUpdateForm::builder().removed(Some(removed)).build(),
@@ -77,18 +75,6 @@ impl PerformCrud for RemovePost {
     )
     .await?;
 
-    // apub updates
-    let community = Community::read(context.pool(), orig_post.community_id).await?;
-    let deletable = DeletableObjects::Post(Box::new(updated_post.into()));
-    send_apub_delete_in_community(
-      local_user_view.person,
-      community,
-      deletable,
-      data.reason.clone().or_else(|| Some(String::new())),
-      removed,
-      context,
-    )
-    .await?;
     Ok(res)
   }
 }
index 4c3038c87dd9f3e833720bee39cd9cbce3cb8a0c..9337c595271c90e32ce8c0afd840270bdff70acf 100644 (file)
@@ -1,6 +1,7 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{EditPost, PostResponse},
   request::fetch_site_data,
   utils::{
@@ -10,11 +11,6 @@ use lemmy_api_common::{
     local_site_to_slur_regex,
   },
   websocket::{send::send_post_ws_message, UserOperationCrud},
-  LemmyContext,
-};
-use lemmy_apub::protocol::activities::{
-  create_or_update::page::CreateOrUpdatePage,
-  CreateOrUpdateType,
 };
 use lemmy_db_schema::{
   source::{
@@ -109,27 +105,15 @@ impl PerformCrud for EditPost {
 
     let post_id = data.post_id;
     let res = Post::update(context.pool(), post_id, &post_form).await;
-    let updated_post: Post = match res {
-      Ok(post) => post,
-      Err(e) => {
-        let err_type = if e.to_string() == "value too long for type character varying(200)" {
-          "post_title_too_long"
-        } else {
-          "couldnt_update_post"
-        };
-
-        return Err(LemmyError::from_error_message(e, err_type));
-      }
-    };
-
-    // Send apub update
-    CreateOrUpdatePage::send(
-      updated_post.into(),
-      &local_user_view.person.clone().into(),
-      CreateOrUpdateType::Update,
-      context,
-    )
-    .await?;
+    if let Err(e) = res {
+      let err_type = if e.to_string() == "value too long for type character varying(200)" {
+        "post_title_too_long"
+      } else {
+        "couldnt_update_post"
+      };
+
+      return Err(LemmyError::from_error_message(e, err_type));
+    }
 
     send_post_ws_message(
       data.post_id,
index 03d994c08b79e578d0c5a5223d8b66ea78fc7886..25c7be467d063dce24ab4cce2502276472a73713 100644 (file)
@@ -1,22 +1,18 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
-  generate_local_apub_endpoint,
+  context::LemmyContext,
   private_message::{CreatePrivateMessage, PrivateMessageResponse},
   utils::{
     check_person_block,
+    generate_local_apub_endpoint,
     get_interface_language,
     get_local_user_view_from_jwt,
     local_site_to_slur_regex,
     send_email_to_user,
+    EndpointType,
   },
   websocket::{send::send_pm_ws_message, UserOperationCrud},
-  EndpointType,
-  LemmyContext,
-};
-use lemmy_apub::protocol::activities::{
-  create_or_update::chat_message::CreateOrUpdateChatMessage,
-  CreateOrUpdateType,
 };
 use lemmy_db_schema::{
   source::{
@@ -74,7 +70,7 @@ impl PerformCrud for CreatePrivateMessage {
       &inserted_private_message_id.to_string(),
       &protocol_and_hostname,
     )?;
-    let updated_private_message = PrivateMessage::update(
+    PrivateMessage::update(
       context.pool(),
       inserted_private_message.id,
       &PrivateMessageUpdateForm::builder()
@@ -84,14 +80,6 @@ impl PerformCrud for CreatePrivateMessage {
     .await
     .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_private_message"))?;
 
-    CreateOrUpdateChatMessage::send(
-      updated_private_message.into(),
-      &local_user_view.person.into(),
-      CreateOrUpdateType::Create,
-      context,
-    )
-    .await?;
-
     let res = send_pm_ws_message(
       inserted_private_message.id,
       UserOperationCrud::CreatePrivateMessage,
index ad6b78d3e47301de2e0eda8aa0eaac2b29d55685..4f58065a3eda550dbac04b67715867d0def4d31b 100644 (file)
@@ -1,12 +1,11 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   private_message::{DeletePrivateMessage, PrivateMessageResponse},
   utils::get_local_user_view_from_jwt,
   websocket::{send::send_pm_ws_message, UserOperationCrud},
-  LemmyContext,
 };
-use lemmy_apub::activities::deletion::send_apub_delete_private_message;
 use lemmy_db_schema::{
   source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
   traits::Crud,
@@ -37,7 +36,7 @@ impl PerformCrud for DeletePrivateMessage {
     // Doing the update
     let private_message_id = data.private_message_id;
     let deleted = data.deleted;
-    let updated_private_message = PrivateMessage::update(
+    PrivateMessage::update(
       context.pool(),
       private_message_id,
       &PrivateMessageUpdateForm::builder()
@@ -47,15 +46,6 @@ impl PerformCrud for DeletePrivateMessage {
     .await
     .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
 
-    // Send the apub update
-    send_apub_delete_private_message(
-      &local_user_view.person.into(),
-      updated_private_message,
-      data.deleted,
-      context,
-    )
-    .await?;
-
     let op = UserOperationCrud::DeletePrivateMessage;
     send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
   }
index 88bb08300469f98c0b478a82be147ac798582f96..28680274524788fa15a1ee6636293fb529c105be 100644 (file)
@@ -1,9 +1,9 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   private_message::{GetPrivateMessages, PrivateMessagesResponse},
   utils::get_local_user_view_from_jwt,
-  LemmyContext,
 };
 use lemmy_db_schema::traits::DeleteableOrRemoveable;
 use lemmy_db_views::private_message_view::PrivateMessageQuery;
index b6e08c9c6bfaa1ebd69779fdd15928d5a8c57e71..f6f8c8f0374f01334a77dca4f8a16a475d6429bf 100644 (file)
@@ -1,14 +1,10 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   private_message::{EditPrivateMessage, PrivateMessageResponse},
   utils::{get_local_user_view_from_jwt, local_site_to_slur_regex},
   websocket::{send::send_pm_ws_message, UserOperationCrud},
-  LemmyContext,
-};
-use lemmy_apub::protocol::activities::{
-  create_or_update::chat_message::CreateOrUpdateChatMessage,
-  CreateOrUpdateType,
 };
 use lemmy_db_schema::{
   source::{
@@ -45,7 +41,7 @@ impl PerformCrud for EditPrivateMessage {
     // Doing the update
     let content_slurs_removed = remove_slurs(&data.content, &local_site_to_slur_regex(&local_site));
     let private_message_id = data.private_message_id;
-    let updated_private_message = PrivateMessage::update(
+    PrivateMessage::update(
       context.pool(),
       private_message_id,
       &PrivateMessageUpdateForm::builder()
@@ -56,15 +52,6 @@ impl PerformCrud for EditPrivateMessage {
     .await
     .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
 
-    // Send the apub update
-    CreateOrUpdateChatMessage::send(
-      updated_private_message.into(),
-      &local_user_view.person.into(),
-      CreateOrUpdateType::Update,
-      context,
-    )
-    .await?;
-
     let op = UserOperationCrud::EditPrivateMessage;
     send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
   }
index 34ac404a946e6aee9d94a664eaf1ce9302bf6f7a..d04343b0c2e145814147fa7d8c5d93c93b7028e2 100644 (file)
@@ -2,16 +2,16 @@ use crate::PerformCrud;
 use activitypub_federation::core::signatures::generate_actor_keypair;
 use actix_web::web::Data;
 use lemmy_api_common::{
-  generate_site_inbox_url,
+  context::LemmyContext,
   site::{CreateSite, SiteResponse},
   utils::{
+    generate_site_inbox_url,
     get_local_user_view_from_jwt,
     is_admin,
     local_site_rate_limit_to_rate_limit_config,
     local_site_to_slur_regex,
     site_description_length_check,
   },
-  LemmyContext,
 };
 use lemmy_db_schema::{
   newtypes::DbUrl,
index 8f27bb2ee51ed35c07de301eeb9613d08a70065d..55dcd8fb2d915d5d1cd565f110bcb725212732b5 100644 (file)
@@ -1,10 +1,10 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{GetSite, GetSiteResponse, MyUserInfo},
   utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
   websocket::messages::GetUsersOnline,
-  LemmyContext,
 };
 use lemmy_db_schema::source::{actor_language::SiteLanguage, language::Language, tagline::Tagline};
 use lemmy_db_views::structs::{LocalUserDiscussionLanguageView, SiteView};
index e738a2513616e337a77db9022375d5589a3177f8..4a96925edbb8b4719302451dbc54a3304d258ac9 100644 (file)
@@ -1,6 +1,7 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{EditSite, SiteResponse},
   utils::{
     get_local_user_view_from_jwt,
@@ -10,7 +11,6 @@ use lemmy_api_common::{
     site_description_length_check,
   },
   websocket::{messages::SendAllMessage, UserOperationCrud},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index 0521ffe0ced7274627e1b454f2d351a8cfc3010b..34b3b69e47004d154d9018662d570314879a51d4 100644 (file)
@@ -2,20 +2,20 @@ use crate::PerformCrud;
 use activitypub_federation::core::signatures::generate_actor_keypair;
 use actix_web::web::Data;
 use lemmy_api_common::{
-  generate_inbox_url,
-  generate_local_apub_endpoint,
-  generate_shared_inbox_url,
+  context::LemmyContext,
   person::{LoginResponse, Register},
   utils::{
+    generate_inbox_url,
+    generate_local_apub_endpoint,
+    generate_shared_inbox_url,
     honeypot_check,
     local_site_to_slur_regex,
     password_length_check,
     send_new_applicant_email_to_admins,
     send_verification_email,
+    EndpointType,
   },
   websocket::messages::CheckCaptcha,
-  EndpointType,
-  LemmyContext,
 };
 use lemmy_db_schema::{
   aggregates::structs::PersonAggregates,
index 87ad78e44323234ed75c77f9d5ddd4bb0d22e88e..b49695eaca5c02265a818225417b9617a2d9df78 100644 (file)
@@ -2,11 +2,10 @@ use crate::PerformCrud;
 use actix_web::web::Data;
 use bcrypt::verify;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{DeleteAccount, DeleteAccountResponse},
-  utils::{delete_user_account, get_local_user_view_from_jwt},
-  LemmyContext,
+  utils::get_local_user_view_from_jwt,
 };
-use lemmy_apub::protocol::activities::deletion::delete_user::DeleteUser;
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
 #[async_trait::async_trait(?Send)]
@@ -33,15 +32,6 @@ impl PerformCrud for DeleteAccount {
       return Err(LemmyError::from_message("password_incorrect"));
     }
 
-    delete_user_account(
-      local_user_view.person.id,
-      context.pool(),
-      context.settings(),
-      context.client(),
-    )
-    .await?;
-    DeleteUser::send(&local_user_view.person.into(), context).await?;
-
     Ok(DeleteAccountResponse {})
   }
 }
index 84307241104e745d234d78c7f4eba2bbe06a8c96..aeaae9dddf07d14eaa062ebec4aa968771e6c342 100644 (file)
@@ -1,3 +1,2 @@
 mod create;
 mod delete;
-mod read;
index c77bfde35c2221daa779df0289c3c6757e25d9e1..b5f03eaf1f3ce498f85df4ffe577d003d211e225 100644 (file)
@@ -24,8 +24,8 @@ use activitystreams_kinds::{activity::BlockType, public};
 use anyhow::anyhow;
 use chrono::NaiveDateTime;
 use lemmy_api_common::{
+  context::LemmyContext,
   utils::{remove_user_data, remove_user_data_in_community},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index 5a8c48f13678b369f8c8ca4738c89f0894064f5d..8adc2501297ce5844dfcb7532425e4db19c5ad09 100644 (file)
@@ -1,13 +1,27 @@
 use crate::{
-  objects::{community::ApubCommunity, instance::ApubSite},
-  protocol::objects::{group::Group, instance::Instance},
+  objects::{community::ApubCommunity, instance::ApubSite, person::ApubPerson},
+  protocol::{
+    activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
+    objects::{group::Group, instance::Instance},
+  },
   ActorType,
+  SendActivity,
 };
 use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject};
 use chrono::NaiveDateTime;
-use lemmy_api_common::LemmyContext;
-use lemmy_db_schema::{source::site::Site, utils::DbPool};
-use lemmy_utils::error::LemmyError;
+use lemmy_api_common::{
+  community::{BanFromCommunity, BanFromCommunityResponse},
+  context::LemmyContext,
+  person::{BanPerson, BanPersonResponse},
+  utils::get_local_user_view_from_jwt,
+};
+use lemmy_db_schema::{
+  source::{community::Community, person::Person, site::Site},
+  traits::Crud,
+  utils::DbPool,
+};
+use lemmy_db_views::structs::SiteView;
+use lemmy_utils::{error::LemmyError, utils::naive_from_unix};
 use serde::Deserialize;
 use url::Url;
 
@@ -123,3 +137,90 @@ async fn generate_cc(target: &SiteOrCommunity, pool: &DbPool) -> Result<Vec<Url>
     SiteOrCommunity::Community(c) => vec![c.actor_id()],
   })
 }
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for BanPerson {
+  type Response = BanPersonResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let person = Person::read(context.pool(), request.person_id).await?;
+    let site = SiteOrCommunity::Site(SiteView::read_local(context.pool()).await?.site.into());
+    let expires = request.expires.map(naive_from_unix);
+
+    // if the action affects a local user, federate to other instances
+    if person.local {
+      if request.ban {
+        BlockUser::send(
+          &site,
+          &person.into(),
+          &local_user_view.person.into(),
+          request.remove_data.unwrap_or(false),
+          request.reason.clone(),
+          expires,
+          context,
+        )
+        .await
+      } else {
+        UndoBlockUser::send(
+          &site,
+          &person.into(),
+          &local_user_view.person.into(),
+          request.reason.clone(),
+          context,
+        )
+        .await
+      }
+    } else {
+      Ok(())
+    }
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for BanFromCommunity {
+  type Response = BanFromCommunityResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let community: ApubCommunity = Community::read(context.pool(), request.community_id)
+      .await?
+      .into();
+    let banned_person: ApubPerson = Person::read(context.pool(), request.person_id)
+      .await?
+      .into();
+    let expires = request.expires.map(naive_from_unix);
+
+    if request.ban {
+      BlockUser::send(
+        &SiteOrCommunity::Community(community),
+        &banned_person,
+        &local_user_view.person.clone().into(),
+        request.remove_data.unwrap_or(false),
+        request.reason.clone(),
+        expires,
+        context,
+      )
+      .await
+    } else {
+      UndoBlockUser::send(
+        &SiteOrCommunity::Community(community),
+        &banned_person,
+        &local_user_view.person.clone().into(),
+        request.reason.clone(),
+        context,
+      )
+      .await
+    }
+  }
+}
index 56f794dc18e5e97741efaa3da3c8b0b98ff8cb46..315667ac6c565738c3d254ff6996b89e738c5992 100644 (file)
@@ -19,7 +19,7 @@ use activitypub_federation::{
   utils::verify_domains_match,
 };
 use activitystreams_kinds::{activity::UndoType, public};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{
     community::{CommunityPersonBan, CommunityPersonBanForm},
index 3718ea680edd28a0d3edb43ec1f9f9c2cea71847..1bc31b48cbfd3bb5935e990acf93fdbe6e9de34a 100644 (file)
@@ -10,8 +10,12 @@ use crate::{
   activity_lists::AnnouncableActivities,
   local_instance,
   objects::{community::ApubCommunity, person::ApubPerson},
-  protocol::{activities::community::add_mod::AddMod, InCommunity},
+  protocol::{
+    activities::community::{add_mod::AddMod, remove_mod::RemoveMod},
+    InCommunity,
+  },
   ActorType,
+  SendActivity,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -19,11 +23,16 @@ use activitypub_federation::{
   traits::{ActivityHandler, Actor},
 };
 use activitystreams_kinds::{activity::AddType, public};
-use lemmy_api_common::{generate_moderators_url, LemmyContext};
+use lemmy_api_common::{
+  community::{AddModToCommunity, AddModToCommunityResponse},
+  context::LemmyContext,
+  utils::{generate_moderators_url, get_local_user_view_from_jwt},
+};
 use lemmy_db_schema::{
   source::{
-    community::{CommunityModerator, CommunityModeratorForm},
+    community::{Community, CommunityModerator, CommunityModeratorForm},
     moderator::{ModAddCommunity, ModAddCommunityForm},
+    person::Person,
   },
   traits::{Crud, Joinable},
 };
@@ -134,3 +143,40 @@ impl ActivityHandler for AddMod {
     Ok(())
   }
 }
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for AddModToCommunity {
+  type Response = AddModToCommunityResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let community: ApubCommunity = Community::read(context.pool(), request.community_id)
+      .await?
+      .into();
+    let updated_mod: ApubPerson = Person::read(context.pool(), request.person_id)
+      .await?
+      .into();
+    if request.added {
+      AddMod::send(
+        &community,
+        &updated_mod,
+        &local_user_view.person.into(),
+        context,
+      )
+      .await
+    } else {
+      RemoveMod::send(
+        &community,
+        &updated_mod,
+        &local_user_view.person.into(),
+        context,
+      )
+      .await
+    }
+  }
+}
index 1ca1aa848888d67fcfcdbf1c7a27fb2f8200909a..306913aa6682c0864d8263b00fea57ab598ba98a 100644 (file)
@@ -18,7 +18,7 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
 use activitystreams_kinds::{activity::AnnounceType, public};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde_json::Value;
 use tracing::debug;
index 3d0bb4c3dd51abfd6a46d4e2a0f55c93bf54e9e1..4d35c9d56a29efd9f99e3df685c919ed95c7d56f 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
   protocol::activities::community::announce::AnnounceActivity,
 };
 use activitypub_federation::{core::object_id::ObjectId, traits::Actor};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::source::person::PersonFollower;
 use lemmy_utils::error::LemmyError;
 use url::Url;
index 855fe7b4ed22899c01fdface6e0b01302f174577..9bd8c4ec2b152efc5adb07cc0472a10455df2346 100644 (file)
@@ -19,7 +19,7 @@ use activitypub_federation::{
   traits::{ActivityHandler, Actor},
 };
 use activitystreams_kinds::{activity::RemoveType, public};
-use lemmy_api_common::{generate_moderators_url, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::generate_moderators_url};
 use lemmy_db_schema::{
   source::{
     community::{CommunityModerator, CommunityModeratorForm},
index 2741af7e8290acd96208d71355b5cb1486c9450d..57b1244d106803500c8e46079c26bda412a2bd51 100644 (file)
@@ -5,6 +5,7 @@ use crate::{
   protocol::{activities::community::report::Report, InCommunity},
   ActorType,
   PostOrComment,
+  SendActivity,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -13,10 +14,11 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::activity::FlagType;
 use lemmy_api_common::{
-  comment::CommentReportResponse,
-  post::PostReportResponse,
+  comment::{CommentReportResponse, CreateCommentReport},
+  context::LemmyContext,
+  post::{CreatePostReport, PostReportResponse},
+  utils::get_local_user_view_from_jwt,
   websocket::{messages::SendModRoomMessage, UserOperation},
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
@@ -29,9 +31,53 @@ use lemmy_db_views::structs::{CommentReportView, PostReportView};
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
+#[async_trait::async_trait(?Send)]
+impl SendActivity for CreatePostReport {
+  type Response = PostReportResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    Report::send(
+      ObjectId::new(response.post_report_view.post.ap_id.clone()),
+      &local_user_view.person.into(),
+      ObjectId::new(response.post_report_view.community.actor_id.clone()),
+      request.reason.to_string(),
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for CreateCommentReport {
+  type Response = CommentReportResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    Report::send(
+      ObjectId::new(response.comment_report_view.comment.ap_id.clone()),
+      &local_user_view.person.into(),
+      ObjectId::new(response.comment_report_view.community.actor_id.clone()),
+      request.reason.to_string(),
+      context,
+    )
+    .await
+  }
+}
+
 impl Report {
   #[tracing::instrument(skip_all)]
-  pub async fn send(
+  async fn send(
     object_id: ObjectId<PostOrComment>,
     actor: &ApubPerson,
     community_id: ObjectId<ApubCommunity>,
index c0d1a2799432fd6529ac012b4e4b3808bd85a6f5..969741ef66f97f686ee88f41450296c2e923f1e6 100644 (file)
@@ -10,6 +10,7 @@ use crate::{
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::{activities::community::update::UpdateCommunity, InCommunity},
   ActorType,
+  SendActivity,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -18,13 +19,31 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::{activity::UpdateType, public};
 use lemmy_api_common::{
+  community::{CommunityResponse, EditCommunity, HideCommunity},
+  context::LemmyContext,
+  utils::get_local_user_view_from_jwt,
   websocket::{send::send_community_ws_message, UserOperationCrud},
-  LemmyContext,
 };
 use lemmy_db_schema::{source::community::Community, traits::Crud};
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
+#[async_trait::async_trait(?Send)]
+impl SendActivity for EditCommunity {
+  type Response = CommunityResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let community = Community::read(context.pool(), request.community_id).await?;
+    UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
+  }
+}
+
 impl UpdateCommunity {
   #[tracing::instrument(skip_all)]
   pub async fn send(
@@ -115,3 +134,19 @@ impl ActivityHandler for UpdateCommunity {
     Ok(())
   }
 }
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for HideCommunity {
+  type Response = CommunityResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let community = Community::read(context.pool(), request.community_id).await?;
+    UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
+  }
+}
index 5def04604bfd9f23def0f2c0afc1fe86cf36887e..54df09ce616c4d49ebe5f328138cc09e077494ab 100644 (file)
@@ -16,6 +16,7 @@ use crate::{
     InCommunity,
   },
   ActorType,
+  SendActivity,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -25,14 +26,17 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::public;
 use lemmy_api_common::{
+  comment::{CommentResponse, CreateComment, EditComment},
+  context::LemmyContext,
   utils::check_post_deleted_or_removed,
   websocket::{send::send_comment_ws_message, UserOperationCrud},
-  LemmyContext,
 };
 use lemmy_db_schema::{
+  newtypes::PersonId,
   source::{
-    comment::{CommentLike, CommentLikeForm},
+    comment::{Comment, CommentLike, CommentLikeForm},
     community::Community,
+    person::Person,
     post::Post,
   },
   traits::{Crud, Likeable},
@@ -40,29 +44,67 @@ use lemmy_db_schema::{
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
+#[async_trait::async_trait(?Send)]
+impl SendActivity for CreateComment {
+  type Response = CommentResponse;
+
+  async fn send_activity(
+    _request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    CreateOrUpdateNote::send(
+      &response.comment_view.comment,
+      response.comment_view.creator.id,
+      CreateOrUpdateType::Create,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for EditComment {
+  type Response = CommentResponse;
+
+  async fn send_activity(
+    _request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    CreateOrUpdateNote::send(
+      &response.comment_view.comment,
+      response.comment_view.creator.id,
+      CreateOrUpdateType::Update,
+      context,
+    )
+    .await
+  }
+}
+
 impl CreateOrUpdateNote {
-  #[tracing::instrument(skip(comment, actor, kind, context))]
-  pub async fn send(
-    comment: ApubComment,
-    actor: &ApubPerson,
+  #[tracing::instrument(skip(comment, person_id, kind, context))]
+  async fn send(
+    comment: &Comment,
+    person_id: PersonId,
     kind: CreateOrUpdateType,
     context: &LemmyContext,
-    request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
     // TODO: might be helpful to add a comment method to retrieve community directly
     let post_id = comment.post_id;
     let post = Post::read(context.pool(), post_id).await?;
     let community_id = post.community_id;
+    let person: ApubPerson = Person::read(context.pool(), person_id).await?.into();
     let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
 
     let id = generate_activity_id(
       kind.clone(),
       &context.settings().get_protocol_and_hostname(),
     )?;
-    let note = comment.into_apub(context).await?;
+    let note = ApubComment(comment.clone()).into_apub(context).await?;
 
     let create_or_update = CreateOrUpdateNote {
-      actor: ObjectId::new(actor.actor_id()),
+      actor: ObjectId::new(person.actor_id()),
       to: vec![public()],
       cc: note.cc.clone(),
       tag: note.tag.clone(),
@@ -88,13 +130,13 @@ impl CreateOrUpdateNote {
     let mut inboxes = vec![];
     for t in tagged_users {
       let person = t
-        .dereference(context, local_instance(context).await, request_counter)
+        .dereference(context, local_instance(context).await, &mut 0)
         .await?;
       inboxes.push(person.shared_inbox_or_inbox());
     }
 
     let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
-    send_activity_in_community(activity, actor, &community, inboxes, false, context).await
+    send_activity_in_community(activity, &person, &community, inboxes, false, context).await
   }
 }
 
index b53dd2eb847b51ac8c2fb46adcd511e5f849c33d..60ce6ea34b05bd28bf63ae2006938134d094db0c 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{local_instance, objects::person::ApubPerson};
 use activitypub_federation::core::object_id::ObjectId;
-use lemmy_api_common::{websocket::send::send_local_notifs, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, websocket::send::send_local_notifs};
 use lemmy_db_schema::{
   newtypes::LocalUserId,
   source::{comment::Comment, post::Post},
index 161b26b9dadc08aef16554ebbbfb11c3926016cd..92cc708774442b536332f468c71217c7eb67bdf3 100644 (file)
@@ -14,6 +14,7 @@ use crate::{
     InCommunity,
   },
   ActorType,
+  SendActivity,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -23,19 +24,103 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::public;
 use lemmy_api_common::{
+  context::LemmyContext,
+  post::{CreatePost, EditPost, LockPost, PostResponse, StickyPost},
+  utils::get_local_user_view_from_jwt,
   websocket::{send::send_post_ws_message, UserOperationCrud},
-  LemmyContext,
 };
 use lemmy_db_schema::{
+  newtypes::PersonId,
   source::{
     community::Community,
-    post::{PostLike, PostLikeForm},
+    person::Person,
+    post::{Post, PostLike, PostLikeForm},
   },
   traits::{Crud, Likeable},
 };
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
+#[async_trait::async_trait(?Send)]
+impl SendActivity for CreatePost {
+  type Response = PostResponse;
+
+  async fn send_activity(
+    _request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    CreateOrUpdatePage::send(
+      &response.post_view.post,
+      response.post_view.creator.id,
+      CreateOrUpdateType::Create,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for EditPost {
+  type Response = PostResponse;
+
+  async fn send_activity(
+    _request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    CreateOrUpdatePage::send(
+      &response.post_view.post,
+      response.post_view.creator.id,
+      CreateOrUpdateType::Update,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for LockPost {
+  type Response = PostResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    CreateOrUpdatePage::send(
+      &response.post_view.post,
+      local_user_view.person.id,
+      CreateOrUpdateType::Update,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for StickyPost {
+  type Response = PostResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    CreateOrUpdatePage::send(
+      &response.post_view.post,
+      local_user_view.person.id,
+      CreateOrUpdateType::Update,
+      context,
+    )
+    .await
+  }
+}
+
 impl CreateOrUpdatePage {
   pub(crate) async fn new(
     post: ApubPost,
@@ -60,19 +145,30 @@ impl CreateOrUpdatePage {
   }
 
   #[tracing::instrument(skip_all)]
-  pub async fn send(
-    post: ApubPost,
-    actor: &ApubPerson,
+  async fn send(
+    post: &Post,
+    person_id: PersonId,
     kind: CreateOrUpdateType,
     context: &LemmyContext,
   ) -> Result<(), LemmyError> {
+    let post = ApubPost(post.clone());
     let community_id = post.community_id;
+    let person: ApubPerson = Person::read(context.pool(), person_id).await?.into();
     let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
 
-    let create_or_update = CreateOrUpdatePage::new(post, actor, &community, kind, context).await?;
+    let create_or_update =
+      CreateOrUpdatePage::new(post, &person, &community, kind, context).await?;
     let is_mod_action = create_or_update.object.is_mod_action(context).await?;
     let activity = AnnouncableActivities::CreateOrUpdatePost(create_or_update);
-    send_activity_in_community(activity, actor, &community, vec![], is_mod_action, context).await?;
+    send_activity_in_community(
+      activity,
+      &person,
+      &community,
+      vec![],
+      is_mod_action,
+      context,
+    )
+    .await?;
     Ok(())
   }
 }
index 431e699cecd402fb7d2ddb3cb086f3bfa2508972..071209c349bf1d5235ed6457590d3893fcb7b5f5 100644 (file)
@@ -6,6 +6,7 @@ use crate::{
     CreateOrUpdateType,
   },
   ActorType,
+  SendActivity,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -14,22 +15,65 @@ use activitypub_federation::{
   utils::verify_domains_match,
 };
 use lemmy_api_common::{
+  context::LemmyContext,
+  private_message::{CreatePrivateMessage, EditPrivateMessage, PrivateMessageResponse},
   websocket::{send::send_pm_ws_message, UserOperationCrud},
-  LemmyContext,
 };
-use lemmy_db_schema::{source::person::Person, traits::Crud};
+use lemmy_db_schema::{
+  newtypes::PersonId,
+  source::{person::Person, private_message::PrivateMessage},
+  traits::Crud,
+};
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
+#[async_trait::async_trait(?Send)]
+impl SendActivity for CreatePrivateMessage {
+  type Response = PrivateMessageResponse;
+
+  async fn send_activity(
+    _request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    CreateOrUpdateChatMessage::send(
+      &response.private_message_view.private_message,
+      response.private_message_view.creator.id,
+      CreateOrUpdateType::Create,
+      context,
+    )
+    .await
+  }
+}
+#[async_trait::async_trait(?Send)]
+impl SendActivity for EditPrivateMessage {
+  type Response = PrivateMessageResponse;
+
+  async fn send_activity(
+    _request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    CreateOrUpdateChatMessage::send(
+      &response.private_message_view.private_message,
+      response.private_message_view.creator.id,
+      CreateOrUpdateType::Update,
+      context,
+    )
+    .await
+  }
+}
+
 impl CreateOrUpdateChatMessage {
   #[tracing::instrument(skip_all)]
-  pub async fn send(
-    private_message: ApubPrivateMessage,
-    actor: &ApubPerson,
+  async fn send(
+    private_message: &PrivateMessage,
+    sender_id: PersonId,
     kind: CreateOrUpdateType,
     context: &LemmyContext,
   ) -> Result<(), LemmyError> {
     let recipient_id = private_message.recipient_id;
+    let sender: ApubPerson = Person::read(context.pool(), sender_id).await?.into();
     let recipient: ApubPerson = Person::read(context.pool(), recipient_id).await?.into();
 
     let id = generate_activity_id(
@@ -38,13 +82,15 @@ impl CreateOrUpdateChatMessage {
     )?;
     let create_or_update = CreateOrUpdateChatMessage {
       id: id.clone(),
-      actor: ObjectId::new(actor.actor_id()),
+      actor: ObjectId::new(sender.actor_id()),
       to: [ObjectId::new(recipient.actor_id())],
-      object: private_message.into_apub(context).await?,
+      object: ApubPrivateMessage(private_message.clone())
+        .into_apub(context)
+        .await?,
       kind,
     };
     let inbox = vec![recipient.shared_inbox_or_inbox()];
-    send_lemmy_activity(context, create_or_update, actor, inbox, true).await
+    send_lemmy_activity(context, create_or_update, &sender, inbox, true).await
   }
 }
 
index ae93d6e09604228091d9594658d0d2f8786498bb..138a1fae1788bb454eb93792fc8050beb31c3283 100644 (file)
@@ -10,11 +10,11 @@ use crate::{
 use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
 use activitystreams_kinds::activity::DeleteType;
 use lemmy_api_common::{
+  context::LemmyContext,
   websocket::{
     send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
     UserOperationCrud,
   },
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index ffe664d59985ed642a82e33f78ee9040ef074d85..4ace431e67f7d8f7679591fcfc1a1c60bb16d4ff 100644 (file)
@@ -3,6 +3,7 @@ use crate::{
   local_instance,
   objects::{instance::remote_instance_inboxes, person::ApubPerson},
   protocol::activities::deletion::delete_user::DeleteUser,
+  SendActivity,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -11,10 +12,54 @@ use activitypub_federation::{
   utils::verify_urls_match,
 };
 use activitystreams_kinds::{activity::DeleteType, public};
-use lemmy_api_common::{utils::delete_user_account, LemmyContext};
+use lemmy_api_common::{
+  context::LemmyContext,
+  person::{DeleteAccount, DeleteAccountResponse},
+  utils::{delete_user_account, get_local_user_view_from_jwt},
+};
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
+#[async_trait::async_trait(?Send)]
+impl SendActivity for DeleteAccount {
+  type Response = DeleteAccountResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let actor: ApubPerson = local_user_view.person.into();
+    delete_user_account(
+      actor.id,
+      context.pool(),
+      context.settings(),
+      context.client(),
+    )
+    .await?;
+
+    let actor_id = ObjectId::new(actor.actor_id.clone());
+    let id = generate_activity_id(
+      DeleteType::Delete,
+      &context.settings().get_protocol_and_hostname(),
+    )?;
+    let delete = DeleteUser {
+      actor: actor_id.clone(),
+      to: vec![public()],
+      object: actor_id,
+      kind: DeleteType::Delete,
+      id: id.clone(),
+      cc: vec![],
+    };
+
+    let inboxes = remote_instance_inboxes(context.pool()).await?;
+    send_lemmy_activity(context, delete, &actor, inboxes, true).await?;
+    Ok(())
+  }
+}
+
 /// This can be separate from Delete activity because it doesn't need to be handled in shared inbox
 /// (cause instance actor doesn't have shared inbox).
 #[async_trait::async_trait(?Send)]
@@ -60,26 +105,3 @@ impl ActivityHandler for DeleteUser {
     Ok(())
   }
 }
-
-impl DeleteUser {
-  #[tracing::instrument(skip_all)]
-  pub async fn send(actor: &ApubPerson, context: &LemmyContext) -> Result<(), LemmyError> {
-    let actor_id = ObjectId::new(actor.actor_id.clone());
-    let id = generate_activity_id(
-      DeleteType::Delete,
-      &context.settings().get_protocol_and_hostname(),
-    )?;
-    let delete = DeleteUser {
-      actor: actor_id.clone(),
-      to: vec![public()],
-      object: actor_id,
-      kind: DeleteType::Delete,
-      id: id.clone(),
-      cc: vec![],
-    };
-
-    let inboxes = remote_instance_inboxes(context.pool()).await?;
-    send_lemmy_activity(context, delete, actor, inboxes, true).await?;
-    Ok(())
-  }
-}
index d05e450219ae277f4b3db20de6d14171f03675e7..dae70dc3d5aa01752c742b16df442ebf41ac21b7 100644 (file)
@@ -21,6 +21,7 @@ use crate::{
     InCommunity,
   },
   ActorType,
+  SendActivity,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -29,6 +30,12 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::public;
 use lemmy_api_common::{
+  comment::{CommentResponse, DeleteComment, RemoveComment},
+  community::{CommunityResponse, DeleteCommunity, RemoveCommunity},
+  context::LemmyContext,
+  post::{DeletePost, PostResponse, RemovePost},
+  private_message::{DeletePrivateMessage, PrivateMessageResponse},
+  utils::get_local_user_view_from_jwt,
   websocket::{
     send::{
       send_comment_ws_message_simple,
@@ -38,7 +45,6 @@ use lemmy_api_common::{
     },
     UserOperationCrud,
   },
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
@@ -58,10 +64,176 @@ pub mod delete;
 pub mod delete_user;
 pub mod undo_delete;
 
+#[async_trait::async_trait(?Send)]
+impl SendActivity for DeletePost {
+  type Response = PostResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let community = Community::read(context.pool(), response.post_view.community.id).await?;
+    let deletable = DeletableObjects::Post(Box::new(response.post_view.post.clone().into()));
+    send_apub_delete_in_community(
+      local_user_view.person,
+      community,
+      deletable,
+      None,
+      request.deleted,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for RemovePost {
+  type Response = PostResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let community = Community::read(context.pool(), response.post_view.community.id).await?;
+    let deletable = DeletableObjects::Post(Box::new(response.post_view.post.clone().into()));
+    send_apub_delete_in_community(
+      local_user_view.person,
+      community,
+      deletable,
+      request.reason.clone().or_else(|| Some(String::new())),
+      request.removed,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for DeleteComment {
+  type Response = CommentResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let community_id = response.comment_view.community.id;
+    let community = Community::read(context.pool(), community_id).await?;
+    let person = Person::read(context.pool(), response.comment_view.creator.id).await?;
+    let deletable =
+      DeletableObjects::Comment(Box::new(response.comment_view.comment.clone().into()));
+    send_apub_delete_in_community(person, community, deletable, None, request.deleted, context)
+      .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for RemoveComment {
+  type Response = CommentResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let comment = Comment::read(context.pool(), request.comment_id).await?;
+    let community = Community::read(context.pool(), response.comment_view.community.id).await?;
+    let deletable = DeletableObjects::Comment(Box::new(comment.into()));
+    send_apub_delete_in_community(
+      local_user_view.person,
+      community,
+      deletable,
+      request.reason.clone().or_else(|| Some(String::new())),
+      request.removed,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for DeletePrivateMessage {
+  type Response = PrivateMessageResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    send_apub_delete_private_message(
+      &local_user_view.person.into(),
+      response.private_message_view.private_message.clone(),
+      request.deleted,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for DeleteCommunity {
+  type Response = CommunityResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let community = Community::read(context.pool(), request.community_id).await?;
+    let deletable = DeletableObjects::Community(Box::new(community.clone().into()));
+    send_apub_delete_in_community(
+      local_user_view.person,
+      community,
+      deletable,
+      None,
+      request.deleted,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for RemoveCommunity {
+  type Response = CommunityResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let community = Community::read(context.pool(), request.community_id).await?;
+    let deletable = DeletableObjects::Community(Box::new(community.clone().into()));
+    send_apub_delete_in_community(
+      local_user_view.person,
+      community,
+      deletable,
+      request.reason.clone().or_else(|| Some(String::new())),
+      request.removed,
+      context,
+    )
+    .await
+  }
+}
+
 /// Parameter `reason` being set indicates that this is a removal by a mod. If its unset, this
 /// action was done by a normal user.
 #[tracing::instrument(skip_all)]
-pub async fn send_apub_delete_in_community(
+async fn send_apub_delete_in_community(
   actor: Person,
   community: Community,
   object: DeletableObjects,
@@ -90,7 +262,7 @@ pub async fn send_apub_delete_in_community(
 }
 
 #[tracing::instrument(skip_all)]
-pub async fn send_apub_delete_private_message(
+async fn send_apub_delete_private_message(
   actor: &ApubPerson,
   pm: PrivateMessage,
   deleted: bool,
index bc6f9fd14c22ae2e0f0e9a2eeaabd5ac07029e5c..b3cef38580f72c2d3e82ad0e4abf2902ec0d96eb 100644 (file)
@@ -10,11 +10,11 @@ use crate::{
 use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
 use activitystreams_kinds::activity::UndoType;
 use lemmy_api_common::{
+  context::LemmyContext,
   websocket::{
     send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
     UserOperationCrud,
   },
-  LemmyContext,
 };
 use lemmy_db_schema::{
   source::{
index 880db0d99144c9e61c09ea46fe39f2f8d9ca0fbd..6702c8c9590c3893d56a08c12c1b5b552b95e860 100644 (file)
@@ -13,8 +13,8 @@ use activitypub_federation::{
 use activitystreams_kinds::activity::AcceptType;
 use lemmy_api_common::{
   community::CommunityResponse,
+  context::LemmyContext,
   websocket::{messages::SendUserRoomMessage, UserOperation},
-  LemmyContext,
 };
 use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
 use lemmy_db_views::structs::LocalUserView;
index 82c0c37a5942b1a244f7153720b11a47b9cf84fb..62bd24157f4c6e92aed9b684b3b458ed00b9025c 100644 (file)
@@ -8,8 +8,13 @@ use crate::{
   fetcher::user_or_community::UserOrCommunity,
   local_instance,
   objects::{community::ApubCommunity, person::ApubPerson},
-  protocol::activities::following::{accept::AcceptFollow, follow::Follow},
+  protocol::activities::following::{
+    accept::AcceptFollow,
+    follow::Follow,
+    undo_follow::UndoFollow,
+  },
   ActorType,
+  SendActivity,
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -17,13 +22,17 @@ use activitypub_federation::{
   traits::{ActivityHandler, Actor},
 };
 use activitystreams_kinds::activity::FollowType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::{
+  community::{BlockCommunity, BlockCommunityResponse},
+  context::LemmyContext,
+  utils::get_local_user_view_from_jwt,
+};
 use lemmy_db_schema::{
   source::{
-    community::{CommunityFollower, CommunityFollowerForm},
+    community::{Community, CommunityFollower, CommunityFollowerForm},
     person::{PersonFollower, PersonFollowerForm},
   },
-  traits::Followable,
+  traits::{Crud, Followable},
 };
 use lemmy_utils::error::LemmyError;
 use url::Url;
@@ -132,3 +141,19 @@ impl ActivityHandler for Follow {
     AcceptFollow::send(self, context, request_counter).await
   }
 }
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for BlockCommunity {
+  type Response = BlockCommunityResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let community = Community::read(context.pool(), request.community_id).await?;
+    UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await
+  }
+}
index 60bdd5f785c5ec3c5b6874d0401fa30c51785e53..e472dc73a1dd3e9f1339717208c1915cf23270e1 100644 (file)
@@ -1,3 +1,41 @@
+use crate::{
+  objects::community::ApubCommunity,
+  protocol::activities::following::{follow::Follow, undo_follow::UndoFollow},
+  SendActivity,
+};
+use lemmy_api_common::{
+  community::{CommunityResponse, FollowCommunity},
+  context::LemmyContext,
+  utils::get_local_user_view_from_jwt,
+};
+use lemmy_db_schema::{source::community::Community, traits::Crud};
+use lemmy_utils::error::LemmyError;
+
 pub mod accept;
 pub mod follow;
 pub mod undo_follow;
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for FollowCommunity {
+  type Response = CommunityResponse;
+
+  async fn send_activity(
+    request: &Self,
+    _response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let local_user_view =
+      get_local_user_view_from_jwt(&request.auth, context.pool(), context.secret()).await?;
+    let person = local_user_view.person.clone().into();
+    let community: ApubCommunity = Community::read(context.pool(), request.community_id)
+      .await?
+      .into();
+    if community.local {
+      Ok(())
+    } else if request.follow {
+      Follow::send(&person, &community, context).await
+    } else {
+      UndoFollow::send(&person, &community, context).await
+    }
+  }
+}
index 7d48f9f3ce6612265ddd420d3f533c5b82b4814a..436d8a02e84711f7f5f162406bb8dde7e03a27d6 100644 (file)
@@ -13,7 +13,7 @@ use activitypub_federation::{
   utils::verify_urls_match,
 };
 use activitystreams_kinds::activity::UndoType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{
     community::{CommunityFollower, CommunityFollowerForm},
index 68a3b535c10bd16ddb5c9b6c7e1d5a2e4c4fcab2..2fb5808b7869af7a085536965846914e498ef190 100644 (file)
@@ -12,7 +12,7 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::public;
 use anyhow::anyhow;
-use lemmy_api_common::{generate_moderators_url, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::generate_moderators_url};
 use lemmy_db_schema::{
   newtypes::CommunityId,
   source::{community::Community, local_site::LocalSite},
@@ -30,6 +30,7 @@ pub mod community;
 pub mod create_or_update;
 pub mod deletion;
 pub mod following;
+pub mod unfederated;
 pub mod voting;
 
 /// Checks that the specified Url actually identifies a Person (by fetching it), and that the person
diff --git a/crates/apub/src/activities/unfederated.rs b/crates/apub/src/activities/unfederated.rs
new file mode 100644 (file)
index 0000000..cca3340
--- /dev/null
@@ -0,0 +1,351 @@
+use crate::SendActivity;
+use lemmy_api_common::{
+  comment::{
+    CommentReportResponse,
+    CommentResponse,
+    GetComment,
+    GetComments,
+    GetCommentsResponse,
+    ListCommentReports,
+    ListCommentReportsResponse,
+    ResolveCommentReport,
+    SaveComment,
+  },
+  community::{
+    CommunityResponse,
+    CreateCommunity,
+    GetCommunity,
+    GetCommunityResponse,
+    ListCommunities,
+    ListCommunitiesResponse,
+    TransferCommunity,
+  },
+  person::{
+    AddAdmin,
+    AddAdminResponse,
+    BannedPersonsResponse,
+    BlockPerson,
+    BlockPersonResponse,
+    ChangePassword,
+    CommentReplyResponse,
+    GetBannedPersons,
+    GetCaptcha,
+    GetCaptchaResponse,
+    GetPersonDetails,
+    GetPersonDetailsResponse,
+    GetPersonMentions,
+    GetPersonMentionsResponse,
+    GetReplies,
+    GetRepliesResponse,
+    GetReportCount,
+    GetReportCountResponse,
+    GetUnreadCount,
+    GetUnreadCountResponse,
+    Login,
+    LoginResponse,
+    MarkAllAsRead,
+    MarkCommentReplyAsRead,
+    MarkPersonMentionAsRead,
+    PasswordChangeAfterReset,
+    PasswordReset,
+    PasswordResetResponse,
+    PersonMentionResponse,
+    Register,
+    SaveUserSettings,
+    VerifyEmail,
+    VerifyEmailResponse,
+  },
+  post::{
+    GetPost,
+    GetPostResponse,
+    GetPosts,
+    GetPostsResponse,
+    GetSiteMetadata,
+    GetSiteMetadataResponse,
+    ListPostReports,
+    ListPostReportsResponse,
+    MarkPostAsRead,
+    PostReportResponse,
+    PostResponse,
+    ResolvePostReport,
+    SavePost,
+  },
+  private_message::{
+    CreatePrivateMessageReport,
+    GetPrivateMessages,
+    ListPrivateMessageReports,
+    ListPrivateMessageReportsResponse,
+    MarkPrivateMessageAsRead,
+    PrivateMessageReportResponse,
+    PrivateMessageResponse,
+    PrivateMessagesResponse,
+    ResolvePrivateMessageReport,
+  },
+  site::{
+    ApproveRegistrationApplication,
+    CreateSite,
+    EditSite,
+    GetModlog,
+    GetModlogResponse,
+    GetSite,
+    GetSiteResponse,
+    GetUnreadRegistrationApplicationCount,
+    GetUnreadRegistrationApplicationCountResponse,
+    LeaveAdmin,
+    ListRegistrationApplications,
+    ListRegistrationApplicationsResponse,
+    PurgeComment,
+    PurgeCommunity,
+    PurgeItemResponse,
+    PurgePerson,
+    PurgePost,
+    RegistrationApplicationResponse,
+    ResolveObject,
+    ResolveObjectResponse,
+    Search,
+    SearchResponse,
+    SiteResponse,
+  },
+  websocket::structs::{
+    CommunityJoin,
+    CommunityJoinResponse,
+    ModJoin,
+    ModJoinResponse,
+    PostJoin,
+    PostJoinResponse,
+    UserJoin,
+    UserJoinResponse,
+  },
+};
+
+impl SendActivity for Register {
+  type Response = LoginResponse;
+}
+
+impl SendActivity for GetPersonDetails {
+  type Response = GetPersonDetailsResponse;
+}
+
+impl SendActivity for GetPrivateMessages {
+  type Response = PrivateMessagesResponse;
+}
+
+impl SendActivity for CreateSite {
+  type Response = SiteResponse;
+}
+
+impl SendActivity for EditSite {
+  type Response = SiteResponse;
+}
+
+impl SendActivity for GetSite {
+  type Response = GetSiteResponse;
+}
+
+impl SendActivity for GetCommunity {
+  type Response = GetCommunityResponse;
+}
+
+impl SendActivity for ListCommunities {
+  type Response = ListCommunitiesResponse;
+}
+
+impl SendActivity for CreateCommunity {
+  type Response = CommunityResponse;
+}
+
+impl SendActivity for GetPost {
+  type Response = GetPostResponse;
+}
+
+impl SendActivity for GetPosts {
+  type Response = GetPostsResponse;
+}
+
+impl SendActivity for GetComment {
+  type Response = CommentResponse;
+}
+
+impl SendActivity for GetComments {
+  type Response = GetCommentsResponse;
+}
+
+impl SendActivity for Login {
+  type Response = LoginResponse;
+}
+
+impl SendActivity for GetCaptcha {
+  type Response = GetCaptchaResponse;
+}
+
+impl SendActivity for GetReplies {
+  type Response = GetRepliesResponse;
+}
+
+impl SendActivity for AddAdmin {
+  type Response = AddAdminResponse;
+}
+
+impl SendActivity for GetUnreadRegistrationApplicationCount {
+  type Response = GetUnreadRegistrationApplicationCountResponse;
+}
+
+impl SendActivity for ListRegistrationApplications {
+  type Response = ListRegistrationApplicationsResponse;
+}
+
+impl SendActivity for ApproveRegistrationApplication {
+  type Response = RegistrationApplicationResponse;
+}
+
+impl SendActivity for GetBannedPersons {
+  type Response = BannedPersonsResponse;
+}
+
+impl SendActivity for BlockPerson {
+  type Response = BlockPersonResponse;
+}
+
+impl SendActivity for GetPersonMentions {
+  type Response = GetPersonMentionsResponse;
+}
+
+impl SendActivity for MarkPersonMentionAsRead {
+  type Response = PersonMentionResponse;
+}
+
+impl SendActivity for MarkCommentReplyAsRead {
+  type Response = CommentReplyResponse;
+}
+
+impl SendActivity for MarkAllAsRead {
+  type Response = GetRepliesResponse;
+}
+
+impl SendActivity for PasswordReset {
+  type Response = PasswordResetResponse;
+}
+
+impl SendActivity for PasswordChangeAfterReset {
+  type Response = LoginResponse;
+}
+
+impl SendActivity for UserJoin {
+  type Response = UserJoinResponse;
+}
+
+impl SendActivity for PostJoin {
+  type Response = PostJoinResponse;
+}
+
+impl SendActivity for CommunityJoin {
+  type Response = CommunityJoinResponse;
+}
+
+impl SendActivity for ModJoin {
+  type Response = ModJoinResponse;
+}
+
+impl SendActivity for SaveUserSettings {
+  type Response = LoginResponse;
+}
+
+impl SendActivity for ChangePassword {
+  type Response = LoginResponse;
+}
+
+impl SendActivity for GetReportCount {
+  type Response = GetReportCountResponse;
+}
+
+impl SendActivity for GetUnreadCount {
+  type Response = GetUnreadCountResponse;
+}
+
+impl SendActivity for VerifyEmail {
+  type Response = VerifyEmailResponse;
+}
+
+impl SendActivity for MarkPrivateMessageAsRead {
+  type Response = PrivateMessageResponse;
+}
+
+impl SendActivity for CreatePrivateMessageReport {
+  type Response = PrivateMessageReportResponse;
+}
+
+impl SendActivity for ResolvePrivateMessageReport {
+  type Response = PrivateMessageReportResponse;
+}
+
+impl SendActivity for ListPrivateMessageReports {
+  type Response = ListPrivateMessageReportsResponse;
+}
+
+impl SendActivity for GetModlog {
+  type Response = GetModlogResponse;
+}
+
+impl SendActivity for PurgePerson {
+  type Response = PurgeItemResponse;
+}
+
+impl SendActivity for PurgeCommunity {
+  type Response = PurgeItemResponse;
+}
+
+impl SendActivity for PurgePost {
+  type Response = PurgeItemResponse;
+}
+
+impl SendActivity for PurgeComment {
+  type Response = PurgeItemResponse;
+}
+
+impl SendActivity for Search {
+  type Response = SearchResponse;
+}
+
+impl SendActivity for ResolveObject {
+  type Response = ResolveObjectResponse;
+}
+
+impl SendActivity for TransferCommunity {
+  type Response = GetCommunityResponse;
+}
+
+impl SendActivity for LeaveAdmin {
+  type Response = GetSiteResponse;
+}
+
+impl SendActivity for MarkPostAsRead {
+  type Response = PostResponse;
+}
+
+impl SendActivity for SavePost {
+  type Response = PostResponse;
+}
+
+impl SendActivity for ListPostReports {
+  type Response = ListPostReportsResponse;
+}
+
+impl SendActivity for ResolvePostReport {
+  type Response = PostReportResponse;
+}
+
+impl SendActivity for GetSiteMetadata {
+  type Response = GetSiteMetadataResponse;
+}
+
+impl SendActivity for SaveComment {
+  type Response = CommentResponse;
+}
+
+impl SendActivity for ListCommentReports {
+  type Response = ListCommentReportsResponse;
+}
+
+impl SendActivity for ResolveCommentReport {
+  type Response = CommentReportResponse;
+}
index a01dcb2ea3588e62d786ccbdb2f5f8e01d864e88..4471fbd920922cae848e80ded5b618c243c78a88 100644 (file)
 use crate::{
+  activities::community::send_activity_in_community,
+  activity_lists::AnnouncableActivities,
+  fetcher::post_or_comment::PostOrComment,
   objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
-  protocol::activities::voting::vote::VoteType,
+  protocol::activities::voting::{
+    undo_vote::UndoVote,
+    vote::{Vote, VoteType},
+  },
+  SendActivity,
 };
+use activitypub_federation::core::object_id::ObjectId;
 use lemmy_api_common::{
+  comment::{CommentResponse, CreateCommentLike},
+  context::LemmyContext,
+  post::{CreatePostLike, PostResponse},
+  sensitive::Sensitive,
+  utils::get_local_user_view_from_jwt,
   websocket::{
     send::{send_comment_ws_message_simple, send_post_ws_message},
     UserOperation,
   },
-  LemmyContext,
 };
 use lemmy_db_schema::{
+  newtypes::CommunityId,
   source::{
     comment::{CommentLike, CommentLikeForm},
+    community::Community,
+    person::Person,
     post::{PostLike, PostLikeForm},
   },
-  traits::Likeable,
+  traits::{Crud, Likeable},
 };
 use lemmy_utils::error::LemmyError;
 
 pub mod undo_vote;
 pub mod vote;
 
+#[async_trait::async_trait(?Send)]
+impl SendActivity for CreatePostLike {
+  type Response = PostResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let object_id = ObjectId::new(response.post_view.post.ap_id.clone());
+    let community_id = response.post_view.community.id;
+    send_activity(
+      object_id,
+      community_id,
+      request.score,
+      &request.auth,
+      context,
+    )
+    .await
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl SendActivity for CreateCommentLike {
+  type Response = CommentResponse;
+
+  async fn send_activity(
+    request: &Self,
+    response: &Self::Response,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    let object_id = ObjectId::new(response.comment_view.comment.ap_id.clone());
+    let community_id = response.comment_view.community.id;
+    send_activity(
+      object_id,
+      community_id,
+      request.score,
+      &request.auth,
+      context,
+    )
+    .await
+  }
+}
+
+async fn send_activity(
+  object_id: ObjectId<PostOrComment>,
+  community_id: CommunityId,
+  score: i16,
+  jwt: &Sensitive<String>,
+  context: &LemmyContext,
+) -> Result<(), LemmyError> {
+  let community = Community::read(context.pool(), community_id).await?.into();
+  let local_user_view = get_local_user_view_from_jwt(jwt, context.pool(), context.secret()).await?;
+  let actor = Person::read(context.pool(), local_user_view.person.id)
+    .await?
+    .into();
+
+  // score of 1 means upvote, -1 downvote, 0 undo a previous vote
+  if score != 0 {
+    let vote = Vote::new(object_id, &actor, &community, score.try_into()?, context)?;
+    let activity = AnnouncableActivities::Vote(vote);
+    send_activity_in_community(activity, &actor, &community, vec![], false, context).await
+  } else {
+    // Lemmy API doesnt distinguish between Undo/Like and Undo/Dislike, so we hardcode it here.
+    let vote = Vote::new(object_id, &actor, &community, VoteType::Like, context)?;
+    let undo_vote = UndoVote::new(vote, &actor, &community, context)?;
+    let activity = AnnouncableActivities::UndoVote(undo_vote);
+    send_activity_in_community(activity, &actor, &community, vec![], false, context).await
+  }
+}
+
 #[tracing::instrument(skip_all)]
 async fn vote_comment(
   vote_type: &VoteType,
index dca106ded9380117e76e3de939210e1a8d3b8cb1..7a419e879b388bc61b6be26af84cd6d1ca6aeded 100644 (file)
@@ -1,18 +1,13 @@
 use crate::{
   activities::{
-    community::send_activity_in_community,
     generate_activity_id,
     verify_person_in_community,
     voting::{undo_vote_comment, undo_vote_post},
   },
-  activity_lists::AnnouncableActivities,
   local_instance,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::{
-    activities::voting::{
-      undo_vote::UndoVote,
-      vote::{Vote, VoteType},
-    },
+    activities::voting::{undo_vote::UndoVote, vote::Vote},
     InCommunity,
   },
   ActorType,
@@ -25,39 +20,27 @@ use activitypub_federation::{
   utils::verify_urls_match,
 };
 use activitystreams_kinds::activity::UndoType;
-use lemmy_api_common::LemmyContext;
-use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
 impl UndoVote {
-  /// UndoVote has as:Public value in cc field, unlike other activities. This indicates to other
-  /// software (like GNU social, or presumably Mastodon), that the like actor should not be
-  /// disclosed.
-  #[tracing::instrument(skip_all)]
-  pub async fn send(
-    object: &PostOrComment,
+  pub(in crate::activities::voting) fn new(
+    vote: Vote,
     actor: &ApubPerson,
-    community_id: CommunityId,
-    kind: VoteType,
+    community: &ApubCommunity,
     context: &LemmyContext,
-  ) -> Result<(), LemmyError> {
-    let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
-
-    let object = Vote::new(object, actor, &community, kind.clone(), context)?;
-    let id = generate_activity_id(
-      UndoType::Undo,
-      &context.settings().get_protocol_and_hostname(),
-    )?;
-    let undo_vote = UndoVote {
+  ) -> Result<Self, LemmyError> {
+    Ok(UndoVote {
       actor: ObjectId::new(actor.actor_id()),
-      object,
+      object: vote,
       kind: UndoType::Undo,
-      id: id.clone(),
+      id: generate_activity_id(
+        UndoType::Undo,
+        &context.settings().get_protocol_and_hostname(),
+      )?,
       audience: Some(ObjectId::new(community.actor_id())),
-    };
-    let activity = AnnouncableActivities::UndoVote(undo_vote);
-    send_activity_in_community(activity, actor, &community, vec![], false, context).await
+    })
   }
 }
 
index bc702fd865e998418e9f5dcb62c3d1a0cd734c0e..e435b682350f5ad1ca2dcbb38888c447a62aa477 100644 (file)
@@ -1,11 +1,9 @@
 use crate::{
   activities::{
-    community::send_activity_in_community,
     generate_activity_id,
     verify_person_in_community,
     voting::{vote_comment, vote_post},
   },
-  activity_lists::AnnouncableActivities,
   local_instance,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::{
@@ -17,20 +15,14 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
 use anyhow::anyhow;
-use lemmy_api_common::LemmyContext;
-use lemmy_db_schema::{
-  newtypes::CommunityId,
-  source::{community::Community, local_site::LocalSite},
-  traits::Crud,
-};
+use lemmy_api_common::context::LemmyContext;
+use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
-/// Vote has as:Public value in cc field, unlike other activities. This indicates to other software
-/// (like GNU social, or presumably Mastodon), that the like actor should not be disclosed.
 impl Vote {
   pub(in crate::activities::voting) fn new(
-    object: &PostOrComment,
+    object_id: ObjectId<PostOrComment>,
     actor: &ApubPerson,
     community: &ApubCommunity,
     kind: VoteType,
@@ -38,27 +30,12 @@ impl Vote {
   ) -> Result<Vote, LemmyError> {
     Ok(Vote {
       actor: ObjectId::new(actor.actor_id()),
-      object: ObjectId::new(object.ap_id()),
+      object: object_id,
       kind: kind.clone(),
       id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?,
       audience: Some(ObjectId::new(community.actor_id())),
     })
   }
-
-  #[tracing::instrument(skip_all)]
-  pub async fn send(
-    object: &PostOrComment,
-    actor: &ApubPerson,
-    community_id: CommunityId,
-    kind: VoteType,
-    context: &LemmyContext,
-  ) -> Result<(), LemmyError> {
-    let community = Community::read(context.pool(), community_id).await?.into();
-    let vote = Vote::new(object, actor, &community, kind, context)?;
-
-    let activity = AnnouncableActivities::Vote(vote);
-    send_activity_in_community(activity, actor, &community, vec![], false, context).await
-  }
 }
 
 #[async_trait::async_trait(?Send)]
index fa343d8ae746528d599c662b49112959290b48b7..6e1771127a00765ba652835ec7b24a25021ebd99 100644 (file)
@@ -24,7 +24,7 @@ use crate::{
   },
 };
 use activitypub_federation::{data::Data, deser::context::WithContext, traits::ActivityHandler};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use url::Url;
similarity index 94%
rename from crates/api_crud/src/comment/list.rs
rename to crates/apub/src/api/list_comments.rs
index 3e7444bf71b0b9fbad2e46bbdc6a03cc24940a38..c4af6900aa3c7d1102326706c96bb24077488429 100644 (file)
@@ -1,15 +1,18 @@
-use crate::PerformCrud;
+use crate::{
+  api::PerformApub,
+  fetcher::resolve_actor_identifier,
+  objects::community::ApubCommunity,
+};
 use actix_web::web::Data;
 use lemmy_api_common::{
   comment::{GetComments, GetCommentsResponse},
+  context::LemmyContext,
   utils::{
     check_private_instance,
     get_local_user_view_from_jwt_opt,
     listing_type_with_site_default,
   },
-  LemmyContext,
 };
-use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
 use lemmy_db_schema::{
   source::{comment::Comment, community::Community, local_site::LocalSite},
   traits::{Crud, DeleteableOrRemoveable},
@@ -18,7 +21,7 @@ use lemmy_db_views::comment_view::CommentQuery;
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
 #[async_trait::async_trait(?Send)]
-impl PerformCrud for GetComments {
+impl PerformApub for GetComments {
   type Response = GetCommentsResponse;
 
   #[tracing::instrument(skip(context, _websocket_id))]
similarity index 93%
rename from crates/api_crud/src/post/list.rs
rename to crates/apub/src/api/list_posts.rs
index 42944cada8854e5fc993f9398e0c62f6db43a071..7a1f815c78f48fba77de0c1cb50409f240c9de2d 100644 (file)
@@ -1,15 +1,18 @@
-use crate::PerformCrud;
+use crate::{
+  api::PerformApub,
+  fetcher::resolve_actor_identifier,
+  objects::community::ApubCommunity,
+};
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   post::{GetPosts, GetPostsResponse},
   utils::{
     check_private_instance,
     get_local_user_view_from_jwt_opt,
     listing_type_with_site_default,
   },
-  LemmyContext,
 };
-use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
 use lemmy_db_schema::{
   source::{community::Community, local_site::LocalSite},
   traits::DeleteableOrRemoveable,
@@ -18,7 +21,7 @@ use lemmy_db_views::post_view::PostQuery;
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
 #[async_trait::async_trait(?Send)]
-impl PerformCrud for GetPosts {
+impl PerformApub for GetPosts {
   type Response = GetPostsResponse;
 
   #[tracing::instrument(skip(context, _websocket_id))]
diff --git a/crates/apub/src/api/mod.rs b/crates/apub/src/api/mod.rs
new file mode 100644 (file)
index 0000000..233f72f
--- /dev/null
@@ -0,0 +1,21 @@
+use actix_web::web::Data;
+use lemmy_api_common::context::LemmyContext;
+use lemmy_utils::{error::LemmyError, ConnectionId};
+
+mod list_comments;
+mod list_posts;
+mod read_community;
+mod read_person;
+mod resolve_object;
+mod search;
+
+#[async_trait::async_trait(?Send)]
+pub trait PerformApub {
+  type Response: serde::ser::Serialize + Send;
+
+  async fn perform(
+    &self,
+    context: &Data<LemmyContext>,
+    websocket_id: Option<ConnectionId>,
+  ) -> Result<Self::Response, LemmyError>;
+}
similarity index 92%
rename from crates/api_crud/src/community/read.rs
rename to crates/apub/src/api/read_community.rs
index a008f78657b5be16ebcb52796a794fd606a9519f..b1615d7d75aa466ef6f386a3e8cc58f512a1b90a 100644 (file)
@@ -1,14 +1,14 @@
-use crate::PerformCrud;
+use crate::{
+  api::PerformApub,
+  fetcher::resolve_actor_identifier,
+  objects::community::ApubCommunity,
+};
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{GetCommunity, GetCommunityResponse},
+  context::LemmyContext,
   utils::{check_private_instance, get_local_user_view_from_jwt_opt},
   websocket::messages::GetCommunityUsersOnline,
-  LemmyContext,
-};
-use lemmy_apub::{
-  fetcher::resolve_actor_identifier,
-  objects::{community::ApubCommunity, instance::instance_actor_id_from_url},
 };
 use lemmy_db_schema::{
   impls::actor_language::default_post_language,
@@ -24,7 +24,7 @@ use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
 #[async_trait::async_trait(?Send)]
-impl PerformCrud for GetCommunity {
+impl PerformApub for GetCommunity {
   type Response = GetCommunityResponse;
 
   #[tracing::instrument(skip(context, _websocket_id))]
@@ -78,7 +78,8 @@ impl PerformCrud for GetCommunity {
       .await
       .unwrap_or(1);
 
-    let site_id = instance_actor_id_from_url(community_view.community.actor_id.clone().into());
+    let site_id =
+      Site::instance_actor_id_from_url(community_view.community.actor_id.clone().into());
     let mut site = Site::read_from_apub_id(context.pool(), site_id).await?;
     // no need to include metadata for local site (its already available through other endpoints).
     // this also prevents us from leaking the federation private key.
similarity index 95%
rename from crates/api_crud/src/user/read.rs
rename to crates/apub/src/api/read_person.rs
index b7b155a746697d6b25a34a743a040e03c75e35fb..514bcfccc1c3ada70279917a81f149fa696e15eb 100644 (file)
@@ -1,11 +1,10 @@
-use crate::PerformCrud;
+use crate::{api::PerformApub, fetcher::resolve_actor_identifier, objects::person::ApubPerson};
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   person::{GetPersonDetails, GetPersonDetailsResponse},
   utils::{check_private_instance, get_local_user_view_from_jwt_opt},
-  LemmyContext,
 };
-use lemmy_apub::{fetcher::resolve_actor_identifier, objects::person::ApubPerson};
 use lemmy_db_schema::{
   source::{local_site::LocalSite, person::Person},
   utils::post_to_comment_sort_type,
@@ -15,7 +14,7 @@ use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonViewSafe};
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
 #[async_trait::async_trait(?Send)]
-impl PerformCrud for GetPersonDetails {
+impl PerformApub for GetPersonDetails {
   type Response = GetPersonDetailsResponse;
 
   #[tracing::instrument(skip(self, context, _websocket_id))]
similarity index 93%
rename from crates/api/src/site/resolve_object.rs
rename to crates/apub/src/api/resolve_object.rs
index 47aa248e737c3dade33c352e95d5eee82b7e9e26..c179ed58219d0a6bd5dd272942cb86e050518538 100644 (file)
@@ -1,19 +1,21 @@
-use crate::Perform;
+use crate::{
+  api::PerformApub,
+  fetcher::search::{search_query_to_object_id, SearchableObjects},
+};
 use actix_web::web::Data;
 use diesel::NotFound;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{ResolveObject, ResolveObjectResponse},
   utils::{check_private_instance, get_local_user_view_from_jwt_opt},
-  LemmyContext,
 };
-use lemmy_apub::fetcher::search::{search_query_to_object_id, SearchableObjects};
 use lemmy_db_schema::{newtypes::PersonId, source::local_site::LocalSite, utils::DbPool};
 use lemmy_db_views::structs::{CommentView, PostView};
 use lemmy_db_views_actor::structs::{CommunityView, PersonViewSafe};
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
 #[async_trait::async_trait(?Send)]
-impl Perform for ResolveObject {
+impl PerformApub for ResolveObject {
   type Response = ResolveObjectResponse;
 
   #[tracing::instrument(skip(context, _websocket_id))]
similarity index 97%
rename from crates/api/src/site/search.rs
rename to crates/apub/src/api/search.rs
index 1033f92e63eeec4ba32ab419c6f513ff062c6254..cad41c5497ab323b682a7380c5ddfda424ebe5cd 100644 (file)
@@ -1,11 +1,14 @@
-use crate::Perform;
+use crate::{
+  api::PerformApub,
+  fetcher::resolve_actor_identifier,
+  objects::community::ApubCommunity,
+};
 use actix_web::web::Data;
 use lemmy_api_common::{
+  context::LemmyContext,
   site::{Search, SearchResponse},
   utils::{check_private_instance, get_local_user_view_from_jwt_opt},
-  LemmyContext,
 };
-use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
 use lemmy_db_schema::{
   source::{community::Community, local_site::LocalSite},
   traits::DeleteableOrRemoveable,
@@ -17,7 +20,7 @@ use lemmy_db_views_actor::{community_view::CommunityQuery, person_view::PersonQu
 use lemmy_utils::{error::LemmyError, ConnectionId};
 
 #[async_trait::async_trait(?Send)]
-impl Perform for Search {
+impl PerformApub for Search {
   type Response = SearchResponse;
 
   #[tracing::instrument(skip(context, _websocket_id))]
index aa38f8bee2ae63a6307deee0c5c36b024c975e6e..9616ddb306acc07a2608950233f87f5d770ffe52 100644 (file)
@@ -11,7 +11,7 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::collection::OrderedCollectionType;
 use chrono::NaiveDateTime;
-use lemmy_api_common::generate_moderators_url;
+use lemmy_api_common::utils::generate_moderators_url;
 use lemmy_db_schema::{
   source::community::{CommunityModerator, CommunityModeratorForm},
   traits::Joinable,
index 44685430e7bdf2046f218edeb2129a602b25860d..a16fbd02bba8ad75d3b3b1769600b34e167c1ffd 100644 (file)
@@ -19,7 +19,7 @@ use activitypub_federation::{
 use activitystreams_kinds::collection::OrderedCollectionType;
 use chrono::NaiveDateTime;
 use futures::future::join_all;
-use lemmy_api_common::generate_outbox_url;
+use lemmy_api_common::utils::generate_outbox_url;
 use lemmy_db_schema::{
   source::{person::Person, post::Post},
   traits::Crud,
index 4c27beb415c734c1be615110ce4049bebaaff902..40bdf1206aef77cde5060885d12dbd88b1d8010f 100644 (file)
@@ -1,5 +1,5 @@
 use crate::objects::community::ApubCommunity;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 
 pub(crate) mod community_moderators;
 pub(crate) mod community_outbox;
index 563989241f248ea54bc49f290b7993cf0069b472..0ce4dd8f607e53394de0af1f04ca4432d1d27e0d 100644 (file)
@@ -1,7 +1,7 @@
 use crate::{fetcher::webfinger::webfinger_resolve_actor, ActorType};
 use activitypub_federation::traits::ApubObject;
 use itertools::Itertools;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::traits::ApubActor;
 use lemmy_utils::error::LemmyError;
 
index b44d9f16f9d9ea9c9631772fa3d74d9882402871..68e176b0145ccc8ca1b078c89e2d90f42fbbbb7a 100644 (file)
@@ -7,7 +7,7 @@ use crate::{
 };
 use activitypub_federation::traits::ApubObject;
 use chrono::NaiveDateTime;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{community::Community, post::Post},
   traits::Crud,
@@ -97,16 +97,6 @@ impl ApubObject for PostOrComment {
   }
 }
 
-impl PostOrComment {
-  pub(crate) fn ap_id(&self) -> Url {
-    match self {
-      PostOrComment::Post(p) => p.ap_id.clone(),
-      PostOrComment::Comment(c) => c.ap_id.clone(),
-    }
-    .into()
-  }
-}
-
 #[async_trait::async_trait(?Send)]
 impl InCommunity for PostOrComment {
   async fn community(
index 95b47f5e499e0dd5946e6674075bec20606584f6..ffc2c96118694191ccf554b43b21c2416b01013f 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject};
 use chrono::NaiveDateTime;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::Deserialize;
 use url::Url;
@@ -15,7 +15,7 @@ use url::Url;
 /// ObjectId directly, or a webfinger identifier (@user@example.com or !community@example.com)
 /// which gets resolved to an URL.
 #[tracing::instrument(skip_all)]
-pub async fn search_query_to_object_id(
+pub(crate) async fn search_query_to_object_id(
   query: &str,
   local_only: bool,
   context: &LemmyContext,
@@ -54,7 +54,7 @@ pub async fn search_query_to_object_id(
 
 /// The types of ActivityPub objects that can be fetched directly by searching for their ID.
 #[derive(Debug)]
-pub enum SearchableObjects {
+pub(crate) enum SearchableObjects {
   Person(ApubPerson),
   Community(ApubCommunity),
   Post(ApubPost),
@@ -63,7 +63,7 @@ pub enum SearchableObjects {
 
 #[derive(Deserialize)]
 #[serde(untagged)]
-pub enum SearchableApubTypes {
+pub(crate) enum SearchableApubTypes {
   Group(Group),
   Person(Person),
   Page(Page),
index 14fc5c34464ed74b59aa9a6889312dabc014d174..3af86be1a66a13777aaa4f49963dd3dd8d855fa2 100644 (file)
@@ -5,7 +5,7 @@ use crate::{
 };
 use activitypub_federation::traits::{Actor, ApubObject};
 use chrono::NaiveDateTime;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use url::Url;
index 3ec6fcf81873445f4536848c641225f9cda2ea60..4746736ebcf8c2c05896dbb4833560046b7e1afc 100644 (file)
@@ -2,7 +2,7 @@ use crate::{local_instance, ActorType, FEDERATION_HTTP_FETCH_LIMIT};
 use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject};
 use anyhow::anyhow;
 use itertools::Itertools;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::newtypes::DbUrl;
 use lemmy_utils::{error::LemmyError, WebfingerResponse};
 use tracing::debug;
@@ -10,7 +10,6 @@ use url::Url;
 
 /// Turns a person id like `@name@example.com` into an apub ID, like `https://example.com/user/name`,
 /// using webfinger.
-#[tracing::instrument(skip_all)]
 pub(crate) async fn webfinger_resolve_actor<Kind>(
   identifier: &str,
   local_only: bool,
index fbadd42bad3acd647d83eb688439af4225ff331f..5e7de7e25a6c9c9726c5824c7093a0819ed42882 100644 (file)
@@ -5,7 +5,7 @@ use crate::{
 use activitypub_federation::traits::ApubObject;
 use actix_web::{web, web::Path, HttpResponse};
 use diesel::result::Error::NotFound;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};
 use lemmy_utils::error::LemmyError;
 use serde::Deserialize;
index 487ad5512722245ae0e7ac7636cfcffd41d7e59c..74809509fb4adad01f0559b5084b339f4db4a87e 100644 (file)
@@ -16,7 +16,7 @@ use activitypub_federation::{
   traits::ApubObject,
 };
 use actix_web::{web, HttpRequest, HttpResponse};
-use lemmy_api_common::{generate_outbox_url, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url};
 use lemmy_db_schema::{source::community::Community, traits::ApubActor};
 use lemmy_utils::error::LemmyError;
 use serde::Deserialize;
index c4602c3374feb127e88eb9d2a1f4f4fbfafebbac..726834c00bf3bdb4f00957569f06abcaf35dd9d8 100644 (file)
@@ -15,7 +15,7 @@ use activitypub_federation::{
 };
 use actix_web::{web, HttpRequest, HttpResponse};
 use http::StatusCode;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::source::activity::Activity;
 use lemmy_utils::error::LemmyError;
 use once_cell::sync::OnceCell;
index 0e838fe137a7ddb7d78478c73ad8ae2288f3c560..6a1bc5b35c52efa8da7c1499c83ea45525d3cae3 100644 (file)
@@ -7,7 +7,7 @@ use crate::{
 };
 use activitypub_federation::{deser::context::WithContext, traits::ApubObject};
 use actix_web::{web, HttpRequest, HttpResponse};
-use lemmy_api_common::{generate_outbox_url, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url};
 use lemmy_db_schema::{source::person::Person, traits::ApubActor};
 use lemmy_utils::error::LemmyError;
 use serde::Deserialize;
index 85a4406f59e49079b69bdf3a83576b2c5dad0ee8..bea5da3a46d5cf08f1d72dfa987f6e12362aa8cd 100644 (file)
@@ -5,7 +5,7 @@ use crate::{
 use activitypub_federation::traits::ApubObject;
 use actix_web::{web, HttpResponse};
 use diesel::result::Error::NotFound;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{newtypes::PostId, source::post::Post, traits::Crud};
 use lemmy_utils::error::LemmyError;
 use serde::Deserialize;
index 7a945ac72277a7ca7a6ad257ee8fc33c3a530016..fe6c34f639dc59f0de71abe1129964f757ee12b6 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
 };
 use activitypub_federation::{deser::context::WithContext, traits::ApubObject};
 use actix_web::{web, HttpRequest, HttpResponse};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_views::structs::SiteView;
 use lemmy_utils::error::LemmyError;
 use url::Url;
index 92ae014b1fa63da7c6f765d5fb155ab729d36c79..0908a1f4f4ec1cd3fcec5e28cf8acec0c93decab 100644 (file)
@@ -7,7 +7,7 @@ use activitypub_federation::{
   UrlVerifier,
 };
 use async_trait::async_trait;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{activity::Activity, instance::Instance, local_site::LocalSite},
   utils::DbPool,
@@ -19,6 +19,7 @@ use url::Url;
 
 pub mod activities;
 pub(crate) mod activity_lists;
+pub mod api;
 pub(crate) mod collections;
 pub mod fetcher;
 pub mod http;
@@ -216,3 +217,16 @@ pub trait ActorType: Actor + ApubObject {
     PublicKey::new_main_key(self.actor_id(), self.public_key().to_string())
   }
 }
+
+#[async_trait::async_trait(?Send)]
+pub trait SendActivity {
+  type Response;
+
+  async fn send_activity(
+    _request: &Self,
+    _response: &Self::Response,
+    _context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
+    Ok(())
+  }
+}
index ae7d9b6c17bac5faee12b88419228049613ed555..559078942d88a0556caf26a3f3a76743251c9ffb 100644 (file)
@@ -5,7 +5,7 @@ use crate::{
 };
 use activitypub_federation::core::object_id::ObjectId;
 use activitystreams_kinds::link::MentionType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{comment::Comment, person::Person, post::Post},
   traits::Crud,
index a4c6ef737f018bf3828e35bc8a394b504101b7b2..ab11b00d857d8d84ee1139839a4af30e2626a610 100644 (file)
@@ -20,7 +20,7 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::{object::NoteType, public};
 use chrono::NaiveDateTime;
-use lemmy_api_common::{utils::local_site_opt_to_slur_regex, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex};
 use lemmy_db_schema::{
   source::{
     comment::{Comment, CommentInsertForm, CommentUpdateForm},
@@ -39,7 +39,7 @@ use std::ops::Deref;
 use url::Url;
 
 #[derive(Clone, Debug)]
-pub struct ApubComment(Comment);
+pub struct ApubComment(pub(crate) Comment);
 
 impl Deref for ApubComment {
   type Target = Comment;
index d8c1596ae2f664c68e0366d49e7bb44adadf8c88..b309d25fc037ccc1a20146b398db0935be2a1318 100644 (file)
@@ -18,7 +18,10 @@ use activitypub_federation::{
 use activitystreams_kinds::actor::GroupType;
 use chrono::NaiveDateTime;
 use itertools::Itertools;
-use lemmy_api_common::{generate_moderators_url, generate_outbox_url, LemmyContext};
+use lemmy_api_common::{
+  context::LemmyContext,
+  utils::{generate_moderators_url, generate_outbox_url},
+};
 use lemmy_db_schema::{
   source::{
     actor_language::CommunityLanguage,
index 18e9d9f2576aeebdb5d5dcb7775c58c50adb04ee..5ec4fe9097d64ec7982e76ca156c676df3ab346b 100644 (file)
@@ -20,7 +20,7 @@ use activitypub_federation::{
   utils::verify_domains_match,
 };
 use chrono::NaiveDateTime;
-use lemmy_api_common::{utils::local_site_opt_to_slur_regex, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex};
 use lemmy_db_schema::{
   source::{
     actor_language::SiteLanguage,
@@ -176,15 +176,6 @@ impl Actor for ApubSite {
   }
 }
 
-/// Instance actor is at the root path, so we simply need to clear the path and other unnecessary
-/// parts of the url.
-pub fn instance_actor_id_from_url(mut url: Url) -> Url {
-  url.set_fragment(None);
-  url.set_path("");
-  url.set_query(None);
-  url
-}
-
 /// try to fetch the instance actor (to make things like instance rules available)
 pub(in crate::objects) async fn fetch_instance_actor_for_object(
   object_id: Url,
@@ -192,7 +183,7 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object(
   request_counter: &mut i32,
 ) {
   // try to fetch the instance actor (to make things like instance rules available)
-  let instance_id = instance_actor_id_from_url(object_id);
+  let instance_id = Site::instance_actor_id_from_url(object_id);
   let site = ObjectId::<ApubSite>::new(instance_id.clone())
     .dereference(context, local_instance(context).await, request_counter)
     .await;
index 1bf621fca39ac000ccc5cff6bed2ca07222d7c7c..58e1f23f55e5c0298adccf225e36dbbdf6b4f5cf 100644 (file)
@@ -57,9 +57,9 @@ pub(crate) mod tests {
   use actix::Actor;
   use anyhow::anyhow;
   use lemmy_api_common::{
+    context::LemmyContext,
     request::build_user_agent,
     websocket::chat_server::ChatServer,
-    LemmyContext,
   };
   use lemmy_db_schema::{source::secret::Secret, utils::build_db_pool_for_tests};
   use lemmy_utils::{
@@ -113,6 +113,7 @@ pub(crate) mod tests {
       pool.clone(),
       |_, _, _, _| Box::pin(x()),
       |_, _, _, _| Box::pin(x()),
+      |_, _, _, _| Box::pin(x()),
       client.clone(),
       settings.clone(),
       secret.clone(),
index 236f3edf345ed2c0c5340459c8a5c4dbb159c321..2017b605c84eb7301a7345251d6ba88e00fc0792 100644 (file)
@@ -18,7 +18,10 @@ use activitypub_federation::{
   utils::verify_domains_match,
 };
 use chrono::NaiveDateTime;
-use lemmy_api_common::{generate_outbox_url, utils::local_site_opt_to_slur_regex, LemmyContext};
+use lemmy_api_common::{
+  context::LemmyContext,
+  utils::{generate_outbox_url, local_site_opt_to_slur_regex},
+};
 use lemmy_db_schema::{
   source::{
     instance::Instance,
index f79e3055ae117c69a1a4d7e82942c08a4498e4d1..afe025ce263bf4b6ce6f57c7b320a650a9eec76e 100644 (file)
@@ -23,9 +23,9 @@ use activitypub_federation::{
 use activitystreams_kinds::public;
 use chrono::NaiveDateTime;
 use lemmy_api_common::{
+  context::LemmyContext,
   request::fetch_site_data,
   utils::local_site_opt_to_slur_regex,
-  LemmyContext,
 };
 use lemmy_db_schema::{
   self,
@@ -46,7 +46,7 @@ use std::ops::Deref;
 use url::Url;
 
 #[derive(Clone, Debug)]
-pub struct ApubPost(Post);
+pub struct ApubPost(pub(crate) Post);
 
 impl Deref for ApubPost {
   type Target = Post;
index f4807076bab797ba2d4550a7d4cc55c7e5417e9f..4d8c70076c1afe5eea7d08964ec9ffd06bd518a2 100644 (file)
@@ -15,7 +15,7 @@ use activitypub_federation::{
   utils::verify_domains_match,
 };
 use chrono::NaiveDateTime;
-use lemmy_api_common::{utils::check_person_block, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::check_person_block};
 use lemmy_db_schema::{
   source::{
     person::Person,
@@ -31,7 +31,7 @@ use std::ops::Deref;
 use url::Url;
 
 #[derive(Clone, Debug)]
-pub struct ApubPrivateMessage(PrivateMessage);
+pub struct ApubPrivateMessage(pub(crate) PrivateMessage);
 
 impl Deref for ApubPrivateMessage {
   type Target = PrivateMessage;
index 364fe9b9f055bb8409a868edfb5cc6f7f4f94108..3ac040ced0a7b44b3c5b1445e5d86c6de76ce230 100644 (file)
@@ -8,7 +8,7 @@ use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserial
 use activitystreams_kinds::activity::BlockType;
 use anyhow::anyhow;
 use chrono::{DateTime, FixedOffset};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
index 9646315ff9895df6ed55b9b1a681630ef25b91a3..d818af9de8212dbaaa4e6e38873abeb1bf8b6282 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
 use activitystreams_kinds::activity::UndoType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
index c8ea5daa9f801529c5c0f4969f69f0ea5c256984..22fc07fcbaf4fd85a130772aeb6f562786ca3ceb 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
 use activitystreams_kinds::activity::AddType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use url::Url;
index 57d9c1bcab54129dc193e7a5c74485f5c6fb5714..ce46fb920f6cba3b8aaf22d0992514ee8a3955a7 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
 use activitystreams_kinds::activity::RemoveType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use url::Url;
index a66e08b0500a05abe2cc6b3858f7c146c0ea815c..0a1ef650fc264c06d20d7e1ba407de3578f2ee0b 100644 (file)
@@ -7,7 +7,7 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one};
 use activitystreams_kinds::activity::FlagType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use url::Url;
index 8bf39a8269fd530bfa89420822599c58d055f51b..9a2f1f48165e7c7c47f09f743ded9016b0f11cd5 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
 use activitystreams_kinds::activity::UpdateType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use url::Url;
index a952811bea7ad67a966fa9225c4c3a37f6643d76..dfa1dbe9ff5d5d5683e5241299ebe73e541ae57e 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
   protocol::{activities::CreateOrUpdateType, objects::note::Note, InCommunity},
 };
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{source::community::Community, traits::Crud};
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
index 9d45ae0bf1da060839d01d5391fd52aef17efc6e..2c15d9f90d98c8a282d18f275e4fbdf9c291159e 100644 (file)
@@ -5,7 +5,7 @@ use crate::{
   protocol::{activities::CreateOrUpdateType, objects::page::Page, InCommunity},
 };
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use url::Url;
index 8a0c1b0bd858f59db4b5092fec9d5622b81b9ba0..d92ac2456c044d774a0c8eb1fe79d8682e706c8d 100644 (file)
@@ -7,7 +7,7 @@ use crate::{
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
 use activitystreams_kinds::activity::DeleteType;
 use anyhow::anyhow;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{community::Community, post::Post},
   traits::Crud,
index 0e2c0f9821f9ea2367063e083cf16acaba1d32d1..d5249ba9aaa438d2e6156f83f1d67c361613da70 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
 };
 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
 use activitystreams_kinds::activity::UndoType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
index 7c23036c619244c20bf8e479c15c76d91d9ec29c..0973c76a86059d2472b31869c7f7f4e071b171d8 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
 };
 use activitypub_federation::core::object_id::ObjectId;
 use activitystreams_kinds::activity::UndoType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use url::Url;
index a88aa3da9c783aaecd15c9a5f5e4a021f224f443..2a09a45eaa4a4022a48f6abd3679cb36f3e54654 100644 (file)
@@ -6,7 +6,7 @@ use crate::{
   protocol::InCommunity,
 };
 use activitypub_federation::core::object_id::ObjectId;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
 use std::convert::TryFrom;
index 23ee169d4a6b966b2118c9e6161b5071f626137c..b9cf851827951de3e649435ba30e80a0426401f5 100644 (file)
@@ -1,5 +1,5 @@
 use activitystreams_kinds::collection::CollectionType;
-use lemmy_api_common::{generate_followers_url, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::generate_followers_url};
 use lemmy_db_schema::source::community::Community;
 use lemmy_db_views_actor::structs::CommunityFollowerView;
 use lemmy_utils::error::LemmyError;
index 16bdb1b2995ea149721afeb5363442a1e213c660..ef0f2a875a8f642b34d85b832e67d9d8766d2b2e 100644 (file)
@@ -1,7 +1,7 @@
 use crate::{local_instance, objects::community::ApubCommunity};
 use activitypub_federation::{deser::values::MediaTypeMarkdown, utils::fetch_object_http};
 use activitystreams_kinds::object::ImageType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::newtypes::DbUrl;
 use lemmy_utils::error::LemmyError;
 use serde::{de::DeserializeOwned, Deserialize, Serialize};
index 316af1a8dc7d4834c5a34d08fd7ae01d546e920c..03f71a348b2d712029b8682fb642bc2a9fe51b98 100644 (file)
@@ -19,7 +19,7 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::actor::GroupType;
 use chrono::{DateTime, FixedOffset};
-use lemmy_api_common::{utils::local_site_opt_to_slur_regex, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex};
 use lemmy_db_schema::{
   newtypes::InstanceId,
   source::community::{CommunityInsertForm, CommunityUpdateForm},
index f8263d874a3bb959eea54adf6dbea0f68cfd4ce6..f561c313df9e624ad2ec692bbefad7237707aa50 100644 (file)
@@ -15,7 +15,7 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::object::NoteType;
 use chrono::{DateTime, FixedOffset};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{community::Community, post::Post},
   traits::Crud,
index 1ff12bc293df6bf1a6cd32de542624a1511cad30..a62fb8e57d878a8de695dea561897ea0e15601cd 100644 (file)
@@ -20,7 +20,7 @@ use activitystreams_kinds::{
 };
 use chrono::{DateTime, FixedOffset};
 use itertools::Itertools;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::newtypes::DbUrl;
 use lemmy_utils::error::LemmyError;
 use serde::{Deserialize, Serialize};
index 42d384eb97daf8d95f244e6cf68dc0a53fe005e1..96f8a2f0555e7836e77e80ce1a4bdf5fa6f01b2f 100644 (file)
@@ -75,4 +75,13 @@ impl Site {
     let conn = &mut get_conn(pool).await?;
     site.order_by(id).offset(1).get_results::<Self>(conn).await
   }
+
+  /// Instance actor is at the root path, so we simply need to clear the path and other unnecessary
+  /// parts of the url.
+  pub fn instance_actor_id_from_url(mut url: Url) -> Url {
+    url.set_fragment(None);
+    url.set_path("");
+    url.set_query(None);
+    url
+  }
 }
index c5349a20a3536b85c4fefc7ae50ef8e78bd88fd6..bc2b573e52ab420b0855ea2a8adc7e4d27e04511 100644 (file)
@@ -16,7 +16,7 @@ lemmy_utils = { workspace = true }
 lemmy_db_views = { workspace = true }
 lemmy_db_views_actor = { workspace = true }
 lemmy_db_schema = { workspace = true }
-lemmy_api_common = { workspace = true }
+lemmy_api_common = { workspace = true, features = ["full"] }
 diesel = { workspace = true }
 actix-web = { workspace = true }
 anyhow = { workspace = true }
index 72181bf6ac95d2ebc35cb6ecf2fa66977511f574..594bf1153dbb2c6f1ad356e96a12e14fdc1b6f4b 100644 (file)
@@ -1,7 +1,7 @@
 use actix_web::{error::ErrorBadRequest, web, Error, HttpRequest, HttpResponse, Result};
 use anyhow::anyhow;
 use chrono::{DateTime, NaiveDateTime, Utc};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   newtypes::LocalUserId,
   source::{community::Community, local_user::LocalUser, person::Person},
index 6e839e214792401554d7246e8894d0c053d265c3..0b1f6fbdd7c8d60e0f6fad1daa2d209c8e98937e 100644 (file)
@@ -11,7 +11,7 @@ use actix_web::{
   HttpResponse,
 };
 use futures::stream::{Stream, StreamExt};
-use lemmy_api_common::{utils::get_local_user_view_from_jwt, LemmyContext};
+use lemmy_api_common::{context::LemmyContext, utils::get_local_user_view_from_jwt};
 use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_utils::{claims::Claims, rate_limit::RateLimitCell, REQWEST_TIMEOUT};
 use reqwest::Body;
index 3a8b418594b509e4c416b7e3fea2c522b57b4b1b..13786e3b691ba0a96c362ef0e768240e3e7f573e 100644 (file)
@@ -1,6 +1,6 @@
 use actix_web::{error::ErrorBadRequest, web, Error, HttpResponse, Result};
 use anyhow::anyhow;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_views::structs::SiteView;
 use lemmy_utils::{error::LemmyError, version};
 use serde::{Deserialize, Serialize};
index 68482a8d162aa6e318774fe34f114c4f235d51e1..9056ea632be2d2f52ea5af06940d2f9d7ee764bb 100644 (file)
@@ -1,6 +1,6 @@
 use actix_web::{web, web::Query, HttpResponse};
 use anyhow::Context;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{community::Community, person::Person},
   traits::ApubActor,
index 626857c691e28f80107183e7d31d6b57c434fe72..77e5c27d73c6b96ca83ce119a6b3c4e020657834 100644 (file)
@@ -28,6 +28,7 @@ use lemmy_api_common::{
     RemoveCommunity,
     TransferCommunity,
   },
+  context::LemmyContext,
   person::{
     AddAdmin,
     BanPerson,
@@ -96,13 +97,18 @@ use lemmy_api_common::{
   },
   websocket::{
     routes::chat_route,
+    serialize_websocket_message,
     structs::{CommunityJoin, ModJoin, PostJoin, UserJoin},
+    UserOperation,
+    UserOperationApub,
+    UserOperationCrud,
   },
-  LemmyContext,
 };
 use lemmy_api_crud::PerformCrud;
-use lemmy_utils::rate_limit::RateLimitCell;
+use lemmy_apub::{api::PerformApub, SendActivity};
+use lemmy_utils::{error::LemmyError, rate_limit::RateLimitCell, ConnectionId};
 use serde::Deserialize;
+use std::result;
 
 pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
   cfg.service(
@@ -126,12 +132,12 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
       .service(
         web::resource("/search")
           .wrap(rate_limit.search())
-          .route(web::get().to(route_get::<Search>)),
+          .route(web::get().to(route_get_apub::<Search>)),
       )
       .service(
         web::resource("/resolve_object")
           .wrap(rate_limit.message())
-          .route(web::get().to(route_get::<ResolveObject>)),
+          .route(web::get().to(route_get_apub::<ResolveObject>)),
       )
       // Community
       .service(
@@ -143,7 +149,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
       .service(
         web::scope("/community")
           .wrap(rate_limit.message())
-          .route("", web::get().to(route_get_crud::<GetCommunity>))
+          .route("", web::get().to(route_get_apub::<GetCommunity>))
           .route("", web::put().to(route_post_crud::<EditCommunity>))
           .route("/hide", web::put().to(route_post::<HideCommunity>))
           .route("/list", web::get().to(route_get_crud::<ListCommunities>))
@@ -185,7 +191,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
           )
           .route("/lock", web::post().to(route_post::<LockPost>))
           .route("/sticky", web::post().to(route_post::<StickyPost>))
-          .route("/list", web::get().to(route_get_crud::<GetPosts>))
+          .route("/list", web::get().to(route_get_apub::<GetPosts>))
           .route("/like", web::post().to(route_post::<CreatePostLike>))
           .route("/save", web::put().to(route_post::<SavePost>))
           .route("/join", web::post().to(route_post::<PostJoin>))
@@ -221,7 +227,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
           )
           .route("/like", web::post().to(route_post::<CreateCommentLike>))
           .route("/save", web::put().to(route_post::<SaveComment>))
-          .route("/list", web::get().to(route_get_crud::<GetComments>))
+          .route("/list", web::get().to(route_get_apub::<GetComments>))
           .route("/report", web::post().to(route_post::<CreateCommentReport>))
           .route(
             "/report/resolve",
@@ -279,7 +285,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
       .service(
         web::scope("/user")
           .wrap(rate_limit.message())
-          .route("", web::get().to(route_get_crud::<GetPersonDetails>))
+          .route("", web::get().to(route_get_apub::<GetPersonDetails>))
           .route("/mention", web::get().to(route_get::<GetPersonMentions>))
           .route(
             "/mention/mark_as_read",
@@ -352,19 +358,21 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
   );
 }
 
-async fn perform<Request>(
-  data: Request,
+async fn perform<'a, Data>(
+  data: Data,
   context: web::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
-  Request: Perform,
-  Request: Send + 'static,
+  Data: Perform
+    + SendActivity<Response = <Data as Perform>::Response>
+    + Clone
+    + Deserialize<'a>
+    + Send
+    + 'static,
 {
-  let res = data
-    .perform(&context, None)
-    .await
-    .map(|json| HttpResponse::Ok().json(json))?;
-  Ok(res)
+  let res = data.perform(&context, None).await?;
+  SendActivity::send_activity(&data, &res, &context).await?;
+  Ok(HttpResponse::Ok().json(res))
 }
 
 async fn route_get<'a, Data>(
@@ -372,34 +380,63 @@ async fn route_get<'a, Data>(
   context: web::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
-  Data: Deserialize<'a> + Send + 'static + Perform,
+  Data: Perform
+    + SendActivity<Response = <Data as Perform>::Response>
+    + Clone
+    + Deserialize<'a>
+    + Send
+    + 'static,
 {
   perform::<Data>(data.0, context).await
 }
 
+async fn route_get_apub<'a, Data>(
+  data: web::Query<Data>,
+  context: web::Data<LemmyContext>,
+) -> Result<HttpResponse, Error>
+where
+  Data: PerformApub
+    + SendActivity<Response = <Data as PerformApub>::Response>
+    + Clone
+    + Deserialize<'a>
+    + Send
+    + 'static,
+{
+  let res = data.perform(&context, None).await?;
+  SendActivity::send_activity(&data.0, &res, &context).await?;
+  Ok(HttpResponse::Ok().json(res))
+}
+
 async fn route_post<'a, Data>(
   data: web::Json<Data>,
   context: web::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
-  Data: Deserialize<'a> + Send + 'static + Perform,
+  Data: Perform
+    + SendActivity<Response = <Data as Perform>::Response>
+    + Clone
+    + Deserialize<'a>
+    + Send
+    + 'static,
 {
   perform::<Data>(data.0, context).await
 }
 
-async fn perform_crud<Request>(
-  data: Request,
+async fn perform_crud<'a, Data>(
+  data: Data,
   context: web::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
-  Request: PerformCrud,
-  Request: Send + 'static,
+  Data: PerformCrud
+    + SendActivity<Response = <Data as PerformCrud>::Response>
+    + Clone
+    + Deserialize<'a>
+    + Send
+    + 'static,
 {
-  let res = data
-    .perform(&context, None)
-    .await
-    .map(|json| HttpResponse::Ok().json(json))?;
-  Ok(res)
+  let res = data.perform(&context, None).await?;
+  SendActivity::send_activity(&data, &res, &context).await?;
+  Ok(HttpResponse::Ok().json(res))
 }
 
 async fn route_get_crud<'a, Data>(
@@ -407,7 +444,12 @@ async fn route_get_crud<'a, Data>(
   context: web::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
-  Data: Deserialize<'a> + Send + 'static + PerformCrud,
+  Data: PerformCrud
+    + SendActivity<Response = <Data as PerformCrud>::Response>
+    + Clone
+    + Deserialize<'a>
+    + Send
+    + 'static,
 {
   perform_crud::<Data>(data.0, context).await
 }
@@ -417,7 +459,340 @@ async fn route_post_crud<'a, Data>(
   context: web::Data<LemmyContext>,
 ) -> Result<HttpResponse, Error>
 where
-  Data: Deserialize<'a> + Send + 'static + PerformCrud,
+  Data: PerformCrud
+    + SendActivity<Response = <Data as PerformCrud>::Response>
+    + Clone
+    + Deserialize<'a>
+    + Send
+    + 'static,
 {
   perform_crud::<Data>(data.0, context).await
 }
+
+pub async fn match_websocket_operation_crud(
+  context: LemmyContext,
+  id: ConnectionId,
+  op: UserOperationCrud,
+  data: &str,
+) -> result::Result<String, LemmyError> {
+  match op {
+    // User ops
+    UserOperationCrud::Register => {
+      do_websocket_operation_crud::<Register>(context, id, op, data).await
+    }
+    UserOperationCrud::DeleteAccount => {
+      do_websocket_operation_crud::<DeleteAccount>(context, id, op, data).await
+    }
+
+    // Private Message ops
+    UserOperationCrud::CreatePrivateMessage => {
+      do_websocket_operation_crud::<CreatePrivateMessage>(context, id, op, data).await
+    }
+    UserOperationCrud::EditPrivateMessage => {
+      do_websocket_operation_crud::<EditPrivateMessage>(context, id, op, data).await
+    }
+    UserOperationCrud::DeletePrivateMessage => {
+      do_websocket_operation_crud::<DeletePrivateMessage>(context, id, op, data).await
+    }
+    UserOperationCrud::GetPrivateMessages => {
+      do_websocket_operation_crud::<GetPrivateMessages>(context, id, op, data).await
+    }
+
+    // Site ops
+    UserOperationCrud::CreateSite => {
+      do_websocket_operation_crud::<CreateSite>(context, id, op, data).await
+    }
+    UserOperationCrud::EditSite => {
+      do_websocket_operation_crud::<EditSite>(context, id, op, data).await
+    }
+    UserOperationCrud::GetSite => {
+      do_websocket_operation_crud::<GetSite>(context, id, op, data).await
+    }
+
+    // Community ops
+    UserOperationCrud::ListCommunities => {
+      do_websocket_operation_crud::<ListCommunities>(context, id, op, data).await
+    }
+    UserOperationCrud::CreateCommunity => {
+      do_websocket_operation_crud::<CreateCommunity>(context, id, op, data).await
+    }
+    UserOperationCrud::EditCommunity => {
+      do_websocket_operation_crud::<EditCommunity>(context, id, op, data).await
+    }
+    UserOperationCrud::DeleteCommunity => {
+      do_websocket_operation_crud::<DeleteCommunity>(context, id, op, data).await
+    }
+    UserOperationCrud::RemoveCommunity => {
+      do_websocket_operation_crud::<RemoveCommunity>(context, id, op, data).await
+    }
+
+    // Post ops
+    UserOperationCrud::CreatePost => {
+      do_websocket_operation_crud::<CreatePost>(context, id, op, data).await
+    }
+    UserOperationCrud::GetPost => {
+      do_websocket_operation_crud::<GetPost>(context, id, op, data).await
+    }
+    UserOperationCrud::EditPost => {
+      do_websocket_operation_crud::<EditPost>(context, id, op, data).await
+    }
+    UserOperationCrud::DeletePost => {
+      do_websocket_operation_crud::<DeletePost>(context, id, op, data).await
+    }
+    UserOperationCrud::RemovePost => {
+      do_websocket_operation_crud::<RemovePost>(context, id, op, data).await
+    }
+
+    // Comment ops
+    UserOperationCrud::CreateComment => {
+      do_websocket_operation_crud::<CreateComment>(context, id, op, data).await
+    }
+    UserOperationCrud::EditComment => {
+      do_websocket_operation_crud::<EditComment>(context, id, op, data).await
+    }
+    UserOperationCrud::DeleteComment => {
+      do_websocket_operation_crud::<DeleteComment>(context, id, op, data).await
+    }
+    UserOperationCrud::RemoveComment => {
+      do_websocket_operation_crud::<RemoveComment>(context, id, op, data).await
+    }
+    UserOperationCrud::GetComment => {
+      do_websocket_operation_crud::<GetComment>(context, id, op, data).await
+    }
+  }
+}
+
+async fn do_websocket_operation_crud<'a, 'b, Data>(
+  context: LemmyContext,
+  id: ConnectionId,
+  op: UserOperationCrud,
+  data: &str,
+) -> result::Result<String, LemmyError>
+where
+  Data: PerformCrud + SendActivity<Response = <Data as PerformCrud>::Response>,
+  for<'de> Data: Deserialize<'de>,
+{
+  let parsed_data: Data = serde_json::from_str(data)?;
+  let res = parsed_data
+    .perform(&web::Data::new(context.clone()), Some(id))
+    .await?;
+  SendActivity::send_activity(&parsed_data, &res, &context).await?;
+  serialize_websocket_message(&op, &res)
+}
+
+pub async fn match_websocket_operation_apub(
+  context: LemmyContext,
+  id: ConnectionId,
+  op: UserOperationApub,
+  data: &str,
+) -> result::Result<String, LemmyError> {
+  match op {
+    UserOperationApub::GetPersonDetails => {
+      do_websocket_operation_apub::<GetPersonDetails>(context, id, op, data).await
+    }
+    UserOperationApub::GetCommunity => {
+      do_websocket_operation_apub::<GetCommunity>(context, id, op, data).await
+    }
+    UserOperationApub::GetComments => {
+      do_websocket_operation_apub::<GetComments>(context, id, op, data).await
+    }
+    UserOperationApub::GetPosts => {
+      do_websocket_operation_apub::<GetPosts>(context, id, op, data).await
+    }
+    UserOperationApub::ResolveObject => {
+      do_websocket_operation_apub::<ResolveObject>(context, id, op, data).await
+    }
+    UserOperationApub::Search => do_websocket_operation_apub::<Search>(context, id, op, data).await,
+  }
+}
+
+async fn do_websocket_operation_apub<'a, 'b, Data>(
+  context: LemmyContext,
+  id: ConnectionId,
+  op: UserOperationApub,
+  data: &str,
+) -> result::Result<String, LemmyError>
+where
+  Data: PerformApub + SendActivity<Response = <Data as PerformApub>::Response>,
+  for<'de> Data: Deserialize<'de>,
+{
+  let parsed_data: Data = serde_json::from_str(data)?;
+  let res = parsed_data
+    .perform(&web::Data::new(context.clone()), Some(id))
+    .await?;
+  SendActivity::send_activity(&parsed_data, &res, &context).await?;
+  serialize_websocket_message(&op, &res)
+}
+
+pub async fn match_websocket_operation(
+  context: LemmyContext,
+  id: ConnectionId,
+  op: UserOperation,
+  data: &str,
+) -> result::Result<String, LemmyError> {
+  match op {
+    // User ops
+    UserOperation::Login => do_websocket_operation::<Login>(context, id, op, data).await,
+    UserOperation::GetCaptcha => do_websocket_operation::<GetCaptcha>(context, id, op, data).await,
+    UserOperation::GetReplies => do_websocket_operation::<GetReplies>(context, id, op, data).await,
+    UserOperation::AddAdmin => do_websocket_operation::<AddAdmin>(context, id, op, data).await,
+    UserOperation::GetUnreadRegistrationApplicationCount => {
+      do_websocket_operation::<GetUnreadRegistrationApplicationCount>(context, id, op, data).await
+    }
+    UserOperation::ListRegistrationApplications => {
+      do_websocket_operation::<ListRegistrationApplications>(context, id, op, data).await
+    }
+    UserOperation::ApproveRegistrationApplication => {
+      do_websocket_operation::<ApproveRegistrationApplication>(context, id, op, data).await
+    }
+    UserOperation::BanPerson => do_websocket_operation::<BanPerson>(context, id, op, data).await,
+    UserOperation::GetBannedPersons => {
+      do_websocket_operation::<GetBannedPersons>(context, id, op, data).await
+    }
+    UserOperation::BlockPerson => {
+      do_websocket_operation::<BlockPerson>(context, id, op, data).await
+    }
+    UserOperation::GetPersonMentions => {
+      do_websocket_operation::<GetPersonMentions>(context, id, op, data).await
+    }
+    UserOperation::MarkPersonMentionAsRead => {
+      do_websocket_operation::<MarkPersonMentionAsRead>(context, id, op, data).await
+    }
+    UserOperation::MarkCommentReplyAsRead => {
+      do_websocket_operation::<MarkCommentReplyAsRead>(context, id, op, data).await
+    }
+    UserOperation::MarkAllAsRead => {
+      do_websocket_operation::<MarkAllAsRead>(context, id, op, data).await
+    }
+    UserOperation::PasswordReset => {
+      do_websocket_operation::<PasswordReset>(context, id, op, data).await
+    }
+    UserOperation::PasswordChange => {
+      do_websocket_operation::<PasswordChangeAfterReset>(context, id, op, data).await
+    }
+    UserOperation::UserJoin => do_websocket_operation::<UserJoin>(context, id, op, data).await,
+    UserOperation::PostJoin => do_websocket_operation::<PostJoin>(context, id, op, data).await,
+    UserOperation::CommunityJoin => {
+      do_websocket_operation::<CommunityJoin>(context, id, op, data).await
+    }
+    UserOperation::ModJoin => do_websocket_operation::<ModJoin>(context, id, op, data).await,
+    UserOperation::SaveUserSettings => {
+      do_websocket_operation::<SaveUserSettings>(context, id, op, data).await
+    }
+    UserOperation::ChangePassword => {
+      do_websocket_operation::<ChangePassword>(context, id, op, data).await
+    }
+    UserOperation::GetReportCount => {
+      do_websocket_operation::<GetReportCount>(context, id, op, data).await
+    }
+    UserOperation::GetUnreadCount => {
+      do_websocket_operation::<GetUnreadCount>(context, id, op, data).await
+    }
+    UserOperation::VerifyEmail => {
+      do_websocket_operation::<VerifyEmail>(context, id, op, data).await
+    }
+
+    // Private Message ops
+    UserOperation::MarkPrivateMessageAsRead => {
+      do_websocket_operation::<MarkPrivateMessageAsRead>(context, id, op, data).await
+    }
+    UserOperation::CreatePrivateMessageReport => {
+      do_websocket_operation::<CreatePrivateMessageReport>(context, id, op, data).await
+    }
+    UserOperation::ResolvePrivateMessageReport => {
+      do_websocket_operation::<ResolvePrivateMessageReport>(context, id, op, data).await
+    }
+    UserOperation::ListPrivateMessageReports => {
+      do_websocket_operation::<ListPrivateMessageReports>(context, id, op, data).await
+    }
+
+    // Site ops
+    UserOperation::GetModlog => do_websocket_operation::<GetModlog>(context, id, op, data).await,
+    UserOperation::PurgePerson => {
+      do_websocket_operation::<PurgePerson>(context, id, op, data).await
+    }
+    UserOperation::PurgeCommunity => {
+      do_websocket_operation::<PurgeCommunity>(context, id, op, data).await
+    }
+    UserOperation::PurgePost => do_websocket_operation::<PurgePost>(context, id, op, data).await,
+    UserOperation::PurgeComment => {
+      do_websocket_operation::<PurgeComment>(context, id, op, data).await
+    }
+    UserOperation::TransferCommunity => {
+      do_websocket_operation::<TransferCommunity>(context, id, op, data).await
+    }
+    UserOperation::LeaveAdmin => do_websocket_operation::<LeaveAdmin>(context, id, op, data).await,
+
+    // Community ops
+    UserOperation::FollowCommunity => {
+      do_websocket_operation::<FollowCommunity>(context, id, op, data).await
+    }
+    UserOperation::BlockCommunity => {
+      do_websocket_operation::<BlockCommunity>(context, id, op, data).await
+    }
+    UserOperation::BanFromCommunity => {
+      do_websocket_operation::<BanFromCommunity>(context, id, op, data).await
+    }
+    UserOperation::AddModToCommunity => {
+      do_websocket_operation::<AddModToCommunity>(context, id, op, data).await
+    }
+
+    // Post ops
+    UserOperation::LockPost => do_websocket_operation::<LockPost>(context, id, op, data).await,
+    UserOperation::StickyPost => do_websocket_operation::<StickyPost>(context, id, op, data).await,
+    UserOperation::CreatePostLike => {
+      do_websocket_operation::<CreatePostLike>(context, id, op, data).await
+    }
+    UserOperation::MarkPostAsRead => {
+      do_websocket_operation::<MarkPostAsRead>(context, id, op, data).await
+    }
+    UserOperation::SavePost => do_websocket_operation::<SavePost>(context, id, op, data).await,
+    UserOperation::CreatePostReport => {
+      do_websocket_operation::<CreatePostReport>(context, id, op, data).await
+    }
+    UserOperation::ListPostReports => {
+      do_websocket_operation::<ListPostReports>(context, id, op, data).await
+    }
+    UserOperation::ResolvePostReport => {
+      do_websocket_operation::<ResolvePostReport>(context, id, op, data).await
+    }
+    UserOperation::GetSiteMetadata => {
+      do_websocket_operation::<GetSiteMetadata>(context, id, op, data).await
+    }
+
+    // Comment ops
+    UserOperation::SaveComment => {
+      do_websocket_operation::<SaveComment>(context, id, op, data).await
+    }
+    UserOperation::CreateCommentLike => {
+      do_websocket_operation::<CreateCommentLike>(context, id, op, data).await
+    }
+    UserOperation::CreateCommentReport => {
+      do_websocket_operation::<CreateCommentReport>(context, id, op, data).await
+    }
+    UserOperation::ListCommentReports => {
+      do_websocket_operation::<ListCommentReports>(context, id, op, data).await
+    }
+    UserOperation::ResolveCommentReport => {
+      do_websocket_operation::<ResolveCommentReport>(context, id, op, data).await
+    }
+  }
+}
+
+async fn do_websocket_operation<'a, 'b, Data>(
+  context: LemmyContext,
+  id: ConnectionId,
+  op: UserOperation,
+  data: &str,
+) -> result::Result<String, LemmyError>
+where
+  Data: Perform + SendActivity<Response = <Data as Perform>::Response>,
+  for<'de> Data: Deserialize<'de>,
+{
+  let parsed_data: Data = serde_json::from_str(data)?;
+  let res = parsed_data
+    .perform(&web::Data::new(context.clone()), Some(id))
+    .await?;
+  SendActivity::send_activity(&parsed_data, &res, &context).await?;
+  serialize_websocket_message(&op, &res)
+}
index 0c9fecf6927b75949e0cc0e3c51e710c0148eca8..89933a15e3289bb163c25fd51c7e6add80bebc3b 100644 (file)
@@ -9,13 +9,15 @@ use diesel::{
 };
 use diesel_async::RunQueryDsl;
 use lemmy_api_common::{
-  generate_followers_url,
-  generate_inbox_url,
-  generate_local_apub_endpoint,
-  generate_shared_inbox_url,
-  generate_site_inbox_url,
   lemmy_db_views::structs::SiteView,
-  EndpointType,
+  utils::{
+    generate_followers_url,
+    generate_inbox_url,
+    generate_local_apub_endpoint,
+    generate_shared_inbox_url,
+    generate_site_inbox_url,
+    EndpointType,
+  },
 };
 use lemmy_db_schema::{
   source::{
index e4b8e8e3293e9f86d4bcc589a66d6201b568ee4d..c60c1823a3dbf7066490a52a67318a6fffca17d5 100644 (file)
@@ -5,8 +5,8 @@ use actix::prelude::*;
 use actix_web::{middleware, web::Data, App, HttpServer, Result};
 use diesel_migrations::EmbeddedMigrations;
 use doku::json::{AutoComments, CommentsStyle, Formatting, ObjectsStyle};
-use lemmy_api::match_websocket_operation;
 use lemmy_api_common::{
+  context::LemmyContext,
   lemmy_db_views::structs::SiteView,
   request::build_user_agent,
   utils::{
@@ -14,9 +14,7 @@ use lemmy_api_common::{
     local_site_rate_limit_to_rate_limit_config,
   },
   websocket::chat_server::ChatServer,
-  LemmyContext,
 };
-use lemmy_api_crud::match_websocket_operation_crud;
 use lemmy_db_schema::{
   source::secret::Secret,
   utils::{build_db_pool, get_database_url, run_migrations},
@@ -24,6 +22,11 @@ use lemmy_db_schema::{
 use lemmy_routes::{feeds, images, nodeinfo, webfinger};
 use lemmy_server::{
   api_routes,
+  api_routes::{
+    match_websocket_operation,
+    match_websocket_operation_apub,
+    match_websocket_operation_crud,
+  },
   code_migrations::run_advanced_migrations,
   init_logging,
   root_span_builder::QuieterRootSpanBuilder,
@@ -136,6 +139,7 @@ async fn main() -> Result<(), LemmyError> {
     pool.clone(),
     |c, i, o, d| Box::pin(match_websocket_operation(c, i, o, d)),
     |c, i, o, d| Box::pin(match_websocket_operation_crud(c, i, o, d)),
+    |c, i, o, d| Box::pin(match_websocket_operation_apub(c, i, o, d)),
     client.clone(),
     settings.clone(),
     secret.clone(),