]> Untitled Git - lemmy.git/commitdiff
Remove chatserver (#2919)
authorNutomic <me@nutomic.com>
Tue, 6 Jun 2023 16:27:22 +0000 (18:27 +0200)
committerGitHub <noreply@github.com>
Tue, 6 Jun 2023 16:27:22 +0000 (12:27 -0400)
* Remove chatserver

* fix clippy

* Remove captchas (fixes #2922)

* fix prettier

* fix api_common build

* cargo fmt

129 files changed:
Cargo.lock
Cargo.toml
crates/api/Cargo.toml
crates/api/src/comment/distinguish.rs
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 [deleted file]
crates/api/src/local_user/list_banned.rs
crates/api/src/local_user/login.rs
crates/api/src/local_user/mod.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/feature.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_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/federated_instances.rs
crates/api/src/site/leave_admin.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 [deleted file]
crates/api_common/Cargo.toml
crates/api_common/src/build_response.rs [new file with mode: 0644]
crates/api_common/src/community.rs
crates/api_common/src/context.rs
crates/api_common/src/lib.rs
crates/api_common/src/post.rs
crates/api_common/src/site.rs
crates/api_common/src/websocket/chat_server.rs [deleted file]
crates/api_common/src/websocket/handlers/captcha.rs [deleted file]
crates/api_common/src/websocket/handlers/connect.rs [deleted file]
crates/api_common/src/websocket/handlers/join_rooms.rs [deleted file]
crates/api_common/src/websocket/handlers/messages.rs [deleted file]
crates/api_common/src/websocket/handlers/mod.rs [deleted file]
crates/api_common/src/websocket/handlers/online_users.rs [deleted file]
crates/api_common/src/websocket/mod.rs [deleted file]
crates/api_common/src/websocket/send.rs [deleted file]
crates/api_common/src/websocket/structs.rs [deleted file]
crates/api_crud/src/comment/create.rs
crates/api_crud/src/comment/delete.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/remove.rs
crates/api_crud/src/community/update.rs
crates/api_crud/src/custom_emoji/create.rs
crates/api_crud/src/custom_emoji/delete.rs
crates/api_crud/src/custom_emoji/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/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/apub/Cargo.toml
crates/apub/assets/friendica/activities/create_page_1.json
crates/apub/assets/mastodon/objects/person.json
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/mod.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/following/accept.rs
crates/apub/src/activities/unfederated.rs
crates/apub/src/activities/voting/mod.rs
crates/apub/src/api/list_comments.rs
crates/apub/src/api/list_posts.rs
crates/apub/src/api/mod.rs
crates/apub/src/api/read_community.rs
crates/apub/src/api/read_person.rs
crates/apub/src/api/resolve_object.rs
crates/apub/src/api/search.rs
crates/apub/src/objects/mod.rs
src/api_routes_http.rs
src/lib.rs

index 159912e478f5e9c8a4ecf61bc2b41baeb0268c75..17d8548572d0a75ff6eb4e92b860c2b38dccfd4d 100644 (file)
@@ -61,30 +61,6 @@ dependencies = [
  "url",
 ]
 
-[[package]]
-name = "actix"
-version = "0.13.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f728064aca1c318585bf4bb04ffcfac9e75e508ab4e8b1bd9ba5dfe04e2cbed5"
-dependencies = [
- "actix-rt",
- "actix_derive",
- "bitflags",
- "bytes",
- "crossbeam-channel",
- "futures-core",
- "futures-sink",
- "futures-task",
- "futures-util",
- "log",
- "once_cell",
- "parking_lot 0.12.1",
- "pin-project-lite",
- "smallvec",
- "tokio",
- "tokio-util 0.7.4",
-]
-
 [[package]]
 name = "actix-codec"
 version = "0.5.0"
@@ -332,17 +308,6 @@ dependencies = [
  "syn 1.0.103",
 ]
 
-[[package]]
-name = "actix_derive"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6d44b8fee1ced9671ba043476deddef739dd0959bf77030b26b738cc591737a7"
-dependencies = [
- "proc-macro2 1.0.47",
- "quote 1.0.21",
- "syn 1.0.103",
-]
-
 [[package]]
 name = "addr2line"
 version = "0.19.0"
@@ -2537,7 +2502,6 @@ dependencies = [
  "base64",
  "bcrypt",
  "captcha",
- "chrono",
  "lemmy_api_common",
  "lemmy_db_schema",
  "lemmy_db_views",
@@ -2555,8 +2519,8 @@ dependencies = [
 name = "lemmy_api_common"
 version = "0.17.1"
 dependencies = [
- "actix",
  "actix-rt",
+ "actix-web",
  "anyhow",
  "chrono",
  "encoding",
@@ -2567,16 +2531,12 @@ dependencies = [
  "lemmy_db_views_moderator",
  "lemmy_utils",
  "percent-encoding",
- "rand 0.8.5",
  "regex",
  "reqwest",
  "reqwest-middleware",
  "rosetta-i18n",
  "serde",
- "serde_json",
  "serde_with",
- "strum",
- "strum_macros",
  "tracing",
  "ts-rs",
  "url",
@@ -2608,7 +2568,6 @@ name = "lemmy_apub"
 version = "0.17.1"
 dependencies = [
  "activitypub_federation",
- "actix",
  "actix-rt",
  "actix-web",
  "anyhow",
@@ -2746,7 +2705,6 @@ name = "lemmy_server"
 version = "0.17.1"
 dependencies = [
  "activitypub_federation",
- "actix",
  "actix-cors",
  "actix-web",
  "clokwerk",
index 344e4646fa4f1e2dcd901ca93127b0ef2823d9a0..eeeb9c32b036b4a9f94de9fc6084407874c2a08f 100644 (file)
@@ -106,7 +106,6 @@ rosetta-i18n = "0.1.2"
 rand = "0.8.5"
 opentelemetry = { version = "0.17.0", features = ["rt-tokio"] }
 tracing-opentelemetry = { version = "0.17.2" }
-actix = "0.13"
 ts-rs = { version = "6.2", features = ["serde-compat", "format", "chrono-impl"] }
 
 [dependencies]
@@ -134,7 +133,6 @@ reqwest-tracing = { workspace = true }
 clokwerk = { workspace = true }
 doku = { workspace = true }
 serde_json = { workspace = true }
-actix = { workspace = true }
 tracing-opentelemetry = { workspace = true, optional = true }
 opentelemetry = { workspace = true, optional = true }
 console-subscriber = { version = "0.1.8", optional = true }
index 69f1b28e468e7d449f39dcea953d2a73f7039d72..2488f2c2c93caf69f195387a1d66787a8cb1086f 100644 (file)
@@ -21,7 +21,6 @@ lemmy_db_views_moderator = { workspace = true, features = ["full"] }
 lemmy_db_views_actor = { workspace = true, features = ["full"] }
 lemmy_api_common = { workspace = true, features = ["full"] }
 bcrypt = { workspace = true }
-chrono = { workspace = true }
 serde = { workspace = true }
 actix-web = { workspace = true }
 base64 = { workspace = true }
index 73e1469e3f6de23c1c57e2b637bb892fc4c80f60..17f45bfd4b292bf4aa3779dcdb401055cf639e96 100644 (file)
@@ -10,18 +10,14 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_db_views::structs::CommentView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for DistinguishComment {
   type Response = CommentResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<CommentResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
     let data: &DistinguishComment = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index b6e7e504327da40c0273b143c2a863824a58d216..6c4bdebc79cc71b76cb62a6159c37fc2f9c9d0ec 100644 (file)
@@ -1,10 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_comment_response,
   comment::{CommentResponse, CreateCommentLike},
   context::LemmyContext,
   utils::{check_community_ban, check_downvotes_enabled, local_user_view_from_jwt},
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   newtypes::LocalUserId,
@@ -16,18 +16,14 @@ use lemmy_db_schema::{
   traits::Likeable,
 };
 use lemmy_db_views::structs::{CommentView, LocalUserView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for CreateCommentLike {
   type Response = CommentResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommentResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
     let data: &CreateCommentLike = self;
     let local_site = LocalSite::read(context.pool()).await?;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -76,15 +72,13 @@ impl Perform for CreateCommentLike {
         .map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
     }
 
-    context
-      .send_comment_ws_message(
-        &UserOperation::CreateCommentLike,
-        data.comment_id,
-        websocket_id,
-        None,
-        Some(local_user_view.person.id),
-        recipient_ids,
-      )
-      .await
+    build_comment_response(
+      context,
+      comment_id,
+      Some(local_user_view),
+      None,
+      recipient_ids,
+    )
+    .await
   }
 }
index d52b3322d668e18815c7fd9374d4d1dea0c3d280..70c9745f8b884bb42af1bbe4c18ec9e4f5d7b205 100644 (file)
@@ -10,18 +10,14 @@ use lemmy_db_schema::{
   traits::Saveable,
 };
 use lemmy_db_views::structs::CommentView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for SaveComment {
   type Response = CommentResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<CommentResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
     let data: &SaveComment = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index 8d016bf53260f33ac4a7cee4a035e8e976dd8988..8ef975786b6f06125dcefcec2266fac4efc723d2 100644 (file)
@@ -4,7 +4,6 @@ use lemmy_api_common::{
   comment::{CommentReportResponse, CreateCommentReport},
   context::LemmyContext,
   utils::{check_community_ban, local_user_view_from_jwt, send_new_report_email_to_admins},
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::{
@@ -14,18 +13,17 @@ use lemmy_db_schema::{
   traits::Reportable,
 };
 use lemmy_db_views::structs::{CommentReportView, CommentView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 /// Creates a comment report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for CreateCommentReport {
   type Response = CommentReportResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
   ) -> Result<CommentReportResponse, LemmyError> {
     let data: &CreateCommentReport = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -64,17 +62,8 @@ impl Perform for CreateCommentReport {
       .await?;
     }
 
-    let res = CommentReportResponse {
+    Ok(CommentReportResponse {
       comment_report_view,
-    };
-
-    context.send_mod_ws_message(
-      &UserOperation::CreateCommentReport,
-      &res,
-      comment_view.community.id,
-      websocket_id,
-    )?;
-
-    Ok(res)
+    })
   }
 }
index 2cd9ca1bdff3bb434db3cfde004e318992aa3280..d8a4221dbd1f1fa0f6937041403695e2c7908b31 100644 (file)
@@ -6,7 +6,7 @@ use lemmy_api_common::{
   utils::local_user_view_from_jwt,
 };
 use lemmy_db_views::comment_report_view::CommentReportQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 /// Lists comment reports for a community if an id is supplied
 /// or returns all comment reports for communities a user moderates
@@ -14,11 +14,10 @@ use lemmy_utils::{error::LemmyError, ConnectionId};
 impl Perform for ListCommentReports {
   type Response = ListCommentReportsResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<ListCommentReportsResponse, LemmyError> {
     let data: &ListCommentReports = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -42,8 +41,6 @@ impl Perform for ListCommentReports {
       .list()
       .await?;
 
-    let res = ListCommentReportsResponse { comment_reports };
-
-    Ok(res)
+    Ok(ListCommentReportsResponse { comment_reports })
   }
 }
index 4ba45481f2d2b5f58d2c0997a45a196b7fff3ba7..5f1ae97dddca86d890b2e44589f68de67f5d9394 100644 (file)
@@ -4,22 +4,20 @@ use lemmy_api_common::{
   comment::{CommentReportResponse, ResolveCommentReport},
   context::LemmyContext,
   utils::{is_mod_or_admin, local_user_view_from_jwt},
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
 use lemmy_db_views::structs::CommentReportView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 /// Resolves or unresolves a comment report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for ResolveCommentReport {
   type Response = CommentReportResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
   ) -> Result<CommentReportResponse, LemmyError> {
     let data: &ResolveCommentReport = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -44,17 +42,8 @@ impl Perform for ResolveCommentReport {
     let report_id = data.report_id;
     let comment_report_view = CommentReportView::read(context.pool(), report_id, person_id).await?;
 
-    let res = CommentReportResponse {
+    Ok(CommentReportResponse {
       comment_report_view,
-    };
-
-    context.send_mod_ws_message(
-      &UserOperation::ResolveCommentReport,
-      &res,
-      report.community.id,
-      websocket_id,
-    )?;
-
-    Ok(res)
+    })
   }
 }
index 80c470de967365bc53fdfd315d561b539c242a86..a7afd952d549b59ce15104e820871271598d1310 100644 (file)
@@ -4,7 +4,6 @@ use lemmy_api_common::{
   community::{AddModToCommunity, AddModToCommunityResponse},
   context::LemmyContext,
   utils::{is_mod_or_admin, local_user_view_from_jwt},
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::{
@@ -14,17 +13,16 @@ use lemmy_db_schema::{
   traits::{Crud, Joinable},
 };
 use lemmy_db_views_actor::structs::CommunityModeratorView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for AddModToCommunity {
   type Response = AddModToCommunityResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
   ) -> Result<AddModToCommunityResponse, LemmyError> {
     let data: &AddModToCommunity = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -68,14 +66,6 @@ impl Perform for AddModToCommunity {
     let community_id = data.community_id;
     let moderators = CommunityModeratorView::for_community(context.pool(), community_id).await?;
 
-    let res = AddModToCommunityResponse { moderators };
-    context.send_mod_ws_message(
-      &UserOperation::AddModToCommunity,
-      &res,
-      community_id,
-      websocket_id,
-    )?;
-
-    Ok(res)
+    Ok(AddModToCommunityResponse { moderators })
   }
 }
index 47cb6798fa7f01d0be04c2f787181eb8688a980b..a0fd7bf187b0036ed9cd892e0da0b18c8c0b9377 100644 (file)
@@ -4,11 +4,6 @@ use lemmy_api_common::{
   community::{BanFromCommunity, BanFromCommunityResponse},
   context::LemmyContext,
   utils::{is_mod_or_admin, local_user_view_from_jwt, remove_user_data_in_community},
-  websocket::{
-    handlers::messages::SendCommunityRoomMessage,
-    serialize_websocket_message,
-    UserOperation,
-  },
 };
 use lemmy_db_schema::{
   source::{
@@ -26,18 +21,16 @@ use lemmy_db_views_actor::structs::PersonView;
 use lemmy_utils::{
   error::LemmyError,
   utils::{time::naive_from_unix, validation::is_valid_body_field},
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl Perform for BanFromCommunity {
   type Response = BanFromCommunityResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
   ) -> Result<BanFromCommunityResponse, LemmyError> {
     let data: &BanFromCommunity = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -98,19 +91,9 @@ impl Perform for BanFromCommunity {
     let person_id = data.person_id;
     let person_view = PersonView::read(context.pool(), person_id).await?;
 
-    let res = BanFromCommunityResponse {
+    Ok(BanFromCommunityResponse {
       person_view,
       banned: data.ban,
-    };
-
-    // A custom ban message
-    let message = serialize_websocket_message(&UserOperation::BanFromCommunity, &res)?;
-    context.chat_server().do_send(SendCommunityRoomMessage {
-      community_id,
-      message,
-      websocket_id,
-    });
-
-    Ok(res)
+    })
   }
 }
index 21112971f127a36a8115a8353926ae46816f458e..fe3fb6e0791b5630d6b293cc5ba8d05b1bde40fe 100644 (file)
@@ -13,17 +13,16 @@ use lemmy_db_schema::{
   traits::{Blockable, Followable},
 };
 use lemmy_db_views_actor::structs::CommunityView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for BlockCommunity {
   type Response = BlockCommunityResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<BlockCommunityResponse, LemmyError> {
     let data: &BlockCommunity = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
index 9e4efb33f6bc5c908ba7c2cd6bd9e3327fbf7217..ae1ed6a4b0841c8251718c5d0f677e708eb52fa7 100644 (file)
@@ -13,18 +13,14 @@ use lemmy_db_schema::{
   traits::{Crud, Followable},
 };
 use lemmy_db_views_actor::structs::CommunityView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for FollowCommunity {
   type Response = CommunityResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<CommunityResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
     let data: &FollowCommunity = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index e33bf32caecda8d81fd80c9c392c19177447c806..f8d4b1fd7d200b97fe79063614e5a60d21074e23 100644 (file)
@@ -1,10 +1,10 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_community_response,
   community::{CommunityResponse, HideCommunity},
   context::LemmyContext,
   utils::{is_admin, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -13,18 +13,14 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for HideCommunity {
   type Response = CommunityResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommunityResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
     let data: &HideCommunity = self;
 
     // Verify its a admin (only admin can hide or unhide it)
@@ -49,13 +45,6 @@ impl Perform for HideCommunity {
 
     ModHideCommunity::create(context.pool(), &mod_hide_community_form).await?;
 
-    context
-      .send_community_ws_message(
-        &UserOperationCrud::EditCommunity,
-        data.community_id,
-        websocket_id,
-        None,
-      )
-      .await
+    build_community_response(context, local_user_view, community_id).await
   }
 }
index def3df0fa9d7f7298c1c0e8535c2d28f9b4b5e9c..10ba1c4fac0f8481c344e64b1e8d136e9d643cf8 100644 (file)
@@ -14,7 +14,7 @@ use lemmy_db_schema::{
   traits::{Crud, Joinable},
 };
 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
-use lemmy_utils::{error::LemmyError, location_info, ConnectionId};
+use lemmy_utils::{error::LemmyError, location_info};
 
 // TODO: we dont do anything for federation here, it should be updated the next time the community
 //       gets fetched. i hope we can get rid of the community creator role soon.
@@ -22,11 +22,10 @@ use lemmy_utils::{error::LemmyError, location_info, ConnectionId};
 impl Perform for TransferCommunity {
   type Response = GetCommunityResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<GetCommunityResponse, LemmyError> {
     let data: &TransferCommunity = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -95,7 +94,6 @@ impl Perform for TransferCommunity {
       community_view,
       site: None,
       moderators,
-      online: 0,
       discussion_languages: vec![],
     })
   }
index 5c23ec34528399b461f96a32ae725319c7b27c19..9ff1677d0ed4950e5e28f81473b10661a9b892eb 100644 (file)
@@ -1,8 +1,7 @@
 use actix_web::web::Data;
-use captcha::Captcha;
 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::slurs::check_slurs, ConnectionId};
+use lemmy_utils::{error::LemmyError, utils::slurs::check_slurs};
 
 mod comment;
 mod comment_report;
@@ -13,32 +12,12 @@ mod post_report;
 mod private_message;
 mod private_message_report;
 mod site;
-mod websocket;
 
 #[async_trait::async_trait(?Send)]
 pub trait Perform {
   type Response: serde::ser::Serialize + Send;
 
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError>;
-}
-
-/// 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();
-
-  let mut concat_letters: Vec<u8> = Vec::new();
-
-  for letter in letters {
-    let bytes = letter.unwrap_or_default();
-    concat_letters.extend(bytes);
-  }
-
-  // Convert to base64
-  base64::encode(concat_letters)
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
 }
 
 /// Check size of report and remove whitespace
index 5de584650f0dabc3836b5aa346ec00c1523c731d..0d2db3771c7c82136fe37e0448603292493eeb8b 100644 (file)
@@ -4,7 +4,6 @@ use lemmy_api_common::{
   context::LemmyContext,
   person::{AddAdmin, AddAdminResponse},
   utils::{is_admin, local_user_view_from_jwt},
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::{
@@ -14,18 +13,14 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_db_views_actor::structs::PersonView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for AddAdmin {
   type Response = AddAdminResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<AddAdminResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<AddAdminResponse, LemmyError> {
     let data: &AddAdmin = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -53,10 +48,6 @@ impl Perform for AddAdmin {
 
     let admins = PersonView::admins(context.pool()).await?;
 
-    let res = AddAdminResponse { admins };
-
-    context.send_all_ws_message(&UserOperation::AddAdmin, &res, websocket_id)?;
-
-    Ok(res)
+    Ok(AddAdminResponse { admins })
   }
 }
index 014f98b8d58c87c6f55c0e7334eafc15b39b1539..452557d2c64ed98d0a451c160edeadc471c1055e 100644 (file)
@@ -4,7 +4,6 @@ use lemmy_api_common::{
   context::LemmyContext,
   person::{BanPerson, BanPersonResponse},
   utils::{is_admin, local_user_view_from_jwt, remove_user_data},
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::{
@@ -17,19 +16,14 @@ use lemmy_db_views_actor::structs::PersonView;
 use lemmy_utils::{
   error::LemmyError,
   utils::{time::naive_from_unix, validation::is_valid_body_field},
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl Perform for BanPerson {
   type Response = BanPersonResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<BanPersonResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<BanPersonResponse, LemmyError> {
     let data: &BanPerson = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -79,13 +73,9 @@ impl Perform for BanPerson {
     let person_id = data.person_id;
     let person_view = PersonView::read(context.pool(), person_id).await?;
 
-    let res = BanPersonResponse {
+    Ok(BanPersonResponse {
       person_view,
       banned: data.ban,
-    };
-
-    context.send_all_ws_message(&UserOperation::BanPerson, &res, websocket_id)?;
-
-    Ok(res)
+    })
   }
 }
index 5a4c9dca06cc24d979904a8e53e88ead8f824143..c9eaa272587935bf3c84ab8c7c9273ffb2e80cfe 100644 (file)
@@ -10,18 +10,14 @@ use lemmy_db_schema::{
   traits::Blockable,
 };
 use lemmy_db_views_actor::structs::PersonView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for BlockPerson {
   type Response = BlockPersonResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<BlockPersonResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<BlockPersonResponse, LemmyError> {
     let data: &BlockPerson = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -54,11 +50,9 @@ impl Perform for BlockPerson {
         .map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
     }
 
-    let res = BlockPersonResponse {
+    Ok(BlockPersonResponse {
       person_view: target_person_view,
       blocked: data.block,
-    };
-
-    Ok(res)
+    })
   }
 }
index 2b486a5ed590111b6e036b3877870902aef42ea7..60e0b960d462a574530cd7831a4e3e407b9f1331 100644 (file)
@@ -7,18 +7,14 @@ use lemmy_api_common::{
   utils::{local_user_view_from_jwt, password_length_check},
 };
 use lemmy_db_schema::source::local_user::LocalUser;
-use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
+use lemmy_utils::{claims::Claims, error::LemmyError};
 
 #[async_trait::async_trait(?Send)]
 impl Perform for ChangePassword {
   type Response = LoginResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<LoginResponse, LemmyError> {
+  #[tracing::instrument(skip(self, context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
     let data: &ChangePassword = self;
     let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
 
index 04571e47b05954b3aa740537cb95fcb72eb03f8a..de05f8e59848df0bf380270c59e665cec114425b 100644 (file)
@@ -10,18 +10,14 @@ use lemmy_db_schema::{
   RegistrationMode,
 };
 use lemmy_db_views::structs::SiteView;
-use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
+use lemmy_utils::{claims::Claims, error::LemmyError};
 
 #[async_trait::async_trait(?Send)]
 impl Perform for PasswordChangeAfterReset {
   type Response = LoginResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<LoginResponse, LemmyError> {
+  #[tracing::instrument(skip(self, context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
     let data: &PasswordChangeAfterReset = self;
 
     // Fetch the user_id from the token
diff --git a/crates/api/src/local_user/get_captcha.rs b/crates/api/src/local_user/get_captcha.rs
deleted file mode 100644 (file)
index 00ec45a..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-use crate::{captcha_as_wav_base64, Perform};
-use actix_web::web::Data;
-use captcha::{gen, Difficulty};
-use chrono::Duration;
-use lemmy_api_common::{
-  context::LemmyContext,
-  person::{CaptchaResponse, GetCaptcha, GetCaptchaResponse},
-  websocket::{handlers::captcha::AddCaptcha, structs::CaptchaItem},
-};
-use lemmy_db_schema::{source::local_site::LocalSite, utils::naive_now};
-use lemmy_utils::{error::LemmyError, ConnectionId};
-
-#[async_trait::async_trait(?Send)]
-impl Perform for GetCaptcha {
-  type Response = GetCaptchaResponse;
-
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
-    let local_site = LocalSite::read(context.pool()).await?;
-
-    if !local_site.captcha_enabled {
-      return Ok(GetCaptchaResponse { ok: None });
-    }
-
-    let captcha = gen(match local_site.captcha_difficulty.as_str() {
-      "easy" => Difficulty::Easy,
-      "hard" => Difficulty::Hard,
-      _ => Difficulty::Medium,
-    });
-
-    let answer = captcha.chars_as_string();
-
-    let png = captcha.as_base64().expect("failed to generate captcha");
-
-    let uuid = uuid::Uuid::new_v4().to_string();
-
-    let wav = captcha_as_wav_base64(&captcha);
-
-    let captcha_item = CaptchaItem {
-      answer,
-      uuid: uuid.clone(),
-      expires: naive_now() + Duration::minutes(10), // expires in 10 minutes
-    };
-
-    // Stores the captcha item on the queue
-    context.chat_server().do_send(AddCaptcha {
-      captcha: captcha_item,
-    });
-
-    Ok(GetCaptchaResponse {
-      ok: Some(CaptchaResponse { png, wav, uuid }),
-    })
-  }
-}
index e1d0f6e757d0d2befb896c6ad5a817aeb21afc80..5e2c027ba00902696921d3c4b9d45e970789f5d2 100644 (file)
@@ -6,17 +6,13 @@ use lemmy_api_common::{
   utils::{is_admin, local_user_view_from_jwt},
 };
 use lemmy_db_views_actor::structs::PersonView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetBannedPersons {
   type Response = BannedPersonsResponse;
 
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data: &GetBannedPersons = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -25,8 +21,6 @@ impl Perform for GetBannedPersons {
 
     let banned = PersonView::banned(context.pool()).await?;
 
-    let res = Self::Response { banned };
-
-    Ok(res)
+    Ok(Self::Response { banned })
   }
 }
index 25323c45307dba1503bff429ba6573c670aec51c..9f5e587443b40495740f88b7e8b23ef136bfa0de 100644 (file)
@@ -7,23 +7,14 @@ use lemmy_api_common::{
   utils::{check_registration_application, check_user_valid},
 };
 use lemmy_db_views::structs::{LocalUserView, SiteView};
-use lemmy_utils::{
-  claims::Claims,
-  error::LemmyError,
-  utils::validation::check_totp_2fa_valid,
-  ConnectionId,
-};
+use lemmy_utils::{claims::Claims, error::LemmyError, utils::validation::check_totp_2fa_valid};
 
 #[async_trait::async_trait(?Send)]
 impl Perform for Login {
   type Response = LoginResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<LoginResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
     let data: &Login = self;
 
     let site_view = SiteView::read_local(context.pool()).await?;
index 3a92beda57e21d7f5cfb928da9d47e684b0fd6f0..9244f825dd64941ffd0908a79bdd194064a55ffd 100644 (file)
@@ -3,7 +3,6 @@ mod ban_person;
 mod block;
 mod change_password;
 mod change_password_after_reset;
-mod get_captcha;
 mod list_banned;
 mod login;
 mod notifications;
index fbafdb52aa58e2caa338199af8c4762f31301355..4c8d2cf555fc4805cdb44d300eb9de3528ce9609 100644 (file)
@@ -6,17 +6,16 @@ use lemmy_api_common::{
   utils::local_user_view_from_jwt,
 };
 use lemmy_db_views_actor::person_mention_view::PersonMentionQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetPersonMentions {
   type Response = GetPersonMentionsResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<GetPersonMentionsResponse, LemmyError> {
     let data: &GetPersonMentions = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
index 797b6f8d464329710d0bfed46eb27134123f6309..6d1d8f0bd3ea871b1b11cc68362e6f9986d59555 100644 (file)
@@ -6,18 +6,14 @@ use lemmy_api_common::{
   utils::local_user_view_from_jwt,
 };
 use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetReplies {
   type Response = GetRepliesResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetRepliesResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetRepliesResponse, LemmyError> {
     let data: &GetReplies = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index dfda897a9a578bcdff38a76dddf95ed8c3d0df37..cc2999698105b0aca6cf6599c356c82f8da07b10 100644 (file)
@@ -10,18 +10,14 @@ use lemmy_db_schema::source::{
   person_mention::PersonMention,
   private_message::PrivateMessage,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for MarkAllAsRead {
   type Response = GetRepliesResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetRepliesResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetRepliesResponse, LemmyError> {
     let data: &MarkAllAsRead = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let person_id = local_user_view.person.id;
index 80781e72a2beefa6cb6b4e901555dd89b2f3402b..dd3c413f29cbaf8554c01c9432d72081eb5e1137 100644 (file)
@@ -10,17 +10,16 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_db_views_actor::structs::PersonMentionView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for MarkPersonMentionAsRead {
   type Response = PersonMentionResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<PersonMentionResponse, LemmyError> {
     let data: &MarkPersonMentionAsRead = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
index 1e3fad19dcf637de9894a010f27908be67fdc736..a8291cd5074f26a0b02f23c2a24aeb10842e2159 100644 (file)
@@ -10,17 +10,16 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_db_views_actor::structs::CommentReplyView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for MarkCommentReplyAsRead {
   type Response = CommentReplyResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<CommentReplyResponse, LemmyError> {
     let data = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
index 523e9a73febf505f507f4a743869676987f48c3b..21e584d51c55c76b5ee7f77a85485b54e7775658 100644 (file)
@@ -7,18 +7,14 @@ use lemmy_api_common::{
 };
 use lemmy_db_views::structs::PrivateMessageView;
 use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetUnreadCount {
   type Response = GetUnreadCountResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -31,12 +27,10 @@ impl Perform for GetUnreadCount {
     let private_messages =
       PrivateMessageView::get_unread_messages(context.pool(), person_id).await?;
 
-    let res = Self::Response {
+    Ok(Self::Response {
       replies,
       mentions,
       private_messages,
-    };
-
-    Ok(res)
+    })
   }
 }
index b2f4912cc102819e4ae2fe709b09f2c16eea3695..c09280d80f4cc970c1c8f32675502e1ffe7685b5 100644 (file)
@@ -6,17 +6,16 @@ use lemmy_api_common::{
   utils::local_user_view_from_jwt,
 };
 use lemmy_db_views::structs::{CommentReportView, PostReportView, PrivateMessageReportView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetReportCount {
   type Response = GetReportCountResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<GetReportCountResponse, LemmyError> {
     let data: &GetReportCount = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -37,13 +36,11 @@ impl Perform for GetReportCount {
       None
     };
 
-    let res = GetReportCountResponse {
+    Ok(GetReportCountResponse {
       community_id,
       comment_reports,
       post_reports,
       private_message_reports,
-    };
-
-    Ok(res)
+    })
   }
 }
index 5d0e9d88bb3840209602b8d639f60c5efa1b48c7..3c07b2e4d4c94f6fc32a0b91b4a182a2b52c98f5 100644 (file)
@@ -6,17 +6,16 @@ use lemmy_api_common::{
   utils::send_password_reset_email,
 };
 use lemmy_db_views::structs::LocalUserView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for PasswordReset {
   type Response = PasswordResetResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
+  #[tracing::instrument(skip(self, context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<PasswordResetResponse, LemmyError> {
     let data: &PasswordReset = self;
 
index a04086125c72462e8f263b82f7fbf0b95aca2d63..e74266fc9dd3e13154bdbc240ade484ff43c9f89 100644 (file)
@@ -25,19 +25,14 @@ use lemmy_utils::{
     is_valid_display_name,
     is_valid_matrix_id,
   },
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl Perform for SaveUserSettings {
   type Response = LoginResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<LoginResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
     let data: &SaveUserSettings = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let site_view = SiteView::read_local(context.pool()).await?;
index fb82b716bb543c0d2d5c2a8130e60667f96b9ae0..80befc5a8344a79ee4173c87c8850f0896f51959 100644 (file)
@@ -19,11 +19,7 @@ use lemmy_utils::error::LemmyError;
 impl Perform for VerifyEmail {
   type Response = VerifyEmailResponse;
 
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<usize>,
-  ) -> Result<Self::Response, LemmyError> {
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let token = self.token.clone();
     let verification = EmailVerification::read_for_token(context.pool(), &token)
       .await
index 6d9f05f071386ade154919c2f144e696326839a0..3c9e1a1c04adeb3c3760904d26253740ed190a47 100644 (file)
@@ -1,6 +1,7 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_post_response,
   context::LemmyContext,
   post::{FeaturePost, PostResponse},
   utils::{
@@ -10,7 +11,6 @@ use lemmy_api_common::{
     is_mod_or_admin,
     local_user_view_from_jwt,
   },
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::{
@@ -20,18 +20,14 @@ use lemmy_db_schema::{
   traits::Crud,
   PostFeatureType,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for FeaturePost {
   type Response = PostResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
     let data: &FeaturePost = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -81,13 +77,12 @@ impl Perform for FeaturePost {
 
     ModFeaturePost::create(context.pool(), &form).await?;
 
-    context
-      .send_post_ws_message(
-        &UserOperation::FeaturePost,
-        data.post_id,
-        websocket_id,
-        Some(local_user_view.person.id),
-      )
-      .await
+    build_post_response(
+      context,
+      orig_post.community_id,
+      local_user_view.person.id,
+      post_id,
+    )
+    .await
   }
 }
index eaf111eba7beb1f5629bbebeeea853ca605b4e51..a67ea3f6fbbde8fac3f58420cb9f9e4a40a01018 100644 (file)
@@ -5,17 +5,16 @@ use lemmy_api_common::{
   post::{GetSiteMetadata, GetSiteMetadataResponse},
   request::fetch_site_metadata,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetSiteMetadata {
   type Response = GetSiteMetadataResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<GetSiteMetadataResponse, LemmyError> {
     let data: &Self = self;
 
index 2413a983cafbfc905a37a9148dfb71975d293935..5811107c2994a0a48a0de974fd520e9960900455 100644 (file)
@@ -1,6 +1,7 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_post_response,
   context::LemmyContext,
   post::{CreatePostLike, PostResponse},
   utils::{
@@ -10,7 +11,6 @@ use lemmy_api_common::{
     local_user_view_from_jwt,
     mark_post_as_read,
   },
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::{
@@ -19,18 +19,14 @@ use lemmy_db_schema::{
   },
   traits::{Crud, Likeable},
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for CreatePostLike {
   type Response = PostResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
     let data: &CreatePostLike = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
@@ -67,13 +63,12 @@ impl Perform for CreatePostLike {
     // Mark the post as read
     mark_post_as_read(person_id, post_id, context.pool()).await?;
 
-    context
-      .send_post_ws_message(
-        &UserOperation::CreatePostLike,
-        data.post_id,
-        websocket_id,
-        Some(local_user_view.person.id),
-      )
-      .await
+    build_post_response(
+      context,
+      post.community_id,
+      local_user_view.person.id,
+      post_id,
+    )
+    .await
   }
 }
index 4264364002d6eeacaa6c10cb9cfe23d331824ff8..5266d5441e89f13e37316cf56d610b606eaf3859 100644 (file)
@@ -1,6 +1,7 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_post_response,
   context::LemmyContext,
   post::{LockPost, PostResponse},
   utils::{
@@ -9,7 +10,6 @@ use lemmy_api_common::{
     is_mod_or_admin,
     local_user_view_from_jwt,
   },
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::{
@@ -18,18 +18,14 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for LockPost {
   type Response = PostResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
     let data: &LockPost = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -70,13 +66,12 @@ impl Perform for LockPost {
     };
     ModLockPost::create(context.pool(), &form).await?;
 
-    context
-      .send_post_ws_message(
-        &UserOperation::LockPost,
-        data.post_id,
-        websocket_id,
-        Some(local_user_view.person.id),
-      )
-      .await
+    build_post_response(
+      context,
+      orig_post.community_id,
+      local_user_view.person.id,
+      post_id,
+    )
+    .await
   }
 }
index e53d7a78ffbfb33f896100b997dbc36a55ad29b0..0e013a88363912dda3997841fe57ed007a5ce25c 100644 (file)
@@ -6,18 +6,14 @@ use lemmy_api_common::{
   utils::{local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread},
 };
 use lemmy_db_views::structs::PostView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for MarkPostAsRead {
   type Response = PostResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -34,8 +30,6 @@ impl Perform for MarkPostAsRead {
     // Fetch it
     let post_view = PostView::read(context.pool(), post_id, Some(person_id), None).await?;
 
-    let res = Self::Response { post_view };
-
-    Ok(res)
+    Ok(Self::Response { post_view })
   }
 }
index f3ef6319cd9dde4720b52b498dee38fcc10797e7..3213d2be6cd5fd4c610239925444b446c551e709 100644 (file)
@@ -10,18 +10,14 @@ use lemmy_db_schema::{
   traits::Saveable,
 };
 use lemmy_db_views::structs::PostView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for SavePost {
   type Response = PostResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<PostResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
     let data: &SavePost = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index 092f1cd8d8d10c05001d625b86a931727a97c11f..52bc3ce75fa0da7e9d440f15cf045914465afe3a 100644 (file)
@@ -4,7 +4,6 @@ use lemmy_api_common::{
   context::LemmyContext,
   post::{CreatePostReport, PostReportResponse},
   utils::{check_community_ban, local_user_view_from_jwt, send_new_report_email_to_admins},
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::{
@@ -14,19 +13,15 @@ use lemmy_db_schema::{
   traits::Reportable,
 };
 use lemmy_db_views::structs::{PostReportView, PostView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 /// Creates a post report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for CreatePostReport {
   type Response = PostReportResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostReportResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostReportResponse, LemmyError> {
     let data: &CreatePostReport = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
@@ -66,15 +61,6 @@ impl Perform for CreatePostReport {
       .await?;
     }
 
-    let res = PostReportResponse { post_report_view };
-
-    context.send_mod_ws_message(
-      &UserOperation::CreatePostReport,
-      &res,
-      post_view.community.id,
-      websocket_id,
-    )?;
-
-    Ok(res)
+    Ok(PostReportResponse { post_report_view })
   }
 }
index f592704242807de1f83b045a4a65956a420a540f..d8473f736c93273b1cdb02bc760eccdc242ac454 100644 (file)
@@ -6,7 +6,7 @@ use lemmy_api_common::{
   utils::local_user_view_from_jwt,
 };
 use lemmy_db_views::post_report_view::PostReportQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 /// Lists post reports for a community if an id is supplied
 /// or returns all post reports for communities a user moderates
@@ -14,11 +14,10 @@ use lemmy_utils::{error::LemmyError, ConnectionId};
 impl Perform for ListPostReports {
   type Response = ListPostReportsResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<ListPostReportsResponse, LemmyError> {
     let data: &ListPostReports = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -42,8 +41,6 @@ impl Perform for ListPostReports {
       .list()
       .await?;
 
-    let res = ListPostReportsResponse { post_reports };
-
-    Ok(res)
+    Ok(ListPostReportsResponse { post_reports })
   }
 }
index 80290b2a35fae0bda649ad8cefccdd9f5000d4b7..cc6d0510ffbcb7ab136646698c1c47b17eff212d 100644 (file)
@@ -4,23 +4,18 @@ use lemmy_api_common::{
   context::LemmyContext,
   post::{PostReportResponse, ResolvePostReport},
   utils::{is_mod_or_admin, local_user_view_from_jwt},
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
 use lemmy_db_views::structs::PostReportView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 /// Resolves or unresolves a post report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for ResolvePostReport {
   type Response = PostReportResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostReportResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostReportResponse, LemmyError> {
     let data: &ResolvePostReport = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -43,15 +38,6 @@ impl Perform for ResolvePostReport {
 
     let post_report_view = PostReportView::read(context.pool(), report_id, person_id).await?;
 
-    let res = PostReportResponse { post_report_view };
-
-    context.send_mod_ws_message(
-      &UserOperation::ResolvePostReport,
-      &res,
-      report.community.id,
-      websocket_id,
-    )?;
-
-    Ok(res)
+    Ok(PostReportResponse { post_report_view })
   }
 }
index bf373e99c0dc4d5b4457ba7d26cdecfce74207b6..ca343174237bad401607fb4bcdbdce6610191d87 100644 (file)
@@ -4,23 +4,22 @@ use lemmy_api_common::{
   context::LemmyContext,
   private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
   utils::local_user_view_from_jwt,
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_db_views::structs::PrivateMessageView;
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for MarkPrivateMessageAsRead {
   type Response = PrivateMessageResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessageResponse, LemmyError> {
     let data: &MarkPrivateMessageAsRead = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -43,13 +42,9 @@ impl Perform for MarkPrivateMessageAsRead {
     .await
     .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
 
-    // No need to send an apub update
-    context
-      .send_pm_ws_message(
-        &UserOperation::MarkPrivateMessageAsRead,
-        data.private_message_id,
-        websocket_id,
-      )
-      .await
+    let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
+    Ok(PrivateMessageResponse {
+      private_message_view: view,
+    })
   }
 }
index a9ca0291d8e4d14f8c760f57d7f03e9facbc8cd7..2a2feef346500ebdd28ae2402fbd0f50e6a17004 100644 (file)
@@ -4,10 +4,8 @@ use lemmy_api_common::{
   context::LemmyContext,
   private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
   utils::{local_user_view_from_jwt, send_new_report_email_to_admins},
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
-  newtypes::CommunityId,
   source::{
     local_site::LocalSite,
     private_message::PrivateMessage,
@@ -16,18 +14,14 @@ use lemmy_db_schema::{
   traits::{Crud, Reportable},
 };
 use lemmy_db_views::structs::PrivateMessageReportView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for CreatePrivateMessageReport {
   type Response = PrivateMessageReportResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
 
@@ -63,19 +57,10 @@ impl Perform for CreatePrivateMessageReport {
       .await?;
     }
 
-    let res = PrivateMessageReportResponse {
-      private_message_report_view,
-    };
-
-    context.send_mod_ws_message(
-      &UserOperation::CreatePrivateMessageReport,
-      &res,
-      CommunityId(0),
-      websocket_id,
-    )?;
-
     // TODO: consider federating this
 
-    Ok(res)
+    Ok(PrivateMessageReportResponse {
+      private_message_report_view,
+    })
   }
 }
index 69b3dbf94b787cc876a887aa1f7498903b35b608..62c07325c2337266c856b352e0a8f79a6f3f52b8 100644 (file)
@@ -6,18 +6,14 @@ use lemmy_api_common::{
   utils::{is_admin, local_user_view_from_jwt},
 };
 use lemmy_db_views::private_message_report_view::PrivateMessageReportQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for ListPrivateMessageReports {
   type Response = ListPrivateMessageReportsResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
 
     is_admin(&local_user_view)?;
@@ -34,10 +30,8 @@ impl Perform for ListPrivateMessageReports {
       .list()
       .await?;
 
-    let res = ListPrivateMessageReportsResponse {
+    Ok(ListPrivateMessageReportsResponse {
       private_message_reports,
-    };
-
-    Ok(res)
+    })
   }
 }
index 09e3b251a07fc84a8049fac5e853b929f0107150..e4fcfc85681aeb13bc05e9cd95389eb1f2b626f2 100644 (file)
@@ -4,26 +4,17 @@ use lemmy_api_common::{
   context::LemmyContext,
   private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
   utils::{is_admin, local_user_view_from_jwt},
-  websocket::UserOperation,
-};
-use lemmy_db_schema::{
-  newtypes::CommunityId,
-  source::private_message_report::PrivateMessageReport,
-  traits::Reportable,
 };
+use lemmy_db_schema::{source::private_message_report::PrivateMessageReport, traits::Reportable};
 use lemmy_db_views::structs::PrivateMessageReportView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for ResolvePrivateMessageReport {
   type Response = PrivateMessageReportResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
 
     is_admin(&local_user_view)?;
@@ -43,17 +34,8 @@ impl Perform for ResolvePrivateMessageReport {
     let private_message_report_view =
       PrivateMessageReportView::read(context.pool(), report_id).await?;
 
-    let res = PrivateMessageReportResponse {
+    Ok(PrivateMessageReportResponse {
       private_message_report_view,
-    };
-
-    context.send_mod_ws_message(
-      &UserOperation::ResolvePrivateMessageReport,
-      &res,
-      CommunityId(0),
-      websocket_id,
-    )?;
-
-    Ok(res)
+    })
   }
 }
index 107fece44731c948750d68ec7d29e148c787bdd3..0d2b83bc048c0947377b776e1ff18f9714cacaea 100644 (file)
@@ -6,18 +6,14 @@ use lemmy_api_common::{
   utils::build_federated_instances,
 };
 use lemmy_db_views::structs::SiteView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetFederatedInstances {
   type Response = GetFederatedInstancesResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let site_view = SiteView::read_local(context.pool()).await?;
     let federated_instances =
       build_federated_instances(&site_view.local_site, context.pool()).await?;
index a7c0941d132e574f31e506a53d3a7a9c99b3776c..d7c0cf3aa222159173fad1c674ba220c111c1342 100644 (file)
@@ -17,18 +17,14 @@ use lemmy_db_schema::{
 };
 use lemmy_db_views::structs::{CustomEmojiView, SiteView};
 use lemmy_db_views_actor::structs::PersonView;
-use lemmy_utils::{error::LemmyError, version, ConnectionId};
+use lemmy_utils::{error::LemmyError, version};
 
 #[async_trait::async_trait(?Send)]
 impl Perform for LeaveAdmin {
   type Response = GetSiteResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetSiteResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetSiteResponse, LemmyError> {
     let data: &LeaveAdmin = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -69,7 +65,6 @@ impl Perform for LeaveAdmin {
     Ok(GetSiteResponse {
       site_view,
       admins,
-      online: 0,
       version: version::VERSION.to_string(),
       my_user: None,
       all_languages,
index dcb5f5edf5aa2386d5bed5923257f050f04a6204..2ca725150b3312c2614da1314b2de6fb5810b6a1 100644 (file)
@@ -28,19 +28,15 @@ use lemmy_db_views_moderator::structs::{
   ModTransferCommunityView,
   ModlogListParams,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 use ModlogActionType::*;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetModlog {
   type Response = GetModlogResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetModlogResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetModlogResponse, LemmyError> {
     let data: &GetModlog = self;
 
     let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
index f4ba4509740cbdaa5ee88729370bdb4a4b333efb..c8abf57d978a882d6e45d19fdbcf6991aa89b831 100644 (file)
@@ -12,18 +12,14 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for PurgeComment {
   type Response = PurgeItemResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data: &Self = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index 5bdf62e75bb154187da9d9d646281bec1296aeeb..111c437ec12957b56f1ab01b9b1cc45f8c176085 100644 (file)
@@ -13,18 +13,14 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for PurgeCommunity {
   type Response = PurgeItemResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data: &Self = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index 896dc783cf8032b61cfa48938d9d1592af91946e..5273110ed89dcade56cb84a0b8c29abea264d7c0 100644 (file)
@@ -13,18 +13,14 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for PurgePerson {
   type Response = PurgeItemResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data: &Self = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index c04fc5601849850a22f5de8f354adcc12780412b..01d0332ebe8b26a463bf68694250ac53d7b14374 100644 (file)
@@ -13,18 +13,14 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for PurgePost {
   type Response = PurgeItemResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data: &Self = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index edba7f2b85cc4bd42ab72390c6f0faa2ec3db680..b7f672e61b6c3a53b0210d608d9e04e849c7a729 100644 (file)
@@ -14,17 +14,13 @@ use lemmy_db_schema::{
   utils::diesel_option_overwrite,
 };
 use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for ApproveRegistrationApplication {
   type Response = RegistrationApplicationResponse;
 
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index b5a366e1666953e15d2f123ac263a9fa5ebe5178..6a3599577ef5b27d5bd98d2509d7971168fd0c6f 100644 (file)
@@ -7,18 +7,14 @@ use lemmy_api_common::{
 };
 use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 /// Lists registration applications, filterable by undenied only.
 #[async_trait::async_trait(?Send)]
 impl Perform for ListRegistrationApplications {
   type Response = ListRegistrationApplicationsResponse;
 
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
@@ -41,10 +37,8 @@ impl Perform for ListRegistrationApplications {
       .list()
       .await?;
 
-    let res = Self::Response {
+    Ok(Self::Response {
       registration_applications,
-    };
-
-    Ok(res)
+    })
   }
 }
index 72490e480399537414d2aa4627c1a5a9f81906cf..aed07c708556728802f5d055a03f54aa4237715a 100644 (file)
@@ -7,17 +7,13 @@ use lemmy_api_common::{
 };
 use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_db_views::structs::RegistrationApplicationView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetUnreadRegistrationApplicationCount {
   type Response = GetUnreadRegistrationApplicationCountResponse;
 
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
diff --git a/crates/api/src/websocket.rs b/crates/api/src/websocket.rs
deleted file mode 100644 (file)
index 0552c19..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-use crate::Perform;
-use actix_web::web::Data;
-use lemmy_api_common::{
-  context::LemmyContext,
-  utils::local_user_view_from_jwt,
-  websocket::{
-    handlers::join_rooms::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
-    structs::{
-      CommunityJoin,
-      CommunityJoinResponse,
-      ModJoin,
-      ModJoinResponse,
-      PostJoin,
-      PostJoinResponse,
-      UserJoin,
-      UserJoinResponse,
-    },
-  },
-};
-use lemmy_utils::{error::LemmyError, ConnectionId};
-
-#[async_trait::async_trait(?Send)]
-impl Perform for UserJoin {
-  type Response = UserJoinResponse;
-
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<UserJoinResponse, LemmyError> {
-    let data: &UserJoin = self;
-    let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
-
-    if let Some(id) = websocket_id {
-      context.chat_server().do_send(JoinUserRoom {
-        user_id: local_user_view.local_user.id,
-        id,
-      });
-    }
-
-    Ok(UserJoinResponse { joined: true })
-  }
-}
-
-#[async_trait::async_trait(?Send)]
-impl Perform for CommunityJoin {
-  type Response = CommunityJoinResponse;
-
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommunityJoinResponse, LemmyError> {
-    let data: &CommunityJoin = self;
-
-    if let Some(id) = websocket_id {
-      context.chat_server().do_send(JoinCommunityRoom {
-        community_id: data.community_id,
-        id,
-      });
-    }
-
-    Ok(CommunityJoinResponse { joined: true })
-  }
-}
-
-#[async_trait::async_trait(?Send)]
-impl Perform for ModJoin {
-  type Response = ModJoinResponse;
-
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<ModJoinResponse, LemmyError> {
-    let data: &ModJoin = self;
-
-    if let Some(id) = websocket_id {
-      context.chat_server().do_send(JoinModRoom {
-        community_id: data.community_id,
-        id,
-      });
-    }
-
-    Ok(ModJoinResponse { joined: true })
-  }
-}
-
-#[async_trait::async_trait(?Send)]
-impl Perform for PostJoin {
-  type Response = PostJoinResponse;
-
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostJoinResponse, LemmyError> {
-    let data: &PostJoin = self;
-
-    if let Some(id) = websocket_id {
-      context.chat_server().do_send(JoinPostRoom {
-        post_id: data.post_id,
-        id,
-      });
-    }
-
-    Ok(PostJoinResponse { joined: true })
-  }
-}
index e10af5a0de54fa7f7ac561c069261c9cf44d73d6..5b5ee9ab2b7a0ebfc4a67061d81018598c5936f9 100644 (file)
@@ -35,14 +35,10 @@ rosetta-i18n = { workspace = true, optional = true }
 percent-encoding = { workspace = true, optional = true }
 webpage = { version = "1.4.0", default-features = false, features = ["serde"], optional = true }
 encoding = { version = "0.2.33", optional = true }
-rand = { workspace = true }
-serde_json = { workspace = true }
 anyhow = { workspace = true }
-strum = { workspace = true }
-strum_macros = { workspace = true }
-actix = { workspace = true }
 futures = { workspace = true }
 uuid = { workspace = true }
 actix-rt = { workspace = true }
 reqwest = { workspace = true }
 ts-rs = { workspace = true, optional = true }
+actix-web = { workspace = true }
diff --git a/crates/api_common/src/build_response.rs b/crates/api_common/src/build_response.rs
new file mode 100644 (file)
index 0000000..374a74d
--- /dev/null
@@ -0,0 +1,216 @@
+use crate::{
+  comment::CommentResponse,
+  community::CommunityResponse,
+  context::LemmyContext,
+  post::PostResponse,
+  utils::{check_person_block, get_interface_language, is_mod_or_admin, send_email_to_user},
+};
+use actix_web::web::Data;
+use lemmy_db_schema::{
+  newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId},
+  source::{
+    actor_language::CommunityLanguage,
+    comment::Comment,
+    comment_reply::{CommentReply, CommentReplyInsertForm},
+    person::Person,
+    person_mention::{PersonMention, PersonMentionInsertForm},
+    post::Post,
+  },
+  traits::Crud,
+};
+use lemmy_db_views::structs::{CommentView, LocalUserView, PostView};
+use lemmy_db_views_actor::structs::CommunityView;
+use lemmy_utils::{error::LemmyError, utils::mention::MentionData};
+
+pub async fn build_comment_response(
+  context: &Data<LemmyContext>,
+  comment_id: CommentId,
+  local_user_view: Option<LocalUserView>,
+  form_id: Option<String>,
+  recipient_ids: Vec<LocalUserId>,
+) -> Result<CommentResponse, LemmyError> {
+  let person_id = local_user_view.map(|l| l.person.id);
+  let comment_view = CommentView::read(context.pool(), comment_id, person_id).await?;
+  Ok(CommentResponse {
+    comment_view,
+    recipient_ids,
+    form_id,
+  })
+}
+
+pub async fn build_community_response(
+  context: &Data<LemmyContext>,
+  local_user_view: LocalUserView,
+  community_id: CommunityId,
+) -> Result<CommunityResponse, LemmyError> {
+  let is_mod_or_admin = is_mod_or_admin(context.pool(), local_user_view.person.id, community_id)
+    .await
+    .is_ok();
+  let person_id = local_user_view.person.id;
+  let community_view = CommunityView::read(
+    context.pool(),
+    community_id,
+    Some(person_id),
+    Some(is_mod_or_admin),
+  )
+  .await?;
+  let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
+
+  Ok(CommunityResponse {
+    community_view,
+    discussion_languages,
+  })
+}
+
+pub async fn build_post_response(
+  context: &Data<LemmyContext>,
+  community_id: CommunityId,
+  person_id: PersonId,
+  post_id: PostId,
+) -> Result<PostResponse, LemmyError> {
+  let is_mod_or_admin = is_mod_or_admin(context.pool(), person_id, community_id)
+    .await
+    .is_ok();
+  let post_view = PostView::read(
+    context.pool(),
+    post_id,
+    Some(person_id),
+    Some(is_mod_or_admin),
+  )
+  .await?;
+  Ok(PostResponse { post_view })
+}
+
+// TODO: this function is a mess and should be split up to handle email seperately
+#[tracing::instrument(skip_all)]
+pub async fn send_local_notifs(
+  mentions: Vec<MentionData>,
+  comment: &Comment,
+  person: &Person,
+  post: &Post,
+  do_send_email: bool,
+  context: &LemmyContext,
+) -> Result<Vec<LocalUserId>, LemmyError> {
+  let mut recipient_ids = Vec::new();
+  let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
+
+  // Send the local mentions
+  for mention in mentions
+    .iter()
+    .filter(|m| m.is_local(&context.settings().hostname) && m.name.ne(&person.name))
+    .collect::<Vec<&MentionData>>()
+  {
+    let mention_name = mention.name.clone();
+    let user_view = LocalUserView::read_from_name(context.pool(), &mention_name).await;
+    if let Ok(mention_user_view) = user_view {
+      // TODO
+      // At some point, make it so you can't tag the parent creator either
+      // This can cause two notifications, one for reply and the other for mention
+      recipient_ids.push(mention_user_view.local_user.id);
+
+      let user_mention_form = PersonMentionInsertForm {
+        recipient_id: mention_user_view.person.id,
+        comment_id: comment.id,
+        read: None,
+      };
+
+      // Allow this to fail softly, since comment edits might re-update or replace it
+      // Let the uniqueness handle this fail
+      PersonMention::create(context.pool(), &user_mention_form)
+        .await
+        .ok();
+
+      // Send an email to those local users that have notifications on
+      if do_send_email {
+        let lang = get_interface_language(&mention_user_view);
+        send_email_to_user(
+          &mention_user_view,
+          &lang.notification_mentioned_by_subject(&person.name),
+          &lang.notification_mentioned_by_body(&comment.content, &inbox_link, &person.name),
+          context.settings(),
+        )
+      }
+    }
+  }
+
+  // Send comment_reply to the parent commenter / poster
+  if let Some(parent_comment_id) = comment.parent_comment_id() {
+    let parent_comment = Comment::read(context.pool(), parent_comment_id).await?;
+
+    // Get the parent commenter local_user
+    let parent_creator_id = parent_comment.creator_id;
+
+    // Only add to recipients if that person isn't blocked
+    let creator_blocked = check_person_block(person.id, parent_creator_id, context.pool())
+      .await
+      .is_err();
+
+    // Don't send a notif to yourself
+    if parent_comment.creator_id != person.id && !creator_blocked {
+      let user_view = LocalUserView::read_person(context.pool(), parent_creator_id).await;
+      if let Ok(parent_user_view) = user_view {
+        recipient_ids.push(parent_user_view.local_user.id);
+
+        let comment_reply_form = CommentReplyInsertForm {
+          recipient_id: parent_user_view.person.id,
+          comment_id: comment.id,
+          read: None,
+        };
+
+        // Allow this to fail softly, since comment edits might re-update or replace it
+        // Let the uniqueness handle this fail
+        CommentReply::create(context.pool(), &comment_reply_form)
+          .await
+          .ok();
+
+        if do_send_email {
+          let lang = get_interface_language(&parent_user_view);
+          send_email_to_user(
+            &parent_user_view,
+            &lang.notification_comment_reply_subject(&person.name),
+            &lang.notification_comment_reply_body(&comment.content, &inbox_link, &person.name),
+            context.settings(),
+          )
+        }
+      }
+    }
+  } else {
+    // If there's no parent, its the post creator
+    // Only add to recipients if that person isn't blocked
+    let creator_blocked = check_person_block(person.id, post.creator_id, context.pool())
+      .await
+      .is_err();
+
+    if post.creator_id != person.id && !creator_blocked {
+      let creator_id = post.creator_id;
+      let parent_user = LocalUserView::read_person(context.pool(), creator_id).await;
+      if let Ok(parent_user_view) = parent_user {
+        recipient_ids.push(parent_user_view.local_user.id);
+
+        let comment_reply_form = CommentReplyInsertForm {
+          recipient_id: parent_user_view.person.id,
+          comment_id: comment.id,
+          read: None,
+        };
+
+        // Allow this to fail softly, since comment edits might re-update or replace it
+        // Let the uniqueness handle this fail
+        CommentReply::create(context.pool(), &comment_reply_form)
+          .await
+          .ok();
+
+        if do_send_email {
+          let lang = get_interface_language(&parent_user_view);
+          send_email_to_user(
+            &parent_user_view,
+            &lang.notification_post_reply_subject(&person.name),
+            &lang.notification_post_reply_body(&comment.content, &inbox_link, &person.name),
+            context.settings(),
+          )
+        }
+      }
+    }
+  }
+
+  Ok(recipient_ids)
+}
index becf29ab479e68b6ef859bc63ebcc100dc396ae5..cb92d4c2e2afd11db552e4f1b05fb0f66529a703 100644 (file)
@@ -32,7 +32,6 @@ pub struct GetCommunityResponse {
   pub community_view: CommunityView,
   pub site: Option<Site>,
   pub moderators: Vec<CommunityModeratorView>,
-  pub online: usize,
   pub discussion_languages: Vec<LanguageId>,
 }
 
index 1301bf36f6618d1d0eeec43b0efd71a88b2c365d..42fa74964ee61698645374815d36cf33637fe066 100644 (file)
@@ -1,5 +1,3 @@
-use crate::websocket::chat_server::ChatServer;
-use actix::Addr;
 use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
 use lemmy_utils::{
   rate_limit::RateLimitCell,
@@ -11,7 +9,6 @@ use std::sync::Arc;
 #[derive(Clone)]
 pub struct LemmyContext {
   pool: DbPool,
-  chat_server: Addr<ChatServer>,
   client: Arc<ClientWithMiddleware>,
   secret: Arc<Secret>,
   rate_limit_cell: RateLimitCell,
@@ -20,14 +17,12 @@ pub struct LemmyContext {
 impl LemmyContext {
   pub fn create(
     pool: DbPool,
-    chat_server: Addr<ChatServer>,
     client: ClientWithMiddleware,
     secret: Secret,
     rate_limit_cell: RateLimitCell,
   ) -> LemmyContext {
     LemmyContext {
       pool,
-      chat_server,
       client: Arc::new(client),
       secret: Arc::new(secret),
       rate_limit_cell,
@@ -36,9 +31,6 @@ impl LemmyContext {
   pub fn pool(&self) -> &DbPool {
     &self.pool
   }
-  pub fn chat_server(&self) -> &Addr<ChatServer> {
-    &self.chat_server
-  }
   pub fn client(&self) -> &ClientWithMiddleware {
     &self.client
   }
index 3c9d71216f71a0f83e0b2948cc1853e4df5fcbe9..224e114a55161d335cb9ce955139b6ceca042226 100644 (file)
@@ -1,3 +1,5 @@
+#[cfg(feature = "full")]
+pub mod build_response;
 pub mod comment;
 pub mod community;
 #[cfg(feature = "full")]
@@ -12,11 +14,7 @@ pub mod sensitive;
 pub mod site;
 #[cfg(feature = "full")]
 pub mod utils;
-#[cfg(feature = "full")]
-pub mod websocket;
 
-#[macro_use]
-extern crate strum_macros;
 pub extern crate lemmy_db_schema;
 pub extern crate lemmy_db_views;
 pub extern crate lemmy_db_views_actor;
index f421bf047da836c395bbd2ecb7be7e8dd6a59c91..962c4bb92bc3cdee8a2a34cf3c3a7f1324cf3deb 100644 (file)
@@ -60,7 +60,6 @@ pub struct GetPostResponse {
   pub moderators: Vec<CommunityModeratorView>,
   /// A list of cross-posts, or other times / communities this link has been posted to.
   pub cross_posts: Vec<PostView>,
-  pub online: usize,
 }
 
 #[skip_serializing_none]
index 2ba6611c9a5c0feb8fd1d0b22c2aa142d1ea137c..4d488ec1b812befc6bf23bf68bc21cf2b3df2063 100644 (file)
@@ -294,7 +294,6 @@ pub struct SiteResponse {
 pub struct GetSiteResponse {
   pub site_view: SiteView,
   pub admins: Vec<PersonView>,
-  pub online: usize,
   pub version: String,
   pub my_user: Option<MyUserInfo>,
   pub all_languages: Vec<Language>,
diff --git a/crates/api_common/src/websocket/chat_server.rs b/crates/api_common/src/websocket/chat_server.rs
deleted file mode 100644 (file)
index fa06987..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-use crate::websocket::{
-  handlers::{SessionInfo, WsMessage},
-  structs::CaptchaItem,
-};
-use actix::{Actor, Context};
-use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
-use lemmy_utils::ConnectionId;
-use rand::{rngs::StdRng, SeedableRng};
-use std::collections::{HashMap, HashSet};
-
-pub struct ChatServer {
-  /// A map from generated random ID to session addr
-  pub sessions: HashMap<ConnectionId, SessionInfo>,
-
-  /// A map from post_id to set of connectionIDs
-  pub post_rooms: HashMap<PostId, HashSet<ConnectionId>>,
-
-  /// A map from community to set of connectionIDs
-  pub community_rooms: HashMap<CommunityId, HashSet<ConnectionId>>,
-
-  pub mod_rooms: HashMap<CommunityId, HashSet<ConnectionId>>,
-
-  /// A map from user id to its connection ID for joined users. Remember a user can have multiple
-  /// sessions (IE clients)
-  pub(super) user_rooms: HashMap<LocalUserId, HashSet<ConnectionId>>,
-
-  pub(super) rng: StdRng,
-
-  /// A list of the current captchas
-  pub(super) captchas: Vec<CaptchaItem>,
-}
-
-/// `ChatServer` is an actor. It maintains list of connection client session.
-/// And manages available rooms. Peers send messages to other peers in same
-/// room through `ChatServer`.
-impl ChatServer {
-  pub fn new() -> ChatServer {
-    ChatServer {
-      sessions: Default::default(),
-      post_rooms: Default::default(),
-      community_rooms: Default::default(),
-      mod_rooms: Default::default(),
-      user_rooms: Default::default(),
-      rng: StdRng::from_entropy(),
-      captchas: vec![],
-    }
-  }
-
-  pub fn send_message(
-    &self,
-    connections: &HashSet<ConnectionId>,
-    message: &str,
-    exclude_connection: Option<ConnectionId>,
-  ) {
-    for id in connections
-      .iter()
-      .filter(|c| Some(*c) != exclude_connection.as_ref())
-    {
-      if let Some(session) = self.sessions.get(id) {
-        session.addr.do_send(WsMessage(message.to_owned()));
-      }
-    }
-  }
-}
-
-impl Default for ChatServer {
-  fn default() -> Self {
-    Self::new()
-  }
-}
-
-/// Make actor from `ChatServer`
-impl Actor for ChatServer {
-  /// We are going to use simple Context, we just need ability to communicate
-  /// with other actors.
-  type Context = Context<Self>;
-}
diff --git a/crates/api_common/src/websocket/handlers/captcha.rs b/crates/api_common/src/websocket/handlers/captcha.rs
deleted file mode 100644 (file)
index e3ff609..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-use crate::websocket::{chat_server::ChatServer, structs::CaptchaItem};
-use actix::{Context, Handler, Message};
-use lemmy_db_schema::utils::naive_now;
-
-/// Adding a Captcha
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct AddCaptcha {
-  pub captcha: CaptchaItem,
-}
-
-impl Handler<AddCaptcha> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: AddCaptcha, _: &mut Context<Self>) -> Self::Result {
-    self.captchas.push(msg.captcha);
-  }
-}
-
-/// Checking a Captcha
-#[derive(Message)]
-#[rtype(bool)]
-pub struct CheckCaptcha {
-  pub uuid: String,
-  pub answer: String,
-}
-
-impl Handler<CheckCaptcha> for ChatServer {
-  type Result = bool;
-
-  fn handle(&mut self, msg: CheckCaptcha, _: &mut Context<Self>) -> Self::Result {
-    // Remove all the ones that are past the expire time
-    self.captchas.retain(|x| x.expires.gt(&naive_now()));
-
-    let check = self
-      .captchas
-      .iter()
-      .any(|r| r.uuid == msg.uuid && r.answer.to_lowercase() == msg.answer.to_lowercase());
-
-    // Remove this uuid so it can't be re-checked (Checks only work once)
-    self.captchas.retain(|x| x.uuid != msg.uuid);
-
-    check
-  }
-}
diff --git a/crates/api_common/src/websocket/handlers/connect.rs b/crates/api_common/src/websocket/handlers/connect.rs
deleted file mode 100644 (file)
index f3e7e3b..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-use crate::websocket::{
-  chat_server::ChatServer,
-  handlers::{SessionInfo, WsMessage},
-};
-use actix::{Context, Handler, Message, Recipient};
-use lemmy_utils::ConnectionId;
-use rand::Rng;
-
-/// New chat session is created
-#[derive(Message)]
-#[rtype(ConnectionId)]
-pub struct Connect {
-  pub addr: Recipient<WsMessage>,
-}
-
-/// Handler for Connect message.
-///
-/// Register new session and assign unique id to this session
-impl Handler<Connect> for ChatServer {
-  type Result = ConnectionId;
-
-  fn handle(&mut self, msg: Connect, _: &mut Context<Self>) -> Self::Result {
-    // register session with random id
-    let id = self.rng.gen::<usize>();
-    let session = SessionInfo { addr: msg.addr };
-    self.sessions.insert(id, session);
-
-    // send id back
-    id
-  }
-}
-
-/// Session is disconnected
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct Disconnect {
-  pub id: ConnectionId,
-}
-
-/// Handler for Disconnect message.
-impl Handler<Disconnect> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: Disconnect, _: &mut Context<Self>) -> Self::Result {
-    // remove address
-    if self.sessions.remove(&msg.id).is_some() {
-      // remove session from all rooms
-      for sessions in self.user_rooms.values_mut() {
-        sessions.remove(&msg.id);
-      }
-      for sessions in self.post_rooms.values_mut() {
-        sessions.remove(&msg.id);
-      }
-      for sessions in self.community_rooms.values_mut() {
-        sessions.remove(&msg.id);
-      }
-      for sessions in self.mod_rooms.values_mut() {
-        sessions.remove(&msg.id);
-      }
-    }
-  }
-}
diff --git a/crates/api_common/src/websocket/handlers/join_rooms.rs b/crates/api_common/src/websocket/handlers/join_rooms.rs
deleted file mode 100644 (file)
index 10235e3..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-use crate::websocket::chat_server::ChatServer;
-use actix::{Context, Handler, Message};
-use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
-use lemmy_utils::ConnectionId;
-use std::collections::HashSet;
-
-/// Joining a Post room
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct JoinPostRoom {
-  pub post_id: PostId,
-  pub id: ConnectionId,
-}
-
-impl Handler<JoinPostRoom> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: JoinPostRoom, _: &mut Context<Self>) -> Self::Result {
-    // remove session from all rooms
-    for sessions in self.post_rooms.values_mut() {
-      sessions.remove(&msg.id);
-    }
-
-    // Also leave all communities
-    // This avoids double messages
-    // TODO found a bug, whereby community messages like
-    // delete and remove aren't sent, because
-    // you left the community room
-    for sessions in self.community_rooms.values_mut() {
-      sessions.remove(&msg.id);
-    }
-
-    self
-      .post_rooms
-      .entry(msg.post_id)
-      .or_insert_with(HashSet::new)
-      .insert(msg.id);
-  }
-}
-
-/// Joining a Community Room
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct JoinCommunityRoom {
-  pub community_id: CommunityId,
-  pub id: ConnectionId,
-}
-
-impl Handler<JoinCommunityRoom> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: JoinCommunityRoom, _: &mut Context<Self>) -> Self::Result {
-    // remove session from all rooms
-    for sessions in self.community_rooms.values_mut() {
-      sessions.remove(&msg.id);
-    }
-
-    // Also leave all post rooms
-    // This avoids double messages
-    for sessions in self.post_rooms.values_mut() {
-      sessions.remove(&msg.id);
-    }
-
-    self
-      .community_rooms
-      .entry(msg.community_id)
-      .or_insert_with(HashSet::new)
-      .insert(msg.id);
-  }
-}
-
-/// Joining a Mod room
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct JoinModRoom {
-  pub community_id: CommunityId,
-  pub id: ConnectionId,
-}
-
-impl Handler<JoinModRoom> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: JoinModRoom, _: &mut Context<Self>) -> Self::Result {
-    // remove session from all rooms
-    for sessions in self.mod_rooms.values_mut() {
-      sessions.remove(&msg.id);
-    }
-
-    self
-      .mod_rooms
-      .entry(msg.community_id)
-      .or_insert_with(HashSet::new)
-      .insert(msg.id);
-  }
-}
-
-/// Joining a User room
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct JoinUserRoom {
-  pub user_id: LocalUserId,
-  pub id: ConnectionId,
-}
-
-impl Handler<JoinUserRoom> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: JoinUserRoom, _: &mut Context<Self>) -> Self::Result {
-    // remove session from all rooms
-    for sessions in self.user_rooms.values_mut() {
-      sessions.remove(&msg.id);
-    }
-
-    self
-      .user_rooms
-      .entry(msg.user_id)
-      .or_insert_with(HashSet::new)
-      .insert(msg.id);
-  }
-}
diff --git a/crates/api_common/src/websocket/handlers/messages.rs b/crates/api_common/src/websocket/handlers/messages.rs
deleted file mode 100644 (file)
index 3b49302..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-use crate::websocket::chat_server::ChatServer;
-use actix::{Context, Handler, Message};
-use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
-use lemmy_utils::ConnectionId;
-use std::collections::HashSet;
-
-/// Sending a post room message
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct SendPostRoomMessage {
-  pub post_id: PostId,
-  pub message: String,
-  pub websocket_id: Option<ConnectionId>,
-}
-
-impl Handler<SendPostRoomMessage> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: SendPostRoomMessage, _: &mut Context<Self>) -> Self::Result {
-    let room_connections = self.post_rooms.get(&msg.post_id);
-    if let Some(connections) = room_connections {
-      self.send_message(connections, &msg.message, msg.websocket_id);
-    }
-  }
-}
-
-/// Sending a community room message
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct SendCommunityRoomMessage {
-  pub community_id: CommunityId,
-  pub message: String,
-  pub websocket_id: Option<ConnectionId>,
-}
-
-impl Handler<SendCommunityRoomMessage> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: SendCommunityRoomMessage, _: &mut Context<Self>) -> Self::Result {
-    let room_connections = self.community_rooms.get(&msg.community_id);
-    if let Some(connections) = room_connections {
-      self.send_message(connections, &msg.message, msg.websocket_id);
-    }
-  }
-}
-
-/// Sending a mod room message
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct SendModRoomMessage {
-  pub community_id: CommunityId,
-  pub message: String,
-  pub websocket_id: Option<ConnectionId>,
-}
-
-impl Handler<SendModRoomMessage> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: SendModRoomMessage, _: &mut Context<Self>) -> Self::Result {
-    let room_connections = self.community_rooms.get(&msg.community_id);
-    if let Some(connections) = room_connections {
-      self.send_message(connections, &msg.message, msg.websocket_id);
-    }
-  }
-}
-
-/// Sending a user room message
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct SendUserRoomMessage {
-  pub recipient_id: LocalUserId,
-  pub message: String,
-  pub websocket_id: Option<ConnectionId>,
-}
-
-impl Handler<SendUserRoomMessage> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: SendUserRoomMessage, _: &mut Context<Self>) -> Self::Result {
-    let room_connections = self.user_rooms.get(&msg.recipient_id);
-    if let Some(connections) = room_connections {
-      self.send_message(connections, &msg.message, msg.websocket_id);
-    }
-  }
-}
-
-/// Sending a message to every session
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct SendAllMessage {
-  pub message: String,
-  pub websocket_id: Option<ConnectionId>,
-}
-
-impl Handler<SendAllMessage> for ChatServer {
-  type Result = ();
-
-  fn handle(&mut self, msg: SendAllMessage, _: &mut Context<Self>) -> Self::Result {
-    let connections: HashSet<ConnectionId> = self.sessions.keys().cloned().collect();
-    self.send_message(&connections, &msg.message, msg.websocket_id);
-  }
-}
-
-///// Send websocket message in all sessions which joined a specific room.
-/////
-///// `message` - The json message body to send
-///// `room` - Connection IDs which should receive the message
-///// `exclude_connection` - Dont send to user who initiated the api call, as that
-/////                        would result in duplicate notification
-//async fn send_message_in_room(
-//  &self,
-//  message: &str,
-//  room: Option<HashSet<ConnectionId>>,
-//  exclude_connection: Option<ConnectionId>,
-//) -> Result<(), LemmyError> {
-//  let mut session = self.inner()?.sessions.clone();
-//  if let Some(room) = room {
-//    // Note, this will ignore any errors, such as closed connections
-//    join_all(
-//      room
-//        .into_iter()
-//        .filter(|c| Some(c) != exclude_connection.as_ref())
-//        .filter_map(|c| session.remove(&c))
-//        .map(|mut s: Session| async move { s.text(message).await }),
-//    )
-//    .await;
-//  }
-//  Ok(())
-//}
-//}
diff --git a/crates/api_common/src/websocket/handlers/mod.rs b/crates/api_common/src/websocket/handlers/mod.rs
deleted file mode 100644 (file)
index d989a44..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-use actix::{Message, Recipient};
-
-pub mod captcha;
-pub mod connect;
-pub mod join_rooms;
-pub mod messages;
-pub mod online_users;
-
-/// A string message sent to a websocket session
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct WsMessage(pub String);
-
-// TODO move this?
-pub struct SessionInfo {
-  pub addr: Recipient<WsMessage>,
-  // pub ip: IpAddr
-}
diff --git a/crates/api_common/src/websocket/handlers/online_users.rs b/crates/api_common/src/websocket/handlers/online_users.rs
deleted file mode 100644 (file)
index 2833b68..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-use crate::websocket::chat_server::ChatServer;
-use actix::{Context, Handler, Message};
-use lemmy_db_schema::newtypes::{CommunityId, PostId};
-
-/// Getting the number of online connections
-#[derive(Message)]
-#[rtype(usize)]
-pub struct GetUsersOnline;
-
-/// Handler for Disconnect message.
-impl Handler<GetUsersOnline> for ChatServer {
-  type Result = usize;
-
-  fn handle(&mut self, _msg: GetUsersOnline, _: &mut Context<Self>) -> Self::Result {
-    self.sessions.len()
-  }
-}
-
-/// Getting the number of post users online
-#[derive(Message)]
-#[rtype(usize)]
-pub struct GetPostUsersOnline {
-  pub post_id: PostId,
-}
-
-/// Handler for Disconnect message.
-impl Handler<GetPostUsersOnline> for ChatServer {
-  type Result = usize;
-
-  fn handle(&mut self, msg: GetPostUsersOnline, _: &mut Context<Self>) -> Self::Result {
-    self
-      .post_rooms
-      .get(&msg.post_id)
-      .map_or(1, std::collections::HashSet::len)
-  }
-}
-
-/// Getting the number of post users online
-#[derive(Message)]
-#[rtype(usize)]
-pub struct GetCommunityUsersOnline {
-  pub community_id: CommunityId,
-}
-
-/// Handler for Disconnect message.
-impl Handler<GetCommunityUsersOnline> for ChatServer {
-  type Result = usize;
-
-  fn handle(&mut self, msg: GetCommunityUsersOnline, _: &mut Context<Self>) -> Self::Result {
-    self
-      .community_rooms
-      .get(&msg.community_id)
-      .map_or(1, std::collections::HashSet::len)
-  }
-}
diff --git a/crates/api_common/src/websocket/mod.rs b/crates/api_common/src/websocket/mod.rs
deleted file mode 100644 (file)
index 2f13d8b..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-use actix::{Message, Recipient};
-use lemmy_utils::error::LemmyError;
-use serde::Serialize;
-
-pub mod chat_server;
-pub mod handlers;
-pub mod send;
-pub mod structs;
-
-/// A string message sent to a websocket session
-#[derive(Message)]
-#[rtype(result = "()")]
-pub struct WsMessage(pub String);
-
-pub struct SessionInfo {
-  pub addr: Recipient<WsMessage>,
-}
-
-#[derive(Serialize)]
-struct WebsocketResponse<T> {
-  op: String,
-  data: T,
-}
-
-pub fn serialize_websocket_message<Response, OP>(
-  op: &OP,
-  data: &Response,
-) -> Result<String, LemmyError>
-where
-  Response: Serialize,
-  OP: ToString,
-{
-  let response = WebsocketResponse {
-    op: op.to_string(),
-    data,
-  };
-  Ok(serde_json::to_string(&response)?)
-}
-
-#[derive(EnumString, Display, Debug, Clone)]
-pub enum UserOperation {
-  Login,
-  GetCaptcha,
-  SaveComment,
-  CreateCommentLike,
-  DistinguishComment,
-  CreateCommentReport,
-  ResolveCommentReport,
-  ListCommentReports,
-  CreatePostLike,
-  LockPost,
-  FeaturePost,
-  MarkPostAsRead,
-  SavePost,
-  CreatePostReport,
-  ResolvePostReport,
-  ListPostReports,
-  GetReportCount,
-  GetUnreadCount,
-  VerifyEmail,
-  FollowCommunity,
-  GetReplies,
-  GetPersonMentions,
-  MarkPersonMentionAsRead,
-  MarkCommentReplyAsRead,
-  GetModlog,
-  BanFromCommunity,
-  AddModToCommunity,
-  AddAdmin,
-  GetUnreadRegistrationApplicationCount,
-  ListRegistrationApplications,
-  ApproveRegistrationApplication,
-  BanPerson,
-  GetBannedPersons,
-  MarkAllAsRead,
-  SaveUserSettings,
-  TransferCommunity,
-  LeaveAdmin,
-  PasswordReset,
-  PasswordChange,
-  MarkPrivateMessageAsRead,
-  CreatePrivateMessageReport,
-  ResolvePrivateMessageReport,
-  ListPrivateMessageReports,
-  UserJoin,
-  PostJoin,
-  CommunityJoin,
-  ModJoin,
-  ChangePassword,
-  GetSiteMetadata,
-  BlockCommunity,
-  BlockPerson,
-  PurgePerson,
-  PurgeCommunity,
-  PurgePost,
-  PurgeComment,
-  GetFederatedInstances,
-}
-
-#[derive(EnumString, Display, Debug, Clone)]
-pub enum UserOperationCrud {
-  // Site
-  CreateSite,
-  GetSite,
-  EditSite,
-  // Community
-  CreateCommunity,
-  ListCommunities,
-  EditCommunity,
-  DeleteCommunity,
-  RemoveCommunity,
-  // Post
-  CreatePost,
-  GetPost,
-  EditPost,
-  DeletePost,
-  RemovePost,
-  // Comment
-  CreateComment,
-  GetComment,
-  EditComment,
-  DeleteComment,
-  RemoveComment,
-  // User
-  Register,
-  DeleteAccount,
-  // Private Message
-  CreatePrivateMessage,
-  GetPrivateMessages,
-  EditPrivateMessage,
-  DeletePrivateMessage,
-  //Emojis
-  CreateCustomEmoji,
-  EditCustomEmoji,
-  DeleteCustomEmoji,
-}
-
-#[derive(EnumString, Display, Debug, Clone)]
-pub enum UserOperationApub {
-  GetPosts,
-  GetCommunity,
-  GetComments,
-  GetPersonDetails,
-  Search,
-  ResolveObject,
-}
diff --git a/crates/api_common/src/websocket/send.rs b/crates/api_common/src/websocket/send.rs
deleted file mode 100644 (file)
index e983b85..0000000
+++ /dev/null
@@ -1,405 +0,0 @@
-use super::{
-  handlers::messages::{
-    SendAllMessage,
-    SendCommunityRoomMessage,
-    SendModRoomMessage,
-    SendPostRoomMessage,
-    SendUserRoomMessage,
-  },
-  serialize_websocket_message,
-};
-use crate::{
-  comment::CommentResponse,
-  community::CommunityResponse,
-  context::LemmyContext,
-  post::PostResponse,
-  private_message::PrivateMessageResponse,
-  utils::{check_person_block, get_interface_language, send_email_to_user},
-};
-use lemmy_db_schema::{
-  newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId},
-  source::{
-    actor_language::CommunityLanguage,
-    comment::Comment,
-    comment_reply::{CommentReply, CommentReplyInsertForm},
-    person::Person,
-    person_mention::{PersonMention, PersonMentionInsertForm},
-    post::Post,
-  },
-  traits::Crud,
-  SubscribedType,
-};
-use lemmy_db_views::structs::{CommentView, LocalUserView, PostView, PrivateMessageView};
-use lemmy_db_views_actor::structs::CommunityView;
-use lemmy_utils::{error::LemmyError, utils::mention::MentionData, ConnectionId};
-use serde::Serialize;
-
-impl LemmyContext {
-  #[tracing::instrument(skip_all)]
-  pub async fn send_post_ws_message<OP>(
-    &self,
-    op: &OP,
-    post_id: PostId,
-    websocket_id: Option<ConnectionId>,
-    person_id: Option<PersonId>,
-  ) -> Result<PostResponse, LemmyError>
-  where
-    OP: ToString,
-  {
-    let post_view = PostView::read(self.pool(), post_id, person_id, Some(true)).await?;
-
-    let res = PostResponse { post_view };
-
-    // Send it to the post room
-    // Don't send my data with it
-    let mut post_sent = res.clone();
-    post_sent.post_view.my_vote = None;
-    let message = serialize_websocket_message(op, &post_sent)?;
-
-    self.chat_server().do_send(SendPostRoomMessage {
-      post_id,
-      message: message.clone(),
-      websocket_id,
-    });
-
-    // Send it to /c/all and that community
-    self.chat_server().do_send(SendCommunityRoomMessage {
-      community_id: CommunityId(0),
-      message: message.clone(),
-      websocket_id,
-    });
-
-    self.chat_server().do_send(SendCommunityRoomMessage {
-      community_id: post_sent.post_view.community.id,
-      message,
-      websocket_id,
-    });
-
-    Ok(res)
-  }
-
-  // TODO: in many call sites in apub crate, we are setting an empty vec for recipient_ids,
-  //       we should get the actual recipient actors from somewhere
-  #[tracing::instrument(skip_all)]
-  pub async fn send_comment_ws_message_simple<OP>(
-    &self,
-    op: &OP,
-    comment_id: CommentId,
-  ) -> Result<CommentResponse, LemmyError>
-  where
-    OP: ToString,
-  {
-    self
-      .send_comment_ws_message(op, comment_id, None, None, None, vec![])
-      .await
-  }
-
-  #[tracing::instrument(skip_all)]
-  pub async fn send_comment_ws_message<OP>(
-    &self,
-    op: &OP,
-    comment_id: CommentId,
-    websocket_id: Option<ConnectionId>,
-    form_id: Option<String>,
-    person_id: Option<PersonId>,
-    recipient_ids: Vec<LocalUserId>,
-  ) -> Result<CommentResponse, LemmyError>
-  where
-    OP: ToString,
-  {
-    let view = CommentView::read(self.pool(), comment_id, person_id).await?;
-
-    let mut res = CommentResponse {
-      comment_view: view,
-      recipient_ids,
-      form_id,
-    };
-
-    // Strip out my specific user info
-    let mut sent_recipient_comment = res.clone();
-    sent_recipient_comment.form_id = None;
-    sent_recipient_comment.comment_view.my_vote = None;
-    let recipient_message = serialize_websocket_message(op, &sent_recipient_comment)?;
-
-    // Send it to the recipient(s) including the mentioned users
-    for recipient_id in &sent_recipient_comment.recipient_ids {
-      self.chat_server().do_send(SendUserRoomMessage {
-        recipient_id: *recipient_id,
-        message: recipient_message.clone(),
-        websocket_id,
-      });
-    }
-
-    // Remove the recipients here to separate mentions / user messages from post or community comments
-    let mut sent_post_comment = sent_recipient_comment;
-    sent_post_comment.recipient_ids = Vec::new();
-    let post_message = serialize_websocket_message(op, &sent_post_comment)?;
-
-    // Send it to the post room
-    self.chat_server().do_send(SendPostRoomMessage {
-      post_id: sent_post_comment.comment_view.post.id,
-      message: post_message.clone(),
-      websocket_id,
-    });
-
-    // Send it to the community too
-    self.chat_server().do_send(SendCommunityRoomMessage {
-      community_id: sent_post_comment.comment_view.community.id,
-      message: post_message,
-      websocket_id,
-    });
-    // TODO should I send it to all? Seems excessive
-    //  self
-    //    .send_community_room_message(
-    //      user_operation,
-    //      &comment_post_sent,
-    //      CommunityId(0),
-    //      websocket_id,
-    //    )
-    //    .await?;
-
-    // No need to return recipients
-    res.recipient_ids = Vec::new();
-
-    Ok(res)
-  }
-
-  #[tracing::instrument(skip_all)]
-  pub async fn send_community_ws_message<OP>(
-    &self,
-    op: &OP,
-    community_id: CommunityId,
-    websocket_id: Option<ConnectionId>,
-    person_id: Option<PersonId>,
-  ) -> Result<CommunityResponse, LemmyError>
-  where
-    OP: ToString,
-  {
-    let community_view =
-      CommunityView::read(self.pool(), community_id, person_id, Some(true)).await?;
-    let discussion_languages = CommunityLanguage::read(self.pool(), community_id).await?;
-
-    let mut res = CommunityResponse {
-      community_view,
-      discussion_languages,
-    };
-
-    // Strip out the person id and subscribed when sending to others
-    res.community_view.subscribed = SubscribedType::NotSubscribed;
-    let message = serialize_websocket_message(op, &res)?;
-
-    self.chat_server().do_send(SendCommunityRoomMessage {
-      community_id: res.community_view.community.id,
-      message,
-      websocket_id,
-    });
-
-    Ok(res)
-  }
-
-  #[tracing::instrument(skip_all)]
-  pub async fn send_pm_ws_message<OP>(
-    &self,
-    op: &OP,
-    private_message_id: PrivateMessageId,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PrivateMessageResponse, LemmyError>
-  where
-    OP: ToString,
-  {
-    let view = PrivateMessageView::read(self.pool(), private_message_id).await?;
-
-    let res = PrivateMessageResponse {
-      private_message_view: view,
-    };
-
-    // Send notifications to the local recipient, if one exists
-    if res.private_message_view.recipient.local {
-      let recipient_id = res.private_message_view.recipient.id;
-      let local_recipient = LocalUserView::read_person(self.pool(), recipient_id).await?;
-
-      let message = serialize_websocket_message(op, &res)?;
-
-      self.chat_server().do_send(SendUserRoomMessage {
-        recipient_id: local_recipient.local_user.id,
-        message,
-        websocket_id,
-      });
-    }
-
-    Ok(res)
-  }
-
-  #[tracing::instrument(skip_all)]
-  pub async fn send_local_notifs(
-    &self,
-    mentions: Vec<MentionData>,
-    comment: &Comment,
-    person: &Person,
-    post: &Post,
-    do_send_email: bool,
-  ) -> Result<Vec<LocalUserId>, LemmyError> {
-    let mut recipient_ids = Vec::new();
-    let inbox_link = format!("{}/inbox", self.settings().get_protocol_and_hostname());
-
-    // Send the local mentions
-    for mention in mentions
-      .iter()
-      .filter(|m| m.is_local(&self.settings().hostname) && m.name.ne(&person.name))
-      .collect::<Vec<&MentionData>>()
-    {
-      let mention_name = mention.name.clone();
-      let user_view = LocalUserView::read_from_name(self.pool(), &mention_name).await;
-      if let Ok(mention_user_view) = user_view {
-        // TODO
-        // At some point, make it so you can't tag the parent creator either
-        // This can cause two notifications, one for reply and the other for mention
-        recipient_ids.push(mention_user_view.local_user.id);
-
-        let user_mention_form = PersonMentionInsertForm {
-          recipient_id: mention_user_view.person.id,
-          comment_id: comment.id,
-          read: None,
-        };
-
-        // Allow this to fail softly, since comment edits might re-update or replace it
-        // Let the uniqueness handle this fail
-        PersonMention::create(self.pool(), &user_mention_form)
-          .await
-          .ok();
-
-        // Send an email to those local users that have notifications on
-        if do_send_email {
-          let lang = get_interface_language(&mention_user_view);
-          send_email_to_user(
-            &mention_user_view,
-            &lang.notification_mentioned_by_subject(&person.name),
-            &lang.notification_mentioned_by_body(&comment.content, &inbox_link, &person.name),
-            self.settings(),
-          )
-        }
-      }
-    }
-
-    // Send comment_reply to the parent commenter / poster
-    if let Some(parent_comment_id) = comment.parent_comment_id() {
-      let parent_comment = Comment::read(self.pool(), parent_comment_id).await?;
-
-      // Get the parent commenter local_user
-      let parent_creator_id = parent_comment.creator_id;
-
-      // Only add to recipients if that person isn't blocked
-      let creator_blocked = check_person_block(person.id, parent_creator_id, self.pool())
-        .await
-        .is_err();
-
-      // Don't send a notif to yourself
-      if parent_comment.creator_id != person.id && !creator_blocked {
-        let user_view = LocalUserView::read_person(self.pool(), parent_creator_id).await;
-        if let Ok(parent_user_view) = user_view {
-          recipient_ids.push(parent_user_view.local_user.id);
-
-          let comment_reply_form = CommentReplyInsertForm {
-            recipient_id: parent_user_view.person.id,
-            comment_id: comment.id,
-            read: None,
-          };
-
-          // Allow this to fail softly, since comment edits might re-update or replace it
-          // Let the uniqueness handle this fail
-          CommentReply::create(self.pool(), &comment_reply_form)
-            .await
-            .ok();
-
-          if do_send_email {
-            let lang = get_interface_language(&parent_user_view);
-            send_email_to_user(
-              &parent_user_view,
-              &lang.notification_comment_reply_subject(&person.name),
-              &lang.notification_comment_reply_body(&comment.content, &inbox_link, &person.name),
-              self.settings(),
-            )
-          }
-        }
-      }
-    } else {
-      // If there's no parent, its the post creator
-      // Only add to recipients if that person isn't blocked
-      let creator_blocked = check_person_block(person.id, post.creator_id, self.pool())
-        .await
-        .is_err();
-
-      if post.creator_id != person.id && !creator_blocked {
-        let creator_id = post.creator_id;
-        let parent_user = LocalUserView::read_person(self.pool(), creator_id).await;
-        if let Ok(parent_user_view) = parent_user {
-          recipient_ids.push(parent_user_view.local_user.id);
-
-          let comment_reply_form = CommentReplyInsertForm {
-            recipient_id: parent_user_view.person.id,
-            comment_id: comment.id,
-            read: None,
-          };
-
-          // Allow this to fail softly, since comment edits might re-update or replace it
-          // Let the uniqueness handle this fail
-          CommentReply::create(self.pool(), &comment_reply_form)
-            .await
-            .ok();
-
-          if do_send_email {
-            let lang = get_interface_language(&parent_user_view);
-            send_email_to_user(
-              &parent_user_view,
-              &lang.notification_post_reply_subject(&person.name),
-              &lang.notification_post_reply_body(&comment.content, &inbox_link, &person.name),
-              self.settings(),
-            )
-          }
-        }
-      }
-    }
-
-    Ok(recipient_ids)
-  }
-
-  #[tracing::instrument(skip_all)]
-  pub fn send_all_ws_message<Data, OP>(
-    &self,
-    op: &OP,
-    data: Data,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<(), LemmyError>
-  where
-    Data: Serialize,
-    OP: ToString,
-  {
-    let message = serialize_websocket_message(op, &data)?;
-    self.chat_server().do_send(SendAllMessage {
-      message,
-      websocket_id,
-    });
-    Ok(())
-  }
-
-  #[tracing::instrument(skip_all)]
-  pub fn send_mod_ws_message<Data, OP>(
-    &self,
-    op: &OP,
-    data: Data,
-    community_id: CommunityId,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<(), LemmyError>
-  where
-    Data: Serialize,
-    OP: ToString,
-  {
-    let message = serialize_websocket_message(op, &data)?;
-    self.chat_server().do_send(SendModRoomMessage {
-      community_id,
-      message,
-      websocket_id,
-    });
-    Ok(())
-  }
-}
diff --git a/crates/api_common/src/websocket/structs.rs b/crates/api_common/src/websocket/structs.rs
deleted file mode 100644 (file)
index dbe5107..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-use crate::sensitive::Sensitive;
-use lemmy_db_schema::newtypes::{CommunityId, PostId};
-use serde::{Deserialize, Serialize};
-#[cfg(feature = "full")]
-use ts_rs::TS;
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-#[cfg_attr(feature = "full", derive(TS))]
-#[cfg_attr(feature = "full", ts(export))]
-/// Join a user room.
-pub struct UserJoin {
-  pub auth: Sensitive<String>,
-}
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-#[cfg_attr(feature = "full", derive(TS))]
-#[cfg_attr(feature = "full", ts(export))]
-/// The join response.
-pub struct UserJoinResponse {
-  pub joined: bool,
-}
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-#[cfg_attr(feature = "full", derive(TS))]
-#[cfg_attr(feature = "full", ts(export))]
-/// Join a community room.
-pub struct CommunityJoin {
-  pub community_id: CommunityId,
-}
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-#[cfg_attr(feature = "full", derive(TS))]
-#[cfg_attr(feature = "full", ts(export))]
-/// The join response.
-pub struct CommunityJoinResponse {
-  pub joined: bool,
-}
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-#[cfg_attr(feature = "full", derive(TS))]
-#[cfg_attr(feature = "full", ts(export))]
-/// Join a mod room.
-pub struct ModJoin {
-  pub community_id: CommunityId,
-}
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-#[cfg_attr(feature = "full", derive(TS))]
-#[cfg_attr(feature = "full", ts(export))]
-/// The join response.
-pub struct ModJoinResponse {
-  pub joined: bool,
-}
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-#[cfg_attr(feature = "full", derive(TS))]
-#[cfg_attr(feature = "full", ts(export))]
-/// Join a post room.
-pub struct PostJoin {
-  pub post_id: PostId,
-}
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-#[cfg_attr(feature = "full", derive(TS))]
-#[cfg_attr(feature = "full", ts(export))]
-/// The join response.
-pub struct PostJoinResponse {
-  pub joined: bool,
-}
-
-#[derive(Debug)]
-pub struct CaptchaItem {
-  pub uuid: String,
-  pub answer: String,
-  pub expires: chrono::NaiveDateTime,
-}
index 8909444d247280862569f547bb89c3a449690dc7..5001879475c61dbaab9cc3d290164d23d0b97c4f 100644 (file)
@@ -1,6 +1,7 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::{build_comment_response, send_local_notifs},
   comment::{CommentResponse, CreateComment},
   context::LemmyContext,
   utils::{
@@ -13,7 +14,6 @@ use lemmy_api_common::{
     local_user_view_from_jwt,
     EndpointType,
   },
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -32,19 +32,14 @@ use lemmy_utils::{
     slurs::remove_slurs,
     validation::is_valid_body_field,
   },
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for CreateComment {
   type Response = CommentResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommentResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
     let data: &CreateComment = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
@@ -129,22 +124,21 @@ impl PerformCrud for CreateComment {
     .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_comment"))?;
 
     // Scan the comment for user mentions, add those rows
-    let post_id = post.id;
     let mentions = scrape_text_for_mentions(&content_slurs_removed);
-    let recipient_ids = context
-      .send_local_notifs(
-        mentions,
-        &updated_comment,
-        &local_user_view.person,
-        &post,
-        true,
-      )
-      .await?;
+    let recipient_ids = send_local_notifs(
+      mentions,
+      &updated_comment,
+      &local_user_view.person,
+      &post,
+      true,
+      context,
+    )
+    .await?;
 
     // You like your own comment by default
     let like_form = CommentLikeForm {
       comment_id: inserted_comment.id,
-      post_id,
+      post_id: post.id,
       person_id: local_user_view.person.id,
       score: 1,
     };
@@ -182,15 +176,13 @@ impl PerformCrud for CreateComment {
       }
     }
 
-    context
-      .send_comment_ws_message(
-        &UserOperationCrud::CreateComment,
-        inserted_comment.id,
-        websocket_id,
-        data.form_id.clone(),
-        Some(local_user_view.person.id),
-        recipient_ids,
-      )
-      .await
+    build_comment_response(
+      context,
+      inserted_comment.id,
+      Some(local_user_view),
+      self.form_id.clone(),
+      recipient_ids,
+    )
+    .await
   }
 }
index cde4ab6292510c35fc30bd4d52d4f1630d3f4047..864daded8cad381e9ca6a43877928bd7ad2e3207 100644 (file)
@@ -1,10 +1,10 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::{build_comment_response, send_local_notifs},
   comment::{CommentResponse, DeleteComment},
   context::LemmyContext,
   utils::{check_community_ban, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -14,18 +14,14 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_db_views::structs::CommentView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for DeleteComment {
   type Response = CommentResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommentResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
     let data: &DeleteComment = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -61,27 +57,23 @@ impl PerformCrud for DeleteComment {
 
     let post_id = updated_comment.post_id;
     let post = Post::read(context.pool(), post_id).await?;
-    let recipient_ids = context
-      .send_local_notifs(
-        vec![],
-        &updated_comment,
-        &local_user_view.person,
-        &post,
-        false,
-      )
-      .await?;
-
-    let res = context
-      .send_comment_ws_message(
-        &UserOperationCrud::DeleteComment,
-        data.comment_id,
-        websocket_id,
-        None,
-        Some(local_user_view.person.id),
-        recipient_ids,
-      )
-      .await?;
+    let recipient_ids = send_local_notifs(
+      vec![],
+      &updated_comment,
+      &local_user_view.person,
+      &post,
+      false,
+      context,
+    )
+    .await?;
 
-    Ok(res)
+    build_comment_response(
+      context,
+      updated_comment.id,
+      Some(local_user_view),
+      None,
+      recipient_ids,
+    )
+    .await
   }
 }
index bd37eb77cdffca62124c246b0d883508a6550586..2ae71973809213d8c889959339d899530a94aea1 100644 (file)
@@ -1,40 +1,26 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_comment_response,
   comment::{CommentResponse, GetComment},
   context::LemmyContext,
   utils::{check_private_instance, local_user_view_from_jwt_opt},
 };
 use lemmy_db_schema::source::local_site::LocalSite;
-use lemmy_db_views::structs::CommentView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for GetComment {
   type Response = CommentResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data = self;
     let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
     let local_site = LocalSite::read(context.pool()).await?;
 
     check_private_instance(&local_user_view, &local_site)?;
 
-    let person_id = local_user_view.map(|u| u.person.id);
-    let id = data.id;
-    let comment_view = CommentView::read(context.pool(), id, person_id)
-      .await
-      .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_comment"))?;
-
-    Ok(Self::Response {
-      comment_view,
-      form_id: None,
-      recipient_ids: Vec::new(),
-    })
+    build_comment_response(context, data.id, local_user_view, None, vec![]).await
   }
 }
index b8834df8d69ac4dbde26deec96b351acf1bc5533..6e4e5528194d690a4a2338816cf9b086a5b4232a 100644 (file)
@@ -1,10 +1,10 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::{build_comment_response, send_local_notifs},
   comment::{CommentResponse, RemoveComment},
   context::LemmyContext,
   utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -15,18 +15,14 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_db_views::structs::CommentView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for RemoveComment {
   type Response = CommentResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommentResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
     let data: &RemoveComment = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -69,27 +65,23 @@ impl PerformCrud for RemoveComment {
 
     let post_id = updated_comment.post_id;
     let post = Post::read(context.pool(), post_id).await?;
-    let recipient_ids = context
-      .send_local_notifs(
-        vec![],
-        &updated_comment,
-        &local_user_view.person.clone(),
-        &post,
-        false,
-      )
-      .await?;
-
-    let res = context
-      .send_comment_ws_message(
-        &UserOperationCrud::RemoveComment,
-        data.comment_id,
-        websocket_id,
-        None, // TODO maybe this might clear other forms
-        Some(local_user_view.person.id),
-        recipient_ids,
-      )
-      .await?;
+    let recipient_ids = send_local_notifs(
+      vec![],
+      &updated_comment,
+      &local_user_view.person.clone(),
+      &post,
+      false,
+      context,
+    )
+    .await?;
 
-    Ok(res)
+    build_comment_response(
+      context,
+      updated_comment.id,
+      Some(local_user_view),
+      None,
+      recipient_ids,
+    )
+    .await
   }
 }
index e74d5c4edd0acff3d3a4a83397c9a9616e027970..86bdb52e2101681ea8e8d31913379b036fa1ed24 100644 (file)
@@ -1,10 +1,10 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::{build_comment_response, send_local_notifs},
   comment::{CommentResponse, EditComment},
   context::LemmyContext,
   utils::{check_community_ban, local_site_to_slur_regex, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -23,19 +23,14 @@ use lemmy_utils::{
     slurs::remove_slurs,
     validation::is_valid_body_field,
   },
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for EditComment {
   type Response = CommentResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommentResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
     let data: &EditComment = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
@@ -84,25 +79,23 @@ impl PerformCrud for EditComment {
     // Do the mentions / recipients
     let updated_comment_content = updated_comment.content.clone();
     let mentions = scrape_text_for_mentions(&updated_comment_content);
-    let recipient_ids = context
-      .send_local_notifs(
-        mentions,
-        &updated_comment,
-        &local_user_view.person,
-        &orig_comment.post,
-        false,
-      )
-      .await?;
+    let recipient_ids = send_local_notifs(
+      mentions,
+      &updated_comment,
+      &local_user_view.person,
+      &orig_comment.post,
+      false,
+      context,
+    )
+    .await?;
 
-    context
-      .send_comment_ws_message(
-        &UserOperationCrud::EditComment,
-        data.comment_id,
-        websocket_id,
-        data.form_id.clone(),
-        None,
-        recipient_ids,
-      )
-      .await
+    build_comment_response(
+      context,
+      updated_comment.id,
+      Some(local_user_view),
+      self.form_id.clone(),
+      recipient_ids,
+    )
+    .await
   }
 }
index fbc557b723a9fffdef2286562f051f5d80918dea..850e9f2f5e65f2a8d011ffe6da9e8efbb91fcdfb 100644 (file)
@@ -2,6 +2,7 @@ use crate::PerformCrud;
 use activitypub_federation::http_signatures::generate_actor_keypair;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_community_response,
   community::{CommunityResponse, CreateCommunity},
   context::LemmyContext,
   utils::{
@@ -31,26 +32,20 @@ use lemmy_db_schema::{
   utils::diesel_option_overwrite_to_url_create,
 };
 use lemmy_db_views::structs::SiteView;
-use lemmy_db_views_actor::structs::CommunityView;
 use lemmy_utils::{
   error::LemmyError,
   utils::{
     slurs::{check_slurs, check_slurs_opt},
     validation::{is_valid_actor_name, is_valid_body_field},
   },
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for CreateCommunity {
   type Response = CommunityResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<CommunityResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
     let data: &CreateCommunity = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let site_view = SiteView::read_local(context.pool()).await?;
@@ -143,15 +138,6 @@ impl PerformCrud for CreateCommunity {
       CommunityLanguage::update(context.pool(), languages, community_id).await?;
     }
 
-    let person_id = local_user_view.person.id;
-    let community_view =
-      CommunityView::read(context.pool(), inserted_community.id, Some(person_id), None).await?;
-    let discussion_languages =
-      CommunityLanguage::read(context.pool(), inserted_community.id).await?;
-
-    Ok(CommunityResponse {
-      community_view,
-      discussion_languages,
-    })
+    build_community_response(context, local_user_view, community_id).await
   }
 }
index 9909f5cdd099d1e4f6793f37553a2f36d8b6b330..019e9f1da7cd9f24cc550cc756c32dd58cce0b75 100644 (file)
@@ -1,28 +1,24 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_community_response,
   community::{CommunityResponse, DeleteCommunity},
   context::LemmyContext,
   utils::{is_top_mod, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::community::{Community, CommunityUpdateForm},
   traits::Crud,
 };
 use lemmy_db_views_actor::structs::CommunityModeratorView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for DeleteCommunity {
   type Response = CommunityResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommunityResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
     let data: &DeleteCommunity = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -47,15 +43,6 @@ impl PerformCrud for DeleteCommunity {
     .await
     .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
 
-    let res = context
-      .send_community_ws_message(
-        &UserOperationCrud::DeleteCommunity,
-        data.community_id,
-        websocket_id,
-        Some(local_user_view.person.id),
-      )
-      .await?;
-
-    Ok(res)
+    build_community_response(context, local_user_view, community_id).await
   }
 }
index e620e16068042a5193acd3bad835af956aa160a1..a58737d990b6df32859658ff988e4140f838a8d4 100644 (file)
@@ -7,17 +7,16 @@ use lemmy_api_common::{
 };
 use lemmy_db_schema::source::local_site::LocalSite;
 use lemmy_db_views_actor::community_view::CommunityQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for ListCommunities {
   type Response = ListCommunitiesResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<ListCommunitiesResponse, LemmyError> {
     let data: &ListCommunities = self;
     let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
index 9a905b87438948d88017972c1132ea26a2a82e4b..52a503c45aadf5e15de685954d4fede4fb593bdd 100644 (file)
@@ -1,10 +1,10 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_community_response,
   community::{CommunityResponse, RemoveCommunity},
   context::LemmyContext,
   utils::{is_admin, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -13,18 +13,14 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix, ConnectionId};
+use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix};
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for RemoveCommunity {
   type Response = CommunityResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommunityResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
     let data: &RemoveCommunity = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -55,15 +51,6 @@ impl PerformCrud for RemoveCommunity {
     };
     ModRemoveCommunity::create(context.pool(), &form).await?;
 
-    let res = context
-      .send_community_ws_message(
-        &UserOperationCrud::RemoveCommunity,
-        data.community_id,
-        websocket_id,
-        Some(local_user_view.person.id),
-      )
-      .await?;
-
-    Ok(res)
+    build_community_response(context, local_user_view, community_id).await
   }
 }
index 9d56ce8a1c8584250d0893f82bc6645fd4e3d4ac..7494cd342322b5d27372928374c995a36da08db2 100644 (file)
@@ -1,10 +1,10 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_community_response,
   community::{CommunityResponse, EditCommunity},
   context::LemmyContext,
   utils::{local_site_to_slur_regex, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -20,19 +20,14 @@ use lemmy_db_views_actor::structs::CommunityModeratorView;
 use lemmy_utils::{
   error::LemmyError,
   utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for EditCommunity {
   type Response = CommunityResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommunityResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
     let data: &EditCommunity = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
@@ -82,13 +77,6 @@ impl PerformCrud for EditCommunity {
       .await
       .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
 
-    context
-      .send_community_ws_message(
-        &UserOperationCrud::EditCommunity,
-        data.community_id,
-        websocket_id,
-        None,
-      )
-      .await
+    build_community_response(context, local_user_view, community_id).await
   }
 }
index 33337945158c4cfd6dff9104305c9aac7a1ed75c..5aaf56125d7646b9cdd41577a14e6b1e22bba5dc 100644 (file)
@@ -11,18 +11,14 @@ use lemmy_db_schema::source::{
   local_site::LocalSite,
 };
 use lemmy_db_views::structs::CustomEmojiView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for CreateCustomEmoji {
   type Response = CustomEmojiResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<CustomEmojiResponse, LemmyError> {
+  #[tracing::instrument(skip(self, context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CustomEmojiResponse, LemmyError> {
     let data: &CreateCustomEmoji = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index dcca883920ace29dac7609cdfcf6a14a39d8c678..45dc6eaeed75391950ad4c4aa723a3659cac5599 100644 (file)
@@ -6,17 +6,16 @@ use lemmy_api_common::{
   utils::{is_admin, local_user_view_from_jwt},
 };
 use lemmy_db_schema::source::custom_emoji::CustomEmoji;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for DeleteCustomEmoji {
   type Response = DeleteCustomEmojiResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
+  #[tracing::instrument(skip(self, context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<DeleteCustomEmojiResponse, LemmyError> {
     let data: &DeleteCustomEmoji = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
index 67a2bed9f45c70affd5c6258db10cb39c069270a..f56763e9d681bac1d98064db7075cbb1d275775b 100644 (file)
@@ -11,18 +11,14 @@ use lemmy_db_schema::source::{
   local_site::LocalSite,
 };
 use lemmy_db_views::structs::CustomEmojiView;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for EditCustomEmoji {
   type Response = CustomEmojiResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<CustomEmojiResponse, LemmyError> {
+  #[tracing::instrument(skip(self, context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<CustomEmojiResponse, LemmyError> {
     let data: &EditCustomEmoji = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
index 70d5d44d4e4487ef8510d148fcf3c9c84b748d6c..a10309fc9491cdfe4131abc4641a82198127183c 100644 (file)
@@ -1,6 +1,6 @@
 use actix_web::web::Data;
 use lemmy_api_common::context::LemmyContext;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 mod comment;
 mod community;
@@ -14,9 +14,5 @@ mod user;
 pub trait PerformCrud {
   type Response: serde::ser::Serialize + Send;
 
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError>;
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
 }
index e0c1a5d13aa743adcb0ca1cf89c90acdc3f77c1c..cd2cf1c3d8b482f657d5d82f1b695c42a993a18e 100644 (file)
@@ -1,6 +1,7 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_post_response,
   context::LemmyContext,
   post::{CreatePost, PostResponse},
   request::fetch_site_data,
@@ -14,7 +15,6 @@ use lemmy_api_common::{
     mark_post_as_read,
     EndpointType,
   },
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   impls::actor_language::default_post_language,
@@ -33,7 +33,6 @@ use lemmy_utils::{
     slurs::{check_slurs, check_slurs_opt},
     validation::{clean_url_params, is_valid_body_field, is_valid_post_title},
   },
-  ConnectionId,
 };
 use tracing::{warn, Instrument};
 use url::Url;
@@ -43,12 +42,8 @@ use webmention::{Webmention, WebmentionError};
 impl PerformCrud for CreatePost {
   type Response = PostResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
     let data: &CreatePost = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
@@ -171,13 +166,6 @@ impl PerformCrud for CreatePost {
       }
     }
 
-    context
-      .send_post_ws_message(
-        &UserOperationCrud::CreatePost,
-        inserted_post.id,
-        websocket_id,
-        Some(local_user_view.person.id),
-      )
-      .await
+    build_post_response(context, community_id, person_id, post_id).await
   }
 }
index 82efeaa17634b47d2eab722a22fdc821fdafb592..6e6a4c076b18d7038838ee1b136dbb8abf42cd25 100644 (file)
@@ -1,27 +1,23 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_post_response,
   context::LemmyContext,
   post::{DeletePost, PostResponse},
   utils::{check_community_ban, check_community_deleted_or_removed, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::post::{Post, PostUpdateForm},
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for DeletePost {
   type Response = PostResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
     let data: &DeletePost = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -56,15 +52,12 @@ impl PerformCrud for DeletePost {
     )
     .await?;
 
-    let res = context
-      .send_post_ws_message(
-        &UserOperationCrud::DeletePost,
-        data.post_id,
-        websocket_id,
-        Some(local_user_view.person.id),
-      )
-      .await?;
-
-    Ok(res)
+    build_post_response(
+      context,
+      orig_post.community_id,
+      local_user_view.person.id,
+      post_id,
+    )
+    .await
   }
 }
index cda2f65b667a1019739eacba26fcc2befd41a88a..85106afe4a42d3cb04f3ddcf3b626b632646a957 100644 (file)
@@ -9,7 +9,6 @@ use lemmy_api_common::{
     local_user_view_from_jwt_opt,
     mark_post_as_read,
   },
-  websocket::handlers::online_users::GetPostUsersOnline,
 };
 use lemmy_db_schema::{
   aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
@@ -18,18 +17,14 @@ use lemmy_db_schema::{
 };
 use lemmy_db_views::{post_view::PostQuery, structs::PostView};
 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for GetPost {
   type Response = GetPostResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetPostResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetPostResponse, LemmyError> {
     let data: &GetPost = self;
     let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
     let local_site = LocalSite::read(context.pool()).await?;
@@ -106,17 +101,11 @@ impl PerformCrud for GetPost {
       Vec::new()
     };
 
-    let online = context
-      .chat_server()
-      .send(GetPostUsersOnline { post_id })
-      .await?;
-
     // Return the jwt
     Ok(GetPostResponse {
       post_view,
       community_view,
       moderators,
-      online,
       cross_posts,
     })
   }
index 9081d911ee401a04b949d2869ba345f4ef57898e..7f379169eae9a114b06e072f0ba86bf4ab3417ff 100644 (file)
@@ -1,10 +1,10 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_post_response,
   context::LemmyContext,
   post::{PostResponse, RemovePost},
   utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -13,18 +13,14 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for RemovePost {
   type Response = PostResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
     let data: &RemovePost = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
@@ -65,15 +61,12 @@ impl PerformCrud for RemovePost {
     };
     ModRemovePost::create(context.pool(), &form).await?;
 
-    let res = context
-      .send_post_ws_message(
-        &UserOperationCrud::RemovePost,
-        data.post_id,
-        websocket_id,
-        Some(local_user_view.person.id),
-      )
-      .await?;
-
-    Ok(res)
+    build_post_response(
+      context,
+      orig_post.community_id,
+      local_user_view.person.id,
+      post_id,
+    )
+    .await
   }
 }
index 2bd101c0995e696df761b64b11545abe466f92d8..af2c63c5019c53ff7a8296d779fed0ed7e45d752 100644 (file)
@@ -1,11 +1,11 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
 use lemmy_api_common::{
+  build_response::build_post_response,
   context::LemmyContext,
   post::{EditPost, PostResponse},
   request::fetch_site_data,
   utils::{check_community_ban, local_site_to_slur_regex, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -22,19 +22,14 @@ use lemmy_utils::{
     slurs::check_slurs_opt,
     validation::{clean_url_params, is_valid_body_field, is_valid_post_title},
   },
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for EditPost {
   type Response = PostResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
     let data: &EditPost = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
@@ -112,13 +107,12 @@ impl PerformCrud for EditPost {
       return Err(LemmyError::from_error_message(e, err_type));
     }
 
-    context
-      .send_post_ws_message(
-        &UserOperationCrud::EditPost,
-        data.post_id,
-        websocket_id,
-        Some(local_user_view.person.id),
-      )
-      .await
+    build_post_response(
+      context,
+      orig_post.community_id,
+      local_user_view.person.id,
+      post_id,
+    )
+    .await
   }
 }
index 6fd3690089b4d0f2d9327a73373d264b89e34ecf..3b3dd70c1d8cfe45be3a30fc5e45e1f22f50a8fd 100644 (file)
@@ -12,7 +12,6 @@ use lemmy_api_common::{
     send_email_to_user,
     EndpointType,
   },
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -21,22 +20,20 @@ use lemmy_db_schema::{
   },
   traits::Crud,
 };
-use lemmy_db_views::structs::LocalUserView;
+use lemmy_db_views::structs::{LocalUserView, PrivateMessageView};
 use lemmy_utils::{
   error::LemmyError,
   utils::{slurs::remove_slurs, validation::is_valid_body_field},
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for CreatePrivateMessage {
   type Response = PrivateMessageResponse;
 
-  #[tracing::instrument(skip(self, context, websocket_id))]
+  #[tracing::instrument(skip(self, context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessageResponse, LemmyError> {
     let data: &CreatePrivateMessage = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -84,16 +81,10 @@ impl PerformCrud for CreatePrivateMessage {
     .await
     .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_private_message"))?;
 
-    let res = context
-      .send_pm_ws_message(
-        &UserOperationCrud::CreatePrivateMessage,
-        inserted_private_message.id,
-        websocket_id,
-      )
-      .await?;
+    let view = PrivateMessageView::read(context.pool(), inserted_private_message.id).await?;
 
     // Send email to the local recipient, if one exists
-    if res.private_message_view.recipient.local {
+    if view.recipient.local {
       let recipient_id = data.recipient_id;
       let local_recipient = LocalUserView::read_person(context.pool(), recipient_id).await?;
       let lang = get_interface_language(&local_recipient);
@@ -110,6 +101,8 @@ impl PerformCrud for CreatePrivateMessage {
       );
     }
 
-    Ok(res)
+    Ok(PrivateMessageResponse {
+      private_message_view: view,
+    })
   }
 }
index f494edffad95013b9517dbbf5c37e61b63f81052..b8e3c3b1101a40b1ef9436356a87875c70c59fc5 100644 (file)
@@ -4,23 +4,22 @@ use lemmy_api_common::{
   context::LemmyContext,
   private_message::{DeletePrivateMessage, PrivateMessageResponse},
   utils::local_user_view_from_jwt,
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
   traits::Crud,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_db_views::structs::PrivateMessageView;
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for DeletePrivateMessage {
   type Response = PrivateMessageResponse;
 
-  #[tracing::instrument(skip(self, context, websocket_id))]
+  #[tracing::instrument(skip(self, context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessageResponse, LemmyError> {
     let data: &DeletePrivateMessage = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -45,12 +44,9 @@ impl PerformCrud for DeletePrivateMessage {
     .await
     .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
 
-    context
-      .send_pm_ws_message(
-        &UserOperationCrud::DeletePrivateMessage,
-        data.private_message_id,
-        websocket_id,
-      )
-      .await
+    let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
+    Ok(PrivateMessageResponse {
+      private_message_view: view,
+    })
   }
 }
index da2bc690bfbb88787dfdac08c65ea1a693a874ee..679cd09f7a8e5b877041191152eea58c8e4146ce 100644 (file)
@@ -6,17 +6,16 @@ use lemmy_api_common::{
   utils::local_user_view_from_jwt,
 };
 use lemmy_db_views::private_message_view::PrivateMessageQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for GetPrivateMessages {
   type Response = PrivateMessagesResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
+  #[tracing::instrument(skip(self, context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessagesResponse, LemmyError> {
     let data: &GetPrivateMessages = self;
     let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
index a485a509323bcfc3b541e97ee12cfe9639d682b6..cc3c377b89b54b3f067485b308c4e06d99c23364 100644 (file)
@@ -4,7 +4,6 @@ use lemmy_api_common::{
   context::LemmyContext,
   private_message::{EditPrivateMessage, PrivateMessageResponse},
   utils::{local_site_to_slur_regex, local_user_view_from_jwt},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -14,21 +13,20 @@ use lemmy_db_schema::{
   traits::Crud,
   utils::naive_now,
 };
+use lemmy_db_views::structs::PrivateMessageView;
 use lemmy_utils::{
   error::LemmyError,
   utils::{slurs::remove_slurs, validation::is_valid_body_field},
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for EditPrivateMessage {
   type Response = PrivateMessageResponse;
 
-  #[tracing::instrument(skip(self, context, websocket_id))]
+  #[tracing::instrument(skip(self, context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessageResponse, LemmyError> {
     let data: &EditPrivateMessage = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@@ -57,12 +55,10 @@ impl PerformCrud for EditPrivateMessage {
     .await
     .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
 
-    context
-      .send_pm_ws_message(
-        &UserOperationCrud::EditPrivateMessage,
-        data.private_message_id,
-        websocket_id,
-      )
-      .await
+    let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
+
+    Ok(PrivateMessageResponse {
+      private_message_view: view,
+    })
   }
 }
index 05b41e35a4dea510f04548fb464275c9450da5b3..c16f3bc56a82f5762d983302c302906e655978ac 100644 (file)
@@ -31,7 +31,6 @@ use lemmy_utils::{
     slurs::{check_slurs, check_slurs_opt},
     validation::is_valid_body_field,
   },
-  ConnectionId,
 };
 use url::Url;
 
@@ -39,12 +38,8 @@ use url::Url;
 impl PerformCrud for CreateSite {
   type Response = SiteResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<SiteResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
     let data: &CreateSite = self;
 
     let local_site = LocalSite::read(context.pool()).await?;
index 1e40cabdd548d7b3b0effc31632f24669023b932..f6c663ac087447148e26365b50ae2c06bade6aa2 100644 (file)
@@ -5,7 +5,6 @@ use lemmy_api_common::{
   sensitive::Sensitive,
   site::{GetSite, GetSiteResponse, MyUserInfo},
   utils::{check_user_valid, check_validator_time},
-  websocket::handlers::online_users::GetUsersOnline,
 };
 use lemmy_db_schema::{
   newtypes::LocalUserId,
@@ -23,26 +22,20 @@ use lemmy_db_views_actor::structs::{
   PersonBlockView,
   PersonView,
 };
-use lemmy_utils::{claims::Claims, error::LemmyError, version, ConnectionId};
+use lemmy_utils::{claims::Claims, error::LemmyError, version};
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for GetSite {
   type Response = GetSiteResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetSiteResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetSiteResponse, LemmyError> {
     let data: &GetSite = self;
 
     let site_view = SiteView::read_local(context.pool()).await?;
 
     let admins = PersonView::admins(context.pool()).await?;
 
-    let online = context.chat_server().send(GetUsersOnline).await?;
-
     // Build the local user
     let my_user = if let Some(local_user_view) =
       local_user_settings_view_from_jwt_opt(data.auth.as_ref(), context).await
@@ -92,7 +85,6 @@ impl PerformCrud for GetSite {
     Ok(GetSiteResponse {
       site_view,
       admins,
-      online,
       version: version::VERSION.to_string(),
       my_user,
       all_languages,
index 31c4e4838748769768fe3b18d8410b347d802860..b1b2981675d3b646f0c6f6c29b295f0ae135118d 100644 (file)
@@ -10,7 +10,6 @@ use lemmy_api_common::{
     local_user_view_from_jwt,
     site_description_length_check,
   },
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -32,19 +31,14 @@ use lemmy_db_views::structs::SiteView;
 use lemmy_utils::{
   error::LemmyError,
   utils::{slurs::check_slurs_opt, validation::is_valid_body_field},
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for EditSite {
   type Response = SiteResponse;
 
-  #[tracing::instrument(skip(context, websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<SiteResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
     let data: &EditSite = self;
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
     let site_view = SiteView::read_local(context.pool()).await?;
@@ -199,8 +193,6 @@ impl PerformCrud for EditSite {
       taglines,
     };
 
-    context.send_all_ws_message(&UserOperationCrud::EditSite, &res, websocket_id)?;
-
     Ok(res)
   }
 }
index 8ae6de3908337ff006f58caba549ec88126b1c4e..c888339309a157482c627b2b217432a4877a8b87 100644 (file)
@@ -15,7 +15,6 @@ use lemmy_api_common::{
     send_verification_email,
     EndpointType,
   },
-  websocket::handlers::captcha::CheckCaptcha,
 };
 use lemmy_db_schema::{
   aggregates::structs::PersonAggregates,
@@ -35,19 +34,14 @@ use lemmy_utils::{
     slurs::{check_slurs, check_slurs_opt},
     validation::is_valid_actor_name,
   },
-  ConnectionId,
 };
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for Register {
   type Response = LoginResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<LoginResponse, LemmyError> {
+  #[tracing::instrument(skip(self, context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
     let data: &Register = self;
 
     let site_view = SiteView::read_local(context.pool()).await?;
@@ -77,20 +71,6 @@ impl PerformCrud for Register {
       return Err(LemmyError::from_message("passwords_dont_match"));
     }
 
-    // If the site is set up, check the captcha
-    if local_site.site_setup && local_site.captcha_enabled {
-      let check = context
-        .chat_server()
-        .send(CheckCaptcha {
-          uuid: data.captcha_uuid.clone().unwrap_or_default(),
-          answer: data.captcha_answer.clone().unwrap_or_default(),
-        })
-        .await?;
-      if !check {
-        return Err(LemmyError::from_message("captcha_incorrect"));
-      }
-    }
-
     let slur_regex = local_site_to_slur_regex(&local_site);
     check_slurs(&data.username, &slur_regex)?;
     check_slurs_opt(&data.answer, &slur_regex)?;
index 731f90721c1fa98b3c5b0735142ae825012b4753..7ce0312cf56cbff6a606b6605c4a04c90203156a 100644 (file)
@@ -6,18 +6,14 @@ use lemmy_api_common::{
   person::{DeleteAccount, DeleteAccountResponse},
   utils::local_user_view_from_jwt,
 };
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for DeleteAccount {
   type Response = DeleteAccountResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  #[tracing::instrument(skip(self, context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
     let data = self;
     let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?;
 
index 4a5c8fc8f70739f062151a30da6ee1561ba86d3b..65aeb0b2fa4561369a128f09a7d995f16a4e9b27 100644 (file)
@@ -26,7 +26,6 @@ serde_json = { workspace = true }
 serde = { workspace = true }
 actix-web = { workspace = true }
 actix-rt = { workspace = true }
-actix = { workspace = true }
 tracing = { workspace = true }
 strum_macros = { workspace = true }
 url = { workspace = true }
index a0ca46830354a2e1189e7c7d56e0b245d088e68d..72e4664788532cbb9b79da47ffa1288bb8a53fb7 100644 (file)
@@ -1,76 +1,65 @@
 {
   "@context": [
     "https://www.w3.org/ns/activitystreams",
-    "https://w3id.org/security/v1",
     {
-      "vcard": "http://www.w3.org/2006/vcard/ns#",
-      "dfrn": "http://purl.org/macgirvin/dfrn/1.0/",
-      "diaspora": "https://diasporafoundation.org/ns/",
-      "litepub": "http://litepub.social/ns#",
-      "toot": "http://joinmastodon.org/ns#",
-      "schema": "http://schema.org#",
-      "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+      "ostatus": "http://ostatus.org#",
+      "atomUri": "ostatus:atomUri",
+      "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+      "conversation": "ostatus:conversation",
       "sensitive": "as:sensitive",
-      "Hashtag": "as:Hashtag",
-      "directMessage": "litepub:directMessage",
-      "discoverable": "toot:discoverable",
-      "PropertyValue": "schema:PropertyValue",
-      "value": "schema:value"
+      "toot": "http://joinmastodon.org/ns#",
+      "votersCount": "toot:votersCount"
     }
   ],
-  "id": "https://pirati.ca/objects/ec054ce7-8062-3c1b-016c-910426317080/Create",
+  "id": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110435994705014161/activity",
   "type": "Create",
-  "actor": "https://pirati.ca/profile/heluecht",
-  "published": "2022-03-24T07:17:21Z",
-  "instrument": {
-    "type": "Service",
-    "name": "Friendica 'Siberian Iris' 2022.05-dev-1452",
-    "url": "https://pirati.ca"
-  },
-  "to": ["https://ds9.lemmy.ml/c/testcom"],
+  "actor": "https://masto.qa.urbanwildlife.biz/users/mastodon",
+  "published": "2023-05-26T16:45:48Z",
+  "to": ["https://www.w3.org/ns/activitystreams#Public"],
   "cc": [
-    "https://www.w3.org/ns/activitystreams#Public",
-    "https://ds9.lemmy.ml/c/testcom/followers"
+    "https://masto.qa.urbanwildlife.biz/users/mastodon/followers",
+    "https://lemmy.qa.urbanwildlife.biz/c/lemmy_community",
+    "https://lemmy.qa.urbanwildlife.biz/c/lemmy_community/followers"
   ],
   "object": {
-    "id": "https://pirati.ca/objects/ec054ce7-8062-3c1b-016c-910426317080",
-    "type": "Page",
-    "summary": "",
+    "id": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110435994705014161",
+    "type": "Note",
+    "summary": null,
     "inReplyTo": null,
-    "diaspora:guid": "ec054ce7-8062-3c1b-016c-910426317080",
-    "published": "2022-03-24T07:17:21Z",
-    "url": "https://www.nasaspaceflight.com/2022/03/us-eva-80/",
-    "attributedTo": "https://pirati.ca/profile/heluecht",
+    "published": "2023-05-26T16:45:48Z",
+    "url": "https://masto.qa.urbanwildlife.biz/@mastodon/110435994705014161",
+    "attributedTo": "https://masto.qa.urbanwildlife.biz/users/mastodon",
+    "to": ["https://www.w3.org/ns/activitystreams#Public"],
+    "cc": [
+      "https://masto.qa.urbanwildlife.biz/users/mastodon/followers",
+      "https://lemmy.qa.urbanwildlife.biz/c/lemmy_community",
+      "https://lemmy.qa.urbanwildlife.biz/c/lemmy_community/followers"
+    ],
     "sensitive": false,
-    "context": "https://pirati.ca/objects/ec054ce7-8062-3c1b-016c-910426317080#context",
-    "name": "ISS astronauts perform final spacewalk of Expedition 66",
-    "content": "Expedition 66 astronauts Raja Chari and Matthias Maurer ventured outside the International Space Station on Wednesday, performing a spacewalk to carry out repairs and upgrades on the space station.",
+    "atomUri": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110435994705014161",
+    "inReplyToAtomUri": null,
+    "conversation": "tag:masto.qa.urbanwildlife.biz,2023-05-26:objectId=61:objectType=Conversation",
+    "content": "<p>Test post to community</p><p><span class=\"h-card\"><a href=\"https://lemmy.qa.urbanwildlife.biz/c/lemmy_community\" class=\"u-url mention\">@<span>lemmy_community</span></a></span></p>",
     "contentMap": {
-      "de": "<bdi>!<a href=\"https://ds9.lemmy.ml/c/testcom\" class=\"userinfo mention\" title=\"testcom\">testcom</a></bdi> Expedition 66 astronauts Raja Chari and Matthias Maurer ventured outside the International Space Station on Wednesday, performing a spacewalk to carry out repairs and upgrades on the space station.<br><a href=\"https://www.nasaspaceflight.com/2022/03/us-eva-80/\" target=\"_blank\" rel=\"noopener noreferrer\">ISS astronauts perform final spacewalk of Expedition 66</a>"
-    },
-    "source": {
-      "content": "![url=https://ds9.lemmy.ml/c/testcom]testcom[/url] Expedition 66 astronauts Raja Chari and Matthias Maurer ventured outside the International Space Station on Wednesday, performing a spacewalk to carry out repairs and upgrades on the space station.\n[attachment type='link' url='https://www.nasaspaceflight.com/2022/03/us-eva-80/' title='ISS astronauts perform final spacewalk of Expedition 66' publisher_name='NASASpaceFlight.com' publisher_url='https://www.nasaspaceflight.com/' publisher_img='https://www.nasaspaceflight.com/wp-content/uploads/2017/12/logo.svg' author_name='Justin Davenport' author_url='https://www.nasaspaceflight.com/author/justin/' author_img='https://secure.gravatar.com/avatar/5dc0dc04b38dbb016bf6f15552555883?s=96&amp;d=mm&amp;r=g' image='https://www.nasaspaceflight.com/wp-content/uploads/2022/03/51941297402_fa7a00c1ee_o-scaled.jpg']Expedition 66 astronauts Raja Chari and Matthias Maurer ventured outside the International Space Station on…[/attachment]",
-      "mediaType": "text/bbcode"
+      "fr": "<p>Test post to community</p><p><span class=\"h-card\"><a href=\"https://lemmy.qa.urbanwildlife.biz/c/lemmy_community\" class=\"u-url mention\">@<span>lemmy_community</span></a></span></p>"
     },
     "attachment": [],
     "tag": [
       {
         "type": "Mention",
-        "href": "https://ds9.lemmy.ml/c/testcom",
-        "name": "@testcom@ds9.lemmy.ml"
+        "href": "https://lemmy.qa.urbanwildlife.biz/c/lemmy_community",
+        "name": "@lemmy_community@lemmy.qa.urbanwildlife.biz"
       }
     ],
-    "to": ["https://ds9.lemmy.ml/c/testcom"],
-    "cc": [
-      "https://www.w3.org/ns/activitystreams#Public",
-      "https://ds9.lemmy.ml/c/testcom/followers"
-    ]
-  },
-  "signature": {
-    "type": "RsaSignature2017",
-    "nonce": "e68dbf66bac13fd0811863c32bbc59ab56dc0ced4a7f0df06a49b015dd142e29",
-    "creator": "https://pirati.ca/profile/heluecht#main-key",
-    "created": "2022-03-24T07:18:24Z",
-    "signatureValue": "T+TZbRA0DhaCG3bRRPXQmxE2bsdIk8j/cueqsXTKCOSbrWvels2B9cg3twAYIfEmtyZ/f6iKz67MnMzAc4wDS5Gm5lJ/bVoweG3+OVtgfpzYUwR85az6qEX7NS0yLNdciqpZnh5J46F8lk+SKuLGEvlGuHVAd5yYXJoSJc0slM3rVvPv1s8toLHsJzM9H9aITLfZdEo99DmGgcAcSm1lrpFlXXMc+nWGAABpvK4eTrhj1auWOs6qb4q9GUyjfg2OdYrEq+vj4tir8uP/2azJHUea2JwIYbu0Cqt13OAPWC4Znz9MZdI6NQcQvipwFRq1tvfjsonzWIkBotDK9seBxTyj1kJfDd9hcPFXQdaNI549U4JJMxenKH5Yj5tj5Df0lg2hiFOCZ5fka5qmVpqDdPni4fnkCICzKpdJwUpwDaJlwbK8tnMlS5stQv+5+fX3O7sTy2z5PiFFYR/DdHHrMAz4eEoYe9AfrUGB5XzSyHRq0YThDMW4expIGm9KZxhfYgnKPVSqmmZLDKMYD69zwV7IMGfj+W9KqbnhrW+v1JQmWSziYmz4g+ESmo+F72kaVqu1UxIi0qToOA/QDp/HOZSM+YJUCQoCL41faO5+7MNrISL8TIjAa8Y5lXrx5oAKEXEx0biqBaxinOdzuqDl8dvyVtPa/DMez8enTbcGzdQ="
+    "replies": {
+      "id": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110435994705014161/replies",
+      "type": "Collection",
+      "first": {
+        "type": "CollectionPage",
+        "next": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110435994705014161/replies?only_other_accounts=true&page=true",
+        "partOf": "https://masto.qa.urbanwildlife.biz/users/mastodon/statuses/110435994705014161/replies",
+        "items": []
+      }
+    }
   }
 }
index e50e6b8a86a6610496c660f060f98bc850044301..afcde4ebf975d90e527b167450763ea8a1a59abf 100644 (file)
@@ -9,6 +9,10 @@
         "@id": "toot:featured",
         "@type": "@id"
       },
+      "featuredTags": {
+        "@id": "toot:featuredTags",
+        "@type": "@id"
+      },
       "alsoKnownAs": {
         "@id": "as:alsoKnownAs",
         "@type": "@id"
@@ -20,7 +24,6 @@
       "schema": "http://schema.org#",
       "PropertyValue": "schema:PropertyValue",
       "value": "schema:value",
-      "IdentityProof": "toot:IdentityProof",
       "discoverable": "toot:discoverable",
       "Device": "toot:Device",
       "Ed25519Signature": "toot:Ed25519Signature",
       "messageFranking": "toot:messageFranking",
       "messageType": "toot:messageType",
       "cipherText": "toot:cipherText",
-      "Hashtag": "as:Hashtag",
+      "suspended": "toot:suspended",
       "focalPoint": {
         "@container": "@list",
         "@id": "toot:focalPoint"
       }
     }
   ],
-  "id": "https://mastodon.madrid/users/felix",
+  "id": "https://masto.qa.urbanwildlife.biz/users/mastodon",
   "type": "Person",
-  "following": "https://mastodon.madrid/users/felix/following",
-  "followers": "https://mastodon.madrid/users/felix/followers",
-  "inbox": "https://mastodon.madrid/users/felix/inbox",
-  "outbox": "https://mastodon.madrid/users/felix/outbox",
-  "featured": "https://mastodon.madrid/users/felix/collections/featured",
-  "preferredUsername": "felix",
-  "name": "",
-  "summary": "<p><a href=\"https://mastodon.madrid/tags/Lemmy\" class=\"mention hashtag\" rel=\"tag\">#<span>Lemmy</span></a> Maintainer</p>",
-  "url": "https://mastodon.madrid/@felix",
+  "following": "https://masto.qa.urbanwildlife.biz/users/mastodon/following",
+  "followers": "https://masto.qa.urbanwildlife.biz/users/mastodon/followers",
+  "inbox": "https://masto.qa.urbanwildlife.biz/users/mastodon/inbox",
+  "outbox": "https://masto.qa.urbanwildlife.biz/users/mastodon/outbox",
+  "featured": "https://masto.qa.urbanwildlife.biz/users/mastodon/collections/featured",
+  "featuredTags": "https://masto.qa.urbanwildlife.biz/users/mastodon/collections/tags",
+  "preferredUsername": "mastodon",
+  "name": "Mastodon",
+  "summary": "",
+  "url": "https://masto.qa.urbanwildlife.biz/@mastodon",
   "manuallyApprovesFollowers": false,
   "discoverable": false,
-  "devices": "https://mastodon.madrid/users/felix/collections/devices",
+  "published": "2022-10-03T00:00:00Z",
+  "devices": "https://masto.qa.urbanwildlife.biz/users/mastodon/collections/devices",
   "publicKey": {
-    "id": "https://mastodon.madrid/users/felix#main-key",
-    "owner": "https://mastodon.madrid/users/felix",
-    "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzc+evQS6XHTUdniPmFfH\n0U6aa4NaGSTQY4fmJna9w9Sr/8nNN4XWbGJLD4kawPxAXMbK63RMkkxvaHI9w+Oe\nd6oIJH2Z5qH4s2eX8f610SGDvyEZltLAY8TkMhNEp+3bOCKf1zG/uCsE7uC6Mjal\nd6KYyqoom5TwO2UWH5r6l3vyLFvnXWX2zOgSWJwLNLxMWkkd9AqM7k9+pgmeaNWD\n6JvG7Na5ywsR4CZrE5PjgtiC9LWP/H3Elgb2nIzye5HUEJuK2h1+eNFP3HSK5CF3\ncrg4DsZ1n5X3fQVm5YmFUYtEMLZL5S18dFsp6uwE0TmVOODJdnJ6+cgu0/8t2ROR\nJQIDAQAB\n-----END PUBLIC KEY-----\n"
+    "id": "https://masto.qa.urbanwildlife.biz/users/mastodon#main-key",
+    "owner": "https://masto.qa.urbanwildlife.biz/users/mastodon",
+    "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtBdE55VmV9gTrhJmRF1K\neX7xTRo17JGQ7d1/KJWsQ1zH62GGeG/E+BG3h/BRtfgI7Z9jwfNEyx8g/Ue8rSeZ\n3M7yc09/Z90uwGVY24hxwAJyzWIN2cv5ayhdtk268byT6NX98a9PQcHlx5i6Bhef\nMlpY73I5gxYlofvwJTHq/VupXVw9K76KId2AgR2z8tLiXPc8TED56HulDWdMlWn3\n9B4mWNYmzMBF7lOl58Ws6bFsiv8GnI3uEywzUGhXqz4242FGveHdAGBaCpUYrm8W\nmT8PArqv3B4fCD1ghakSmxRr3y9clwhkC+kB/aoT6z313uZYbQuvZF1bfbh6EZWm\nIQIDAQAB\n-----END PUBLIC KEY-----\n"
   },
-  "tag": [
-    {
-      "type": "Hashtag",
-      "href": "https://mastodon.madrid/explore/lemmy",
-      "name": "#lemmy"
-    }
-  ],
+  "tag": [],
   "attachment": [],
   "endpoints": {
-    "sharedInbox": "https://mastodon.madrid/inbox"
+    "sharedInbox": "https://masto.qa.urbanwildlife.biz/inbox"
   },
   "icon": {
     "type": "Image",
-    "mediaType": "image/jpeg",
-    "url": "https://mastodon.madrid/system/accounts/avatars/000/087/969/original/ffdd1c832b453bc9.jpg?1598972149"
+    "mediaType": "image/png",
+    "url": "https://masto.qa.urbanwildlife.biz/system/accounts/avatars/109/105/103/301/739/269/original/2cf61ff96e94cb1d.png"
   }
 }
index aaa1e5108140bbe1a3df89d1a678bc9e14239241..750672edb0f025d283edd91dbae46d0184671c67 100644 (file)
@@ -17,7 +17,6 @@ use lemmy_api_common::{
   context::LemmyContext,
   post::{CreatePostReport, PostReportResponse},
   utils::local_user_view_from_jwt,
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   source::{
@@ -26,7 +25,6 @@ use lemmy_db_schema::{
   },
   traits::Reportable,
 };
-use lemmy_db_views::structs::{CommentReportView, PostReportView};
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
@@ -136,17 +134,7 @@ impl ActivityHandler for Report {
           reason: self.summary,
           original_post_body: post.body.clone(),
         };
-
-        let report = PostReport::report(context.pool(), &report_form).await?;
-
-        let post_report_view = PostReportView::read(context.pool(), report.id, actor.id).await?;
-
-        context.send_mod_ws_message(
-          &UserOperation::CreateCommentReport,
-          &PostReportResponse { post_report_view },
-          post.community_id,
-          None,
-        )?;
+        PostReport::report(context.pool(), &report_form).await?;
       }
       PostOrComment::Comment(comment) => {
         let report_form = CommentReportForm {
@@ -155,21 +143,7 @@ impl ActivityHandler for Report {
           original_comment_text: comment.content.clone(),
           reason: self.summary,
         };
-
-        let report = CommentReport::report(context.pool(), &report_form).await?;
-
-        let comment_report_view =
-          CommentReportView::read(context.pool(), report.id, actor.id).await?;
-        let community_id = comment_report_view.community.id;
-
-        context.send_mod_ws_message(
-          &UserOperation::CreateCommentReport,
-          &CommentReportResponse {
-            comment_report_view,
-          },
-          community_id,
-          None,
-        )?;
+        CommentReport::report(context.pool(), &report_form).await?;
       }
     };
     Ok(())
index 5cf1881a3b7c1869a07b3f86e26714a1f5cc0e28..f8bbfa6ce8bc80177ed724ca69466a803df6aae2 100644 (file)
@@ -21,7 +21,6 @@ use lemmy_api_common::{
   community::{CommunityResponse, EditCommunity, HideCommunity},
   context::LemmyContext,
   utils::local_user_view_from_jwt,
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{source::community::Community, traits::Crud};
 use lemmy_utils::error::LemmyError;
@@ -98,17 +97,7 @@ impl ActivityHandler for UpdateCommunity {
 
     let community_update_form = self.object.into_update_form();
 
-    let updated_community =
-      Community::update(context.pool(), community.id, &community_update_form).await?;
-
-    context
-      .send_community_ws_message(
-        &UserOperationCrud::EditCommunity,
-        updated_community.id,
-        None,
-        None,
-      )
-      .await?;
+    Community::update(context.pool(), community.id, &community_update_form).await?;
     Ok(())
   }
 }
index d07a8e663738310dedf534d9c1978451e7183627..814ec0f87dc68e3ca1eb05dda61a1e591dd04522 100644 (file)
@@ -2,7 +2,6 @@ use crate::{
   activities::{
     check_community_deleted_or_removed,
     community::send_activity_in_community,
-    create_or_update::get_comment_notif_recipients,
     generate_activity_id,
     verify_is_public,
     verify_person_in_community,
@@ -25,10 +24,10 @@ use activitypub_federation::{
   traits::{ActivityHandler, Actor, Object},
 };
 use lemmy_api_common::{
+  build_response::send_local_notifs,
   comment::{CommentResponse, CreateComment, EditComment},
   context::LemmyContext,
   utils::{check_post_deleted_or_removed, is_mod_or_admin},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -40,7 +39,7 @@ use lemmy_db_schema::{
   },
   traits::{Crud, Likeable},
 };
-use lemmy_utils::error::LemmyError;
+use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions};
 use url::Url;
 
 #[async_trait::async_trait]
@@ -193,15 +192,17 @@ impl ActivityHandler for CreateOrUpdateNote {
     CommentLike::like(context.pool(), &like_form).await?;
 
     let do_send_email = self.kind == CreateOrUpdateType::Create;
-    let recipients =
-      get_comment_notif_recipients(&self.actor, &comment, do_send_email, context).await?;
-    let notif_type = match self.kind {
-      CreateOrUpdateType::Create => UserOperationCrud::CreateComment,
-      CreateOrUpdateType::Update => UserOperationCrud::EditComment,
-    };
-    context
-      .send_comment_ws_message(&notif_type, comment.id, None, None, None, recipients)
-      .await?;
+    let post_id = comment.post_id;
+    let post = Post::read(context.pool(), post_id).await?;
+    let actor = self.actor.dereference(context).await?;
+
+    // Note:
+    // Although mentions could be gotten from the post tags (they are included there), or the ccs,
+    // Its much easier to scrape them from the comment body, since the API has to do that
+    // anyway.
+    // TODO: for compatibility with other projects, it would be much better to read this from cc or tags
+    let mentions = scrape_text_for_mentions(&comment.content);
+    send_local_notifs(mentions, &comment.0, &actor, &post, do_send_email, context).await?;
     Ok(())
   }
 }
index 9e4fa51b233b476774e3a91e6953dabd2049da55..c69e00e91bdf664e3eaaed1b480b43caa3093eb6 100644 (file)
@@ -1,35 +1,3 @@
-use crate::objects::person::ApubPerson;
-use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
-use lemmy_api_common::context::LemmyContext;
-use lemmy_db_schema::{
-  newtypes::LocalUserId,
-  source::{comment::Comment, post::Post},
-  traits::Crud,
-};
-use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions};
-
 pub mod comment;
 pub mod post;
 pub mod private_message;
-
-#[tracing::instrument(skip_all)]
-async fn get_comment_notif_recipients(
-  actor: &ObjectId<ApubPerson>,
-  comment: &Comment,
-  do_send_email: bool,
-  context: &Data<LemmyContext>,
-) -> Result<Vec<LocalUserId>, LemmyError> {
-  let post_id = comment.post_id;
-  let post = Post::read(context.pool(), post_id).await?;
-  let actor = actor.dereference(context).await?;
-
-  // Note:
-  // Although mentions could be gotten from the post tags (they are included there), or the ccs,
-  // Its much easier to scrape them from the comment body, since the API has to do that
-  // anyway.
-  // TODO: for compatibility with other projects, it would be much better to read this from cc or tags
-  let mentions = scrape_text_for_mentions(&comment.content);
-  context
-    .send_local_notifs(mentions, comment, &actor, &post, do_send_email)
-    .await
-}
index 771e3c3c4580f0c30ec3a404f1c00d3e0606506e..b545f523948a1b3a7931b4fc2e9b01c057a9adcc 100644 (file)
@@ -25,7 +25,6 @@ use activitypub_federation::{
 use lemmy_api_common::{
   context::LemmyContext,
   post::{CreatePost, EditPost, PostResponse},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -191,14 +190,6 @@ impl ActivityHandler for CreateOrUpdatePage {
       score: 1,
     };
     PostLike::like(context.pool(), &like_form).await?;
-
-    let notif_type = match self.kind {
-      CreateOrUpdateType::Create => UserOperationCrud::CreatePost,
-      CreateOrUpdateType::Update => UserOperationCrud::EditPost,
-    };
-    context
-      .send_post_ws_message(&notif_type, post.id, None, None)
-      .await?;
     Ok(())
   }
 }
index 85051344f657e0c6b10767a1397bf1ce40ad7257..691eff300079fdcfd8812498d007f94746d66cc5 100644 (file)
@@ -16,7 +16,6 @@ use activitypub_federation::{
 use lemmy_api_common::{
   context::LemmyContext,
   private_message::{CreatePrivateMessage, EditPrivateMessage, PrivateMessageResponse},
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   newtypes::PersonId,
@@ -118,16 +117,7 @@ impl ActivityHandler for CreateOrUpdateChatMessage {
   #[tracing::instrument(skip_all)]
   async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
     insert_activity(&self.id, &self, false, true, context).await?;
-    let private_message = ApubPrivateMessage::from_json(self.object, context).await?;
-
-    let notif_type = match self.kind {
-      CreateOrUpdateType::Create => UserOperationCrud::CreatePrivateMessage,
-      CreateOrUpdateType::Update => UserOperationCrud::EditPrivateMessage,
-    };
-    context
-      .send_pm_ws_message(&notif_type, private_message.id, None)
-      .await?;
-
+    ApubPrivateMessage::from_json(self.object, context).await?;
     Ok(())
   }
 }
index 1bb3b6c417df43f9a299e904c6cf247c007cb9e1..dfa709c36d3bcefc4b783c323ad4c49dc2c4e76e 100644 (file)
@@ -8,7 +8,7 @@ use crate::{
   protocol::{activities::deletion::delete::Delete, IdOrNestedObject},
 };
 use activitypub_federation::{config::Data, kinds::activity::DeleteType, traits::ActivityHandler};
-use lemmy_api_common::{context::LemmyContext, websocket::UserOperationCrud};
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{
     comment::{Comment, CommentUpdateForm},
@@ -105,7 +105,6 @@ pub(in crate::activities) async fn receive_remove_action(
   reason: Option<String>,
   context: &Data<LemmyContext>,
 ) -> Result<(), LemmyError> {
-  use UserOperationCrud::*;
   match DeletableObjects::read_from_db(object, context).await? {
     DeletableObjects::Community(community) => {
       if community.local {
@@ -121,16 +120,12 @@ pub(in crate::activities) async fn receive_remove_action(
         expires: None,
       };
       ModRemoveCommunity::create(context.pool(), &form).await?;
-      let deleted_community = Community::update(
+      Community::update(
         context.pool(),
         community.id,
         &CommunityUpdateForm::builder().removed(Some(true)).build(),
       )
       .await?;
-
-      context
-        .send_community_ws_message(&RemoveCommunity, deleted_community.id, None, None)
-        .await?;
     }
     DeletableObjects::Post(post) => {
       let form = ModRemovePostForm {
@@ -140,16 +135,12 @@ pub(in crate::activities) async fn receive_remove_action(
         reason,
       };
       ModRemovePost::create(context.pool(), &form).await?;
-      let removed_post = Post::update(
+      Post::update(
         context.pool(),
         post.id,
         &PostUpdateForm::builder().removed(Some(true)).build(),
       )
       .await?;
-
-      context
-        .send_post_ws_message(&RemovePost, removed_post.id, None, None)
-        .await?;
     }
     DeletableObjects::Comment(comment) => {
       let form = ModRemoveCommentForm {
@@ -159,16 +150,12 @@ pub(in crate::activities) async fn receive_remove_action(
         reason,
       };
       ModRemoveComment::create(context.pool(), &form).await?;
-      let removed_comment = Comment::update(
+      Comment::update(
         context.pool(),
         comment.id,
         &CommentUpdateForm::builder().removed(Some(true)).build(),
       )
       .await?;
-
-      context
-        .send_comment_ws_message_simple(&RemoveComment, removed_comment.id)
-        .await?;
     }
     DeletableObjects::PrivateMessage(_) => unimplemented!(),
   }
index ea6f4a67d5457ff14d689549eda27130b70dcf97..3bde90f9395f6b20f453bfd82ed3cfada589e997 100644 (file)
@@ -35,7 +35,6 @@ use lemmy_api_common::{
   post::{DeletePost, PostResponse, RemovePost},
   private_message::{DeletePrivateMessage, PrivateMessageResponse},
   utils::local_user_view_from_jwt,
-  websocket::UserOperationCrud,
 };
 use lemmy_db_schema::{
   source::{
@@ -388,7 +387,7 @@ async fn receive_delete_action(
         send_apub_delete_in_community(mod_, c, object, None, true, context).await?;
       }
 
-      let community = Community::update(
+      Community::update(
         context.pool(),
         community.id,
         &CommunityUpdateForm::builder()
@@ -396,43 +395,29 @@ async fn receive_delete_action(
           .build(),
       )
       .await?;
-      context
-        .send_community_ws_message(
-          &UserOperationCrud::DeleteCommunity,
-          community.id,
-          None,
-          None,
-        )
-        .await?;
     }
     DeletableObjects::Post(post) => {
       if deleted != post.deleted {
-        let deleted_post = Post::update(
+        Post::update(
           context.pool(),
           post.id,
           &PostUpdateForm::builder().deleted(Some(deleted)).build(),
         )
         .await?;
-        context
-          .send_post_ws_message(&UserOperationCrud::DeletePost, deleted_post.id, None, None)
-          .await?;
       }
     }
     DeletableObjects::Comment(comment) => {
       if deleted != comment.deleted {
-        let deleted_comment = Comment::update(
+        Comment::update(
           context.pool(),
           comment.id,
           &CommentUpdateForm::builder().deleted(Some(deleted)).build(),
         )
         .await?;
-        context
-          .send_comment_ws_message_simple(&UserOperationCrud::DeleteComment, deleted_comment.id)
-          .await?;
       }
     }
     DeletableObjects::PrivateMessage(pm) => {
-      let deleted_private_message = PrivateMessage::update(
+      PrivateMessage::update(
         context.pool(),
         pm.id,
         &PrivateMessageUpdateForm::builder()
@@ -440,14 +425,6 @@ async fn receive_delete_action(
           .build(),
       )
       .await?;
-
-      context
-        .send_pm_ws_message(
-          &UserOperationCrud::DeletePrivateMessage,
-          deleted_private_message.id,
-          None,
-        )
-        .await?;
     }
   }
   Ok(())
index 13a32cabcc66082115a35feb62781b550f88fe6b..00768580dda0a3fb8dfcb06137a60d187a0b71fa 100644 (file)
@@ -8,7 +8,7 @@ use crate::{
   protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
 };
 use activitypub_federation::{config::Data, kinds::activity::UndoType, traits::ActivityHandler};
-use lemmy_api_common::{context::LemmyContext, websocket::UserOperationCrud};
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{
     comment::{Comment, CommentUpdateForm},
@@ -97,7 +97,6 @@ impl UndoDelete {
     object: &Url,
     context: &Data<LemmyContext>,
   ) -> Result<(), LemmyError> {
-    use UserOperationCrud::*;
     match DeletableObjects::read_from_db(object, context).await? {
       DeletableObjects::Community(community) => {
         if community.local {
@@ -113,15 +112,12 @@ impl UndoDelete {
           expires: None,
         };
         ModRemoveCommunity::create(context.pool(), &form).await?;
-        let deleted_community = Community::update(
+        Community::update(
           context.pool(),
           community.id,
           &CommunityUpdateForm::builder().removed(Some(false)).build(),
         )
         .await?;
-        context
-          .send_community_ws_message(&EditCommunity, deleted_community.id, None, None)
-          .await?;
       }
       DeletableObjects::Post(post) => {
         let form = ModRemovePostForm {
@@ -131,15 +127,12 @@ impl UndoDelete {
           reason: None,
         };
         ModRemovePost::create(context.pool(), &form).await?;
-        let removed_post = Post::update(
+        Post::update(
           context.pool(),
           post.id,
           &PostUpdateForm::builder().removed(Some(false)).build(),
         )
         .await?;
-        context
-          .send_post_ws_message(&EditPost, removed_post.id, None, None)
-          .await?;
       }
       DeletableObjects::Comment(comment) => {
         let form = ModRemoveCommentForm {
@@ -149,15 +142,12 @@ impl UndoDelete {
           reason: None,
         };
         ModRemoveComment::create(context.pool(), &form).await?;
-        let removed_comment = Comment::update(
+        Comment::update(
           context.pool(),
           comment.id,
           &CommentUpdateForm::builder().removed(Some(false)).build(),
         )
         .await?;
-        context
-          .send_comment_ws_message_simple(&EditComment, removed_comment.id)
-          .await?;
       }
       DeletableObjects::PrivateMessage(_) => unimplemented!(),
     }
index 34dc976ded2db5fd148d631eb31d94852203e842..7b9ab6802311e3749af46bd14f4840b24cca1013 100644 (file)
@@ -9,21 +9,8 @@ use activitypub_federation::{
   protocol::verification::verify_urls_match,
   traits::{ActivityHandler, Actor},
 };
-use lemmy_api_common::{
-  community::CommunityResponse,
-  context::LemmyContext,
-  websocket::{
-    handlers::messages::SendUserRoomMessage,
-    serialize_websocket_message,
-    UserOperation,
-  },
-};
-use lemmy_db_schema::{
-  source::{actor_language::CommunityLanguage, community::CommunityFollower},
-  traits::Followable,
-};
-use lemmy_db_views::structs::LocalUserView;
-use lemmy_db_views_actor::structs::CommunityView;
+use lemmy_api_common::context::LemmyContext;
+use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
 use lemmy_utils::error::LemmyError;
 use url::Url;
 
@@ -81,31 +68,6 @@ impl ActivityHandler for AcceptFollow {
     let person_id = person.id;
     CommunityFollower::follow_accepted(context.pool(), community_id, person_id).await?;
 
-    // Send the Subscribed message over websocket
-    // Re-read the community_view to get the new SubscribedType
-    let community_view =
-      CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
-
-    // Get the local_user_id
-    let local_recipient_id = LocalUserView::read_person(context.pool(), person_id)
-      .await?
-      .local_user
-      .id;
-    let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
-
-    let res = CommunityResponse {
-      community_view,
-      discussion_languages,
-    };
-
-    let message = serialize_websocket_message(&UserOperation::FollowCommunity, &res)?;
-
-    context.chat_server().do_send(SendUserRoomMessage {
-      recipient_id: local_recipient_id,
-      message,
-      websocket_id: None,
-    });
-
     Ok(())
   }
 }
index 0a7981a47c82f03413c83cd2b6e6fef88ce371d0..4b9e6b5a94590726e0b45cd098f10ce8f75ada7e 100644 (file)
@@ -116,16 +116,6 @@ use lemmy_api_common::{
     SearchResponse,
     SiteResponse,
   },
-  websocket::structs::{
-    CommunityJoin,
-    CommunityJoinResponse,
-    ModJoin,
-    ModJoinResponse,
-    PostJoin,
-    PostJoinResponse,
-    UserJoin,
-    UserJoinResponse,
-  },
 };
 
 impl SendActivity for Register {
@@ -240,22 +230,6 @@ 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;
 }
index 60015b137c368ea0b49de82d8234286fa4333e2b..8bae05577ef36645e62444894967a8a87b86c355 100644 (file)
@@ -16,7 +16,6 @@ use lemmy_api_common::{
   post::{CreatePostLike, PostResponse},
   sensitive::Sensitive,
   utils::local_user_view_from_jwt,
-  websocket::UserOperation,
 };
 use lemmy_db_schema::{
   newtypes::CommunityId,
@@ -121,10 +120,6 @@ async fn vote_comment(
   let person_id = actor.id;
   CommentLike::remove(context.pool(), person_id, comment_id).await?;
   CommentLike::like(context.pool(), &like_form).await?;
-
-  context
-    .send_comment_ws_message_simple(&UserOperation::CreateCommentLike, comment_id)
-    .await?;
   Ok(())
 }
 
@@ -144,10 +139,6 @@ async fn vote_post(
   let person_id = actor.id;
   PostLike::remove(context.pool(), person_id, post_id).await?;
   PostLike::like(context.pool(), &like_form).await?;
-
-  context
-    .send_post_ws_message(&UserOperation::CreatePostLike, post.id, None, None)
-    .await?;
   Ok(())
 }
 
@@ -160,10 +151,6 @@ async fn undo_vote_comment(
   let comment_id = comment.id;
   let person_id = actor.id;
   CommentLike::remove(context.pool(), person_id, comment_id).await?;
-
-  context
-    .send_comment_ws_message_simple(&UserOperation::CreateCommentLike, comment_id)
-    .await?;
   Ok(())
 }
 
@@ -176,9 +163,5 @@ async fn undo_vote_post(
   let post_id = post.id;
   let person_id = actor.id;
   PostLike::remove(context.pool(), person_id, post_id).await?;
-
-  context
-    .send_post_ws_message(&UserOperation::CreatePostLike, post_id, None, None)
-    .await?;
   Ok(())
 }
index f697a735833e7d304fba0fde888bfb055c56ad42..b3a1b7cf2e57725f57dd5a155fd403f1705ee4a7 100644 (file)
@@ -14,18 +14,14 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_db_views::comment_view::CommentQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait]
 impl PerformApub for GetComments {
   type Response = GetCommentsResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetCommentsResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetCommentsResponse, LemmyError> {
     let data: &GetComments = self;
     let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
     let local_site = LocalSite::read(context.pool()).await?;
index 58c31b2e652a8a50a8ffbce95646751e7cd7b3f1..99c790c7337c95e129458940868f31d4c56516d6 100644 (file)
@@ -11,18 +11,14 @@ use lemmy_api_common::{
 };
 use lemmy_db_schema::source::{community::Community, local_site::LocalSite};
 use lemmy_db_views::post_view::PostQuery;
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait]
 impl PerformApub for GetPosts {
   type Response = GetPostsResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetPostsResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetPostsResponse, LemmyError> {
     let data: &GetPosts = self;
     let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
     let local_site = LocalSite::read(context.pool()).await?;
index 9099dbd09d04445bb83e25ef1ec28268182d5f00..d95c9b51b8a8d1491757ac093956ef7139fb867a 100644 (file)
@@ -1,7 +1,7 @@
 use activitypub_federation::config::Data;
 use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{newtypes::CommunityId, source::local_site::LocalSite, ListingType};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 mod list_comments;
 mod list_posts;
@@ -14,11 +14,7 @@ mod search;
 pub trait PerformApub {
   type Response: serde::ser::Serialize + Send;
 
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError>;
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
 }
 
 /// Returns default listing type, depending if the query is for frontpage or community.
index 53469cf84b6daef322c1b18a1448d55589f68c28..a197589901c9376acb6effb36c7fb9e8a89e2e4a 100644 (file)
@@ -8,7 +8,6 @@ use lemmy_api_common::{
   community::{GetCommunity, GetCommunityResponse},
   context::LemmyContext,
   utils::{check_private_instance, is_mod_or_admin_opt, local_user_view_from_jwt_opt},
-  websocket::handlers::online_users::GetCommunityUsersOnline,
 };
 use lemmy_db_schema::source::{
   actor_language::CommunityLanguage,
@@ -17,17 +16,16 @@ use lemmy_db_schema::source::{
   site::Site,
 };
 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait]
 impl PerformApub for GetCommunity {
   type Response = GetCommunityResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<GetCommunityResponse, LemmyError> {
     let data: &GetCommunity = self;
     let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
@@ -70,11 +68,6 @@ impl PerformApub for GetCommunity {
       .await
       .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
 
-    let online = context
-      .chat_server()
-      .send(GetCommunityUsersOnline { community_id })
-      .await?;
-
     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.into()).await?;
@@ -93,7 +86,6 @@ impl PerformApub for GetCommunity {
       community_view,
       site,
       moderators,
-      online,
       discussion_languages,
     };
 
index 9d453acee5d91aa79371e231717f880396462378..1e4797fa4fb9482bcaee00ff948ea25e6b4bdcb3 100644 (file)
@@ -11,17 +11,16 @@ use lemmy_db_schema::{
 };
 use lemmy_db_views::{comment_view::CommentQuery, post_view::PostQuery};
 use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait]
 impl PerformApub for GetPersonDetails {
   type Response = GetPersonDetailsResponse;
 
-  #[tracing::instrument(skip(self, context, _websocket_id))]
+  #[tracing::instrument(skip(self, context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<GetPersonDetailsResponse, LemmyError> {
     let data: &GetPersonDetails = self;
 
index 193494ddbae2422fa0377eb487a4b2a7ddf0087c..951cd45516a2fdc7b8a2cb5457109ab645f7325b 100644 (file)
@@ -12,17 +12,16 @@ use lemmy_api_common::{
 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, PersonView};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait]
 impl PerformApub for ResolveObject {
   type Response = ResolveObjectResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
+  #[tracing::instrument(skip(context))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
   ) -> Result<ResolveObjectResponse, LemmyError> {
     let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
     let local_site = LocalSite::read(context.pool()).await?;
index 6cbd6b1e5f5b8b489ee34466fa85cf8526820706..025d1408af3e664d92c7168bf3def9625b791282 100644 (file)
@@ -16,18 +16,14 @@ use lemmy_db_schema::{
 };
 use lemmy_db_views::{comment_view::CommentQuery, post_view::PostQuery};
 use lemmy_db_views_actor::{community_view::CommunityQuery, person_view::PersonQuery};
-use lemmy_utils::{error::LemmyError, ConnectionId};
+use lemmy_utils::error::LemmyError;
 
 #[async_trait::async_trait]
 impl PerformApub for Search {
   type Response = SearchResponse;
 
-  #[tracing::instrument(skip(context, _websocket_id))]
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    _websocket_id: Option<ConnectionId>,
-  ) -> Result<SearchResponse, LemmyError> {
+  #[tracing::instrument(skip(context))]
+  async fn perform(&self, context: &Data<LemmyContext>) -> Result<SearchResponse, LemmyError> {
     let data: &Search = self;
 
     let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
index 1dbc7c63abbdd27ff389d2865453ee1d35a4a68e..5d133e9b848469cfe240dfe4a8e9926cc9f523aa 100644 (file)
@@ -55,13 +55,8 @@ pub(crate) fn verify_is_remote_object(id: &Url, settings: &Settings) -> Result<(
 #[cfg(test)]
 pub(crate) mod tests {
   use activitypub_federation::config::{Data, FederationConfig};
-  use actix::Actor;
   use anyhow::anyhow;
-  use lemmy_api_common::{
-    context::LemmyContext,
-    request::build_user_agent,
-    websocket::chat_server::ChatServer,
-  };
+  use lemmy_api_common::{context::LemmyContext, request::build_user_agent};
   use lemmy_db_schema::{source::secret::Secret, utils::build_db_pool_for_tests};
   use lemmy_utils::{
     rate_limit::{RateLimitCell, RateLimitConfig},
@@ -106,8 +101,7 @@ pub(crate) mod tests {
     let rate_limit_config = RateLimitConfig::builder().build();
     let rate_limit_cell = RateLimitCell::new(rate_limit_config).await;
 
-    let chat_server = ChatServer::default().start();
-    let context = LemmyContext::create(pool, chat_server, client, secret, rate_limit_cell.clone());
+    let context = LemmyContext::create(pool, client, secret, rate_limit_cell.clone());
     let config = FederationConfig::builder()
       .domain("example.com")
       .app_data(context)
index 3259fd17ddd999a5f316717d705f4bb89d63ceab..faf08938bd2458dcaff99b60e05dd8807c2740fb 100644 (file)
@@ -38,7 +38,6 @@ use lemmy_api_common::{
     ChangePassword,
     DeleteAccount,
     GetBannedPersons,
-    GetCaptcha,
     GetPersonDetails,
     GetPersonMentions,
     GetReplies,
@@ -98,7 +97,6 @@ use lemmy_api_common::{
     ResolveObject,
     Search,
   },
-  websocket::structs::{CommunityJoin, ModJoin, PostJoin, UserJoin},
 };
 use lemmy_api_crud::PerformCrud;
 use lemmy_apub::{api::PerformApub, SendActivity};
@@ -159,9 +157,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
           )
           .route("/transfer", web::post().to(route_post::<TransferCommunity>))
           .route("/ban_user", web::post().to(route_post::<BanFromCommunity>))
-          .route("/mod", web::post().to(route_post::<AddModToCommunity>))
-          .route("/join", web::post().to(route_post::<CommunityJoin>))
-          .route("/mod/join", web::post().to(route_post::<ModJoin>)),
+          .route("/mod", web::post().to(route_post::<AddModToCommunity>)),
       )
       .service(
         web::scope("/federated_instances")
@@ -192,7 +188,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
           .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>))
           .route("/report", web::post().to(route_post::<CreatePostReport>))
           .route(
             "/report/resolve",
@@ -277,12 +272,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
           .wrap(rate_limit.register())
           .route(web::post().to(route_post_crud::<Register>)),
       )
-      .service(
-        // Handle captcha separately
-        web::resource("/user/get_captcha")
-          .wrap(rate_limit.post())
-          .route(web::get().to(route_get::<GetCaptcha>)),
-      )
       // User actions
       .service(
         web::scope("/user")
@@ -294,7 +283,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
             web::post().to(route_post::<MarkPersonMentionAsRead>),
           )
           .route("/replies", web::get().to(route_get::<GetReplies>))
-          .route("/join", web::post().to(route_post::<UserJoin>))
           // Admin action. I don't like that it's in /user
           .route("/ban", web::post().to(route_post::<BanPerson>))
           .route("/banned", web::get().to(route_get::<GetBannedPersons>))
@@ -383,7 +371,7 @@ where
     + Send
     + 'static,
 {
-  let res = data.perform(&context, None).await?;
+  let res = data.perform(&context).await?;
   SendActivity::send_activity(&data, &res, &apub_data).await?;
   Ok(HttpResponse::Ok().json(res))
 }
@@ -416,7 +404,7 @@ where
     + Send
     + 'static,
 {
-  let res = data.perform(&context, None).await?;
+  let res = data.perform(&context).await?;
   SendActivity::send_activity(&data.0, &res, &context).await?;
   Ok(HttpResponse::Ok().json(res))
 }
@@ -450,7 +438,7 @@ where
     + Send
     + 'static,
 {
-  let res = data.perform(&context, None).await?;
+  let res = data.perform(&context).await?;
   SendActivity::send_activity(&data, &res, &apub_data).await?;
   Ok(HttpResponse::Ok().json(res))
 }
index 21a4c25b5d557355a781d39009f6c167b48a3790..7cf3d80107ba9df4721679aca8098d746d411ebc 100644 (file)
@@ -7,7 +7,6 @@ pub mod telemetry;
 
 use crate::{code_migrations::run_advanced_migrations, root_span_builder::QuieterRootSpanBuilder};
 use activitypub_federation::config::{FederationConfig, FederationMiddleware};
-use actix::Actor;
 use actix_cors::Cors;
 use actix_web::{middleware, web::Data, App, HttpServer, Result};
 use doku::json::{AutoComments, CommentsStyle, Formatting, ObjectsStyle};
@@ -19,7 +18,6 @@ use lemmy_api_common::{
     check_private_instance_and_federation_enabled,
     local_site_rate_limit_to_rate_limit_config,
   },
-  websocket::chat_server::ChatServer,
 };
 use lemmy_apub::{VerifyUrlData, FEDERATION_HTTP_FETCH_LIMIT};
 use lemmy_db_schema::{
@@ -126,14 +124,11 @@ pub async fn start_lemmy_server() -> Result<(), LemmyError> {
     scheduled_tasks::setup(db_url, user_agent).expect("Couldn't set up scheduled_tasks");
   });
 
-  let chat_server = ChatServer::default().start();
-
   // Create Http server with websocket support
   let settings_bind = settings.clone();
   HttpServer::new(move || {
     let context = LemmyContext::create(
       pool.clone(),
-      chat_server.clone(),
       client.clone(),
       secret.clone(),
       rate_limit_cell.clone(),