diff --git a/Cargo.lock b/Cargo.lock index 159912e47..17d854857 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 344e4646f..eeeb9c32b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index 69f1b28e4..2488f2c2c 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -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 } diff --git a/crates/api/src/comment/distinguish.rs b/crates/api/src/comment/distinguish.rs index 73e1469e3..17f45bfd4 100644 --- a/crates/api/src/comment/distinguish.rs +++ b/crates/api/src/comment/distinguish.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &DistinguishComment = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/comment/like.rs b/crates/api/src/comment/like.rs index b6e7e5043..6c4bdebc7 100644 --- a/crates/api/src/comment/like.rs +++ b/crates/api/src/comment/like.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api/src/comment/save.rs b/crates/api/src/comment/save.rs index d52b3322d..70c9745f8 100644 --- a/crates/api/src/comment/save.rs +++ b/crates/api/src/comment/save.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &SaveComment = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/comment_report/create.rs b/crates/api/src/comment_report/create.rs index 8d016bf53..8ef975786 100644 --- a/crates/api/src/comment_report/create.rs +++ b/crates/api/src/comment_report/create.rs @@ -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, - websocket_id: Option, ) -> Result { 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) + }) } } diff --git a/crates/api/src/comment_report/list.rs b/crates/api/src/comment_report/list.rs index 2cd9ca1bd..d8a4221db 100644 --- a/crates/api/src/comment_report/list.rs +++ b/crates/api/src/comment_report/list.rs @@ -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, - _websocket_id: Option, ) -> Result { 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 }) } } diff --git a/crates/api/src/comment_report/resolve.rs b/crates/api/src/comment_report/resolve.rs index 4ba45481f..5f1ae97dd 100644 --- a/crates/api/src/comment_report/resolve.rs +++ b/crates/api/src/comment_report/resolve.rs @@ -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, - websocket_id: Option, ) -> Result { 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) + }) } } diff --git a/crates/api/src/community/add_mod.rs b/crates/api/src/community/add_mod.rs index 80c470de9..a7afd952d 100644 --- a/crates/api/src/community/add_mod.rs +++ b/crates/api/src/community/add_mod.rs @@ -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, - websocket_id: Option, ) -> Result { 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 }) } } diff --git a/crates/api/src/community/ban.rs b/crates/api/src/community/ban.rs index 47cb6798f..a0fd7bf18 100644 --- a/crates/api/src/community/ban.rs +++ b/crates/api/src/community/ban.rs @@ -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, - websocket_id: Option, ) -> Result { 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) + }) } } diff --git a/crates/api/src/community/block.rs b/crates/api/src/community/block.rs index 21112971f..fe3fb6e07 100644 --- a/crates/api/src/community/block.rs +++ b/crates/api/src/community/block.rs @@ -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, - _websocket_id: Option, ) -> Result { let data: &BlockCommunity = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/community/follow.rs b/crates/api/src/community/follow.rs index 9e4efb33f..ae1ed6a4b 100644 --- a/crates/api/src/community/follow.rs +++ b/crates/api/src/community/follow.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &FollowCommunity = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/community/hide.rs b/crates/api/src/community/hide.rs index e33bf32ca..f8d4b1fd7 100644 --- a/crates/api/src/community/hide.rs +++ b/crates/api/src/community/hide.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api/src/community/transfer.rs b/crates/api/src/community/transfer.rs index def3df0fa..10ba1c4fa 100644 --- a/crates/api/src/community/transfer.rs +++ b/crates/api/src/community/transfer.rs @@ -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, - _websocket_id: Option, ) -> Result { 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![], }) } diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 5c23ec345..9ff1677d0 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -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, - websocket_id: Option, - ) -> Result; -} - -/// 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 = 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) -> Result; } /// Check size of report and remove whitespace diff --git a/crates/api/src/local_user/add_admin.rs b/crates/api/src/local_user/add_admin.rs index 5de584650..0d2db3771 100644 --- a/crates/api/src/local_user/add_admin.rs +++ b/crates/api/src/local_user/add_admin.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 }) } } diff --git a/crates/api/src/local_user/ban_person.rs b/crates/api/src/local_user/ban_person.rs index 014f98b8d..452557d2c 100644 --- a/crates/api/src/local_user/ban_person.rs +++ b/crates/api/src/local_user/ban_person.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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) + }) } } diff --git a/crates/api/src/local_user/block.rs b/crates/api/src/local_user/block.rs index 5a4c9dca0..c9eaa2725 100644 --- a/crates/api/src/local_user/block.rs +++ b/crates/api/src/local_user/block.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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) + }) } } diff --git a/crates/api/src/local_user/change_password.rs b/crates/api/src/local_user/change_password.rs index 2b486a5ed..60e0b960d 100644 --- a/crates/api/src/local_user/change_password.rs +++ b/crates/api/src/local_user/change_password.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(self, context))] + async fn perform(&self, context: &Data) -> Result { let data: &ChangePassword = self; let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?; diff --git a/crates/api/src/local_user/change_password_after_reset.rs b/crates/api/src/local_user/change_password_after_reset.rs index 04571e47b..de05f8e59 100644 --- a/crates/api/src/local_user/change_password_after_reset.rs +++ b/crates/api/src/local_user/change_password_after_reset.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(self, context))] + async fn perform(&self, context: &Data) -> Result { 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 index 00ec45a13..000000000 --- a/crates/api/src/local_user/get_captcha.rs +++ /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, - _websocket_id: Option, - ) -> Result { - 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 }), - }) - } -} diff --git a/crates/api/src/local_user/list_banned.rs b/crates/api/src/local_user/list_banned.rs index e1d0f6e75..5e2c027ba 100644 --- a/crates/api/src/local_user/list_banned.rs +++ b/crates/api/src/local_user/list_banned.rs @@ -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, - _websocket_id: Option, - ) -> Result { + async fn perform(&self, context: &Data) -> Result { 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 }) } } diff --git a/crates/api/src/local_user/login.rs b/crates/api/src/local_user/login.rs index 25323c453..9f5e58744 100644 --- a/crates/api/src/local_user/login.rs +++ b/crates/api/src/local_user/login.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &Login = self; let site_view = SiteView::read_local(context.pool()).await?; diff --git a/crates/api/src/local_user/mod.rs b/crates/api/src/local_user/mod.rs index 3a92beda5..9244f825d 100644 --- a/crates/api/src/local_user/mod.rs +++ b/crates/api/src/local_user/mod.rs @@ -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; diff --git a/crates/api/src/local_user/notifications/list_mentions.rs b/crates/api/src/local_user/notifications/list_mentions.rs index fbafdb52a..4c8d2cf55 100644 --- a/crates/api/src/local_user/notifications/list_mentions.rs +++ b/crates/api/src/local_user/notifications/list_mentions.rs @@ -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, - _websocket_id: Option, ) -> Result { let data: &GetPersonMentions = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/local_user/notifications/list_replies.rs b/crates/api/src/local_user/notifications/list_replies.rs index 797b6f8d4..6d1d8f0bd 100644 --- a/crates/api/src/local_user/notifications/list_replies.rs +++ b/crates/api/src/local_user/notifications/list_replies.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &GetReplies = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/local_user/notifications/mark_all_read.rs b/crates/api/src/local_user/notifications/mark_all_read.rs index dfda897a9..cc2999698 100644 --- a/crates/api/src/local_user/notifications/mark_all_read.rs +++ b/crates/api/src/local_user/notifications/mark_all_read.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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; diff --git a/crates/api/src/local_user/notifications/mark_mention_read.rs b/crates/api/src/local_user/notifications/mark_mention_read.rs index 80781e72a..dd3c413f2 100644 --- a/crates/api/src/local_user/notifications/mark_mention_read.rs +++ b/crates/api/src/local_user/notifications/mark_mention_read.rs @@ -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, - _websocket_id: Option, ) -> Result { let data: &MarkPersonMentionAsRead = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/local_user/notifications/mark_reply_read.rs b/crates/api/src/local_user/notifications/mark_reply_read.rs index 1e3fad19d..a8291cd50 100644 --- a/crates/api/src/local_user/notifications/mark_reply_read.rs +++ b/crates/api/src/local_user/notifications/mark_reply_read.rs @@ -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, - _websocket_id: Option, ) -> Result { let data = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/local_user/notifications/unread_count.rs b/crates/api/src/local_user/notifications/unread_count.rs index 523e9a73f..21e584d51 100644 --- a/crates/api/src/local_user/notifications/unread_count.rs +++ b/crates/api/src/local_user/notifications/unread_count.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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) + }) } } diff --git a/crates/api/src/local_user/report_count.rs b/crates/api/src/local_user/report_count.rs index b2f4912cc..c09280d80 100644 --- a/crates/api/src/local_user/report_count.rs +++ b/crates/api/src/local_user/report_count.rs @@ -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, - _websocket_id: Option, ) -> Result { 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) + }) } } diff --git a/crates/api/src/local_user/reset_password.rs b/crates/api/src/local_user/reset_password.rs index 5d0e9d88b..3c07b2e4d 100644 --- a/crates/api/src/local_user/reset_password.rs +++ b/crates/api/src/local_user/reset_password.rs @@ -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, - _websocket_id: Option, ) -> Result { let data: &PasswordReset = self; diff --git a/crates/api/src/local_user/save_settings.rs b/crates/api/src/local_user/save_settings.rs index a04086125..e74266fc9 100644 --- a/crates/api/src/local_user/save_settings.rs +++ b/crates/api/src/local_user/save_settings.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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?; diff --git a/crates/api/src/local_user/verify_email.rs b/crates/api/src/local_user/verify_email.rs index fb82b716b..80befc5a8 100644 --- a/crates/api/src/local_user/verify_email.rs +++ b/crates/api/src/local_user/verify_email.rs @@ -19,11 +19,7 @@ use lemmy_utils::error::LemmyError; impl Perform for VerifyEmail { type Response = VerifyEmailResponse; - async fn perform( - &self, - context: &Data, - _websocket_id: Option, - ) -> Result { + async fn perform(&self, context: &Data) -> Result { let token = self.token.clone(); let verification = EmailVerification::read_for_token(context.pool(), &token) .await diff --git a/crates/api/src/post/feature.rs b/crates/api/src/post/feature.rs index 6d9f05f07..3c9e1a1c0 100644 --- a/crates/api/src/post/feature.rs +++ b/crates/api/src/post/feature.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api/src/post/get_link_metadata.rs b/crates/api/src/post/get_link_metadata.rs index eaf111eba..a67ea3f6f 100644 --- a/crates/api/src/post/get_link_metadata.rs +++ b/crates/api/src/post/get_link_metadata.rs @@ -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, - _websocket_id: Option, ) -> Result { let data: &Self = self; diff --git a/crates/api/src/post/like.rs b/crates/api/src/post/like.rs index 2413a983c..5811107c2 100644 --- a/crates/api/src/post/like.rs +++ b/crates/api/src/post/like.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api/src/post/lock.rs b/crates/api/src/post/lock.rs index 426436400..5266d5441 100644 --- a/crates/api/src/post/lock.rs +++ b/crates/api/src/post/lock.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api/src/post/mark_read.rs b/crates/api/src/post/mark_read.rs index e53d7a78f..0e013a883 100644 --- a/crates/api/src/post/mark_read.rs +++ b/crates/api/src/post/mark_read.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 }) } } diff --git a/crates/api/src/post/save.rs b/crates/api/src/post/save.rs index f3ef6319c..3213d2be6 100644 --- a/crates/api/src/post/save.rs +++ b/crates/api/src/post/save.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &SavePost = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/post_report/create.rs b/crates/api/src/post_report/create.rs index 092f1cd8d..52bc3ce75 100644 --- a/crates/api/src/post_report/create.rs +++ b/crates/api/src/post_report/create.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 }) } } diff --git a/crates/api/src/post_report/list.rs b/crates/api/src/post_report/list.rs index f59270424..d8473f736 100644 --- a/crates/api/src/post_report/list.rs +++ b/crates/api/src/post_report/list.rs @@ -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, - _websocket_id: Option, ) -> Result { 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 }) } } diff --git a/crates/api/src/post_report/resolve.rs b/crates/api/src/post_report/resolve.rs index 80290b2a3..cc6d0510f 100644 --- a/crates/api/src/post_report/resolve.rs +++ b/crates/api/src/post_report/resolve.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 }) } } diff --git a/crates/api/src/private_message/mark_read.rs b/crates/api/src/private_message/mark_read.rs index bf373e99c..ca3431742 100644 --- a/crates/api/src/private_message/mark_read.rs +++ b/crates/api/src/private_message/mark_read.rs @@ -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, - websocket_id: Option, ) -> Result { 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, + }) } } diff --git a/crates/api/src/private_message_report/create.rs b/crates/api/src/private_message_report/create.rs index a9ca0291d..2a2feef34 100644 --- a/crates/api/src/private_message_report/create.rs +++ b/crates/api/src/private_message_report/create.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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, + }) } } diff --git a/crates/api/src/private_message_report/list.rs b/crates/api/src/private_message_report/list.rs index 69b3dbf94..62c07325c 100644 --- a/crates/api/src/private_message_report/list.rs +++ b/crates/api/src/private_message_report/list.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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) + }) } } diff --git a/crates/api/src/private_message_report/resolve.rs b/crates/api/src/private_message_report/resolve.rs index 09e3b251a..e4fcfc856 100644 --- a/crates/api/src/private_message_report/resolve.rs +++ b/crates/api/src/private_message_report/resolve.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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) + }) } } diff --git a/crates/api/src/site/federated_instances.rs b/crates/api/src/site/federated_instances.rs index 107fece44..0d2b83bc0 100644 --- a/crates/api/src/site/federated_instances.rs +++ b/crates/api/src/site/federated_instances.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let site_view = SiteView::read_local(context.pool()).await?; let federated_instances = build_federated_instances(&site_view.local_site, context.pool()).await?; diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index a7c0941d1..d7c0cf3aa 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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, diff --git a/crates/api/src/site/mod_log.rs b/crates/api/src/site/mod_log.rs index dcb5f5edf..2ca725150 100644 --- a/crates/api/src/site/mod_log.rs +++ b/crates/api/src/site/mod_log.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &GetModlog = self; let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; diff --git a/crates/api/src/site/purge/comment.rs b/crates/api/src/site/purge/comment.rs index f4ba45097..c8abf57d9 100644 --- a/crates/api/src/site/purge/comment.rs +++ b/crates/api/src/site/purge/comment.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &Self = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/site/purge/community.rs b/crates/api/src/site/purge/community.rs index 5bdf62e75..111c437ec 100644 --- a/crates/api/src/site/purge/community.rs +++ b/crates/api/src/site/purge/community.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &Self = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/site/purge/person.rs b/crates/api/src/site/purge/person.rs index 896dc783c..5273110ed 100644 --- a/crates/api/src/site/purge/person.rs +++ b/crates/api/src/site/purge/person.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &Self = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/site/purge/post.rs b/crates/api/src/site/purge/post.rs index c04fc5601..01d0332eb 100644 --- a/crates/api/src/site/purge/post.rs +++ b/crates/api/src/site/purge/post.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &Self = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/site/registration_applications/approve.rs b/crates/api/src/site/registration_applications/approve.rs index edba7f2b8..b7f672e61 100644 --- a/crates/api/src/site/registration_applications/approve.rs +++ b/crates/api/src/site/registration_applications/approve.rs @@ -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, - _websocket_id: Option, - ) -> Result { + async fn perform(&self, context: &Data) -> Result { let data = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api/src/site/registration_applications/list.rs b/crates/api/src/site/registration_applications/list.rs index b5a366e16..6a3599577 100644 --- a/crates/api/src/site/registration_applications/list.rs +++ b/crates/api/src/site/registration_applications/list.rs @@ -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, - _websocket_id: Option, - ) -> Result { + async fn perform(&self, context: &Data) -> Result { 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) + }) } } diff --git a/crates/api/src/site/registration_applications/unread_count.rs b/crates/api/src/site/registration_applications/unread_count.rs index 72490e480..aed07c708 100644 --- a/crates/api/src/site/registration_applications/unread_count.rs +++ b/crates/api/src/site/registration_applications/unread_count.rs @@ -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, - _websocket_id: Option, - ) -> Result { + async fn perform(&self, context: &Data) -> Result { 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 index 0552c1906..000000000 --- a/crates/api/src/websocket.rs +++ /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, - websocket_id: Option, - ) -> Result { - 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, - websocket_id: Option, - ) -> Result { - 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, - websocket_id: Option, - ) -> Result { - 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, - websocket_id: Option, - ) -> Result { - 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 }) - } -} diff --git a/crates/api_common/Cargo.toml b/crates/api_common/Cargo.toml index e10af5a0d..5b5ee9ab2 100644 --- a/crates/api_common/Cargo.toml +++ b/crates/api_common/Cargo.toml @@ -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 index 000000000..374a74d91 --- /dev/null +++ b/crates/api_common/src/build_response.rs @@ -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, + comment_id: CommentId, + local_user_view: Option, + form_id: Option, + recipient_ids: Vec, +) -> Result { + 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, + local_user_view: LocalUserView, + community_id: CommunityId, +) -> Result { + 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, + community_id: CommunityId, + person_id: PersonId, + post_id: PostId, +) -> Result { + 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, + comment: &Comment, + person: &Person, + post: &Post, + do_send_email: bool, + context: &LemmyContext, +) -> Result, 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::>() + { + 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) +} diff --git a/crates/api_common/src/community.rs b/crates/api_common/src/community.rs index becf29ab4..cb92d4c2e 100644 --- a/crates/api_common/src/community.rs +++ b/crates/api_common/src/community.rs @@ -32,7 +32,6 @@ pub struct GetCommunityResponse { pub community_view: CommunityView, pub site: Option, pub moderators: Vec, - pub online: usize, pub discussion_languages: Vec, } diff --git a/crates/api_common/src/context.rs b/crates/api_common/src/context.rs index 1301bf36f..42fa74964 100644 --- a/crates/api_common/src/context.rs +++ b/crates/api_common/src/context.rs @@ -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, client: Arc, secret: Arc, rate_limit_cell: RateLimitCell, @@ -20,14 +17,12 @@ pub struct LemmyContext { impl LemmyContext { pub fn create( pool: DbPool, - chat_server: Addr, 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 { - &self.chat_server - } pub fn client(&self) -> &ClientWithMiddleware { &self.client } diff --git a/crates/api_common/src/lib.rs b/crates/api_common/src/lib.rs index 3c9d71216..224e114a5 100644 --- a/crates/api_common/src/lib.rs +++ b/crates/api_common/src/lib.rs @@ -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; diff --git a/crates/api_common/src/post.rs b/crates/api_common/src/post.rs index f421bf047..962c4bb92 100644 --- a/crates/api_common/src/post.rs +++ b/crates/api_common/src/post.rs @@ -60,7 +60,6 @@ pub struct GetPostResponse { pub moderators: Vec, /// A list of cross-posts, or other times / communities this link has been posted to. pub cross_posts: Vec, - pub online: usize, } #[skip_serializing_none] diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 2ba6611c9..4d488ec1b 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -294,7 +294,6 @@ pub struct SiteResponse { pub struct GetSiteResponse { pub site_view: SiteView, pub admins: Vec, - pub online: usize, pub version: String, pub my_user: Option, pub all_languages: Vec, diff --git a/crates/api_common/src/websocket/chat_server.rs b/crates/api_common/src/websocket/chat_server.rs deleted file mode 100644 index fa06987c5..000000000 --- a/crates/api_common/src/websocket/chat_server.rs +++ /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, - - /// A map from post_id to set of connectionIDs - pub post_rooms: HashMap>, - - /// A map from community to set of connectionIDs - pub community_rooms: HashMap>, - - pub mod_rooms: HashMap>, - - /// 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>, - - pub(super) rng: StdRng, - - /// A list of the current captchas - pub(super) captchas: Vec, -} - -/// `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, - message: &str, - exclude_connection: Option, - ) { - 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; -} diff --git a/crates/api_common/src/websocket/handlers/captcha.rs b/crates/api_common/src/websocket/handlers/captcha.rs deleted file mode 100644 index e3ff60932..000000000 --- a/crates/api_common/src/websocket/handlers/captcha.rs +++ /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 for ChatServer { - type Result = (); - - fn handle(&mut self, msg: AddCaptcha, _: &mut Context) -> 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 for ChatServer { - type Result = bool; - - fn handle(&mut self, msg: CheckCaptcha, _: &mut Context) -> 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 index f3e7e3b63..000000000 --- a/crates/api_common/src/websocket/handlers/connect.rs +++ /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, -} - -/// Handler for Connect message. -/// -/// Register new session and assign unique id to this session -impl Handler for ChatServer { - type Result = ConnectionId; - - fn handle(&mut self, msg: Connect, _: &mut Context) -> Self::Result { - // register session with random id - let id = self.rng.gen::(); - 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 for ChatServer { - type Result = (); - - fn handle(&mut self, msg: Disconnect, _: &mut Context) -> 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 index 10235e3fe..000000000 --- a/crates/api_common/src/websocket/handlers/join_rooms.rs +++ /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 for ChatServer { - type Result = (); - - fn handle(&mut self, msg: JoinPostRoom, _: &mut Context) -> 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 for ChatServer { - type Result = (); - - fn handle(&mut self, msg: JoinCommunityRoom, _: &mut Context) -> 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 for ChatServer { - type Result = (); - - fn handle(&mut self, msg: JoinModRoom, _: &mut Context) -> 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 for ChatServer { - type Result = (); - - fn handle(&mut self, msg: JoinUserRoom, _: &mut Context) -> 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 index 3b49302aa..000000000 --- a/crates/api_common/src/websocket/handlers/messages.rs +++ /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, -} - -impl Handler for ChatServer { - type Result = (); - - fn handle(&mut self, msg: SendPostRoomMessage, _: &mut Context) -> 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, -} - -impl Handler for ChatServer { - type Result = (); - - fn handle(&mut self, msg: SendCommunityRoomMessage, _: &mut Context) -> 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, -} - -impl Handler for ChatServer { - type Result = (); - - fn handle(&mut self, msg: SendModRoomMessage, _: &mut Context) -> 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, -} - -impl Handler for ChatServer { - type Result = (); - - fn handle(&mut self, msg: SendUserRoomMessage, _: &mut Context) -> 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, -} - -impl Handler for ChatServer { - type Result = (); - - fn handle(&mut self, msg: SendAllMessage, _: &mut Context) -> Self::Result { - let connections: HashSet = 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>, -// exclude_connection: Option, -//) -> 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 index d989a44e4..000000000 --- a/crates/api_common/src/websocket/handlers/mod.rs +++ /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, - // 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 index 2833b68f0..000000000 --- a/crates/api_common/src/websocket/handlers/online_users.rs +++ /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 for ChatServer { - type Result = usize; - - fn handle(&mut self, _msg: GetUsersOnline, _: &mut Context) -> 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 for ChatServer { - type Result = usize; - - fn handle(&mut self, msg: GetPostUsersOnline, _: &mut Context) -> 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 for ChatServer { - type Result = usize; - - fn handle(&mut self, msg: GetCommunityUsersOnline, _: &mut Context) -> 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 index 2f13d8b8c..000000000 --- a/crates/api_common/src/websocket/mod.rs +++ /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, -} - -#[derive(Serialize)] -struct WebsocketResponse { - op: String, - data: T, -} - -pub fn serialize_websocket_message( - op: &OP, - data: &Response, -) -> Result -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 index e983b85c5..000000000 --- a/crates/api_common/src/websocket/send.rs +++ /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( - &self, - op: &OP, - post_id: PostId, - websocket_id: Option, - person_id: Option, - ) -> Result - 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( - &self, - op: &OP, - comment_id: CommentId, - ) -> Result - 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( - &self, - op: &OP, - comment_id: CommentId, - websocket_id: Option, - form_id: Option, - person_id: Option, - recipient_ids: Vec, - ) -> Result - 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( - &self, - op: &OP, - community_id: CommunityId, - websocket_id: Option, - person_id: Option, - ) -> Result - 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( - &self, - op: &OP, - private_message_id: PrivateMessageId, - websocket_id: Option, - ) -> Result - 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, - comment: &Comment, - person: &Person, - post: &Post, - do_send_email: bool, - ) -> Result, 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::>() - { - 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( - &self, - op: &OP, - data: Data, - websocket_id: Option, - ) -> 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( - &self, - op: &OP, - data: Data, - community_id: CommunityId, - websocket_id: Option, - ) -> 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 index dbe510738..000000000 --- a/crates/api_common/src/websocket/structs.rs +++ /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, -} - -#[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, -} diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index 8909444d2..500187947 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/comment/delete.rs b/crates/api_crud/src/comment/delete.rs index cde4ab629..864daded8 100644 --- a/crates/api_crud/src/comment/delete.rs +++ b/crates/api_crud/src/comment/delete.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 recipient_ids = send_local_notifs( + vec![], + &updated_comment, + &local_user_view.person, + &post, + false, + context, + ) + .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?; - - Ok(res) + build_comment_response( + context, + updated_comment.id, + Some(local_user_view), + None, + recipient_ids, + ) + .await } } diff --git a/crates/api_crud/src/comment/read.rs b/crates/api_crud/src/comment/read.rs index bd37eb77c..2ae719738 100644 --- a/crates/api_crud/src/comment/read.rs +++ b/crates/api_crud/src/comment/read.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/comment/remove.rs b/crates/api_crud/src/comment/remove.rs index b8834df8d..6e4e55281 100644 --- a/crates/api_crud/src/comment/remove.rs +++ b/crates/api_crud/src/comment/remove.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 recipient_ids = send_local_notifs( + vec![], + &updated_comment, + &local_user_view.person.clone(), + &post, + false, + context, + ) + .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?; - - Ok(res) + build_comment_response( + context, + updated_comment.id, + Some(local_user_view), + None, + recipient_ids, + ) + .await } } diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index e74d5c4ed..86bdb52e2 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/community/create.rs b/crates/api_crud/src/community/create.rs index fbc557b72..850e9f2f5 100644 --- a/crates/api_crud/src/community/create.rs +++ b/crates/api_crud/src/community/create.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/community/delete.rs b/crates/api_crud/src/community/delete.rs index 9909f5cdd..019e9f1da 100644 --- a/crates/api_crud/src/community/delete.rs +++ b/crates/api_crud/src/community/delete.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/community/list.rs b/crates/api_crud/src/community/list.rs index e620e1606..a58737d99 100644 --- a/crates/api_crud/src/community/list.rs +++ b/crates/api_crud/src/community/list.rs @@ -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, - _websocket_id: Option, ) -> Result { let data: &ListCommunities = self; let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; diff --git a/crates/api_crud/src/community/remove.rs b/crates/api_crud/src/community/remove.rs index 9a905b874..52a503c45 100644 --- a/crates/api_crud/src/community/remove.rs +++ b/crates/api_crud/src/community/remove.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/community/update.rs b/crates/api_crud/src/community/update.rs index 9d56ce8a1..7494cd342 100644 --- a/crates/api_crud/src/community/update.rs +++ b/crates/api_crud/src/community/update.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/custom_emoji/create.rs b/crates/api_crud/src/custom_emoji/create.rs index 333379451..5aaf56125 100644 --- a/crates/api_crud/src/custom_emoji/create.rs +++ b/crates/api_crud/src/custom_emoji/create.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(self, context))] + async fn perform(&self, context: &Data) -> Result { let data: &CreateCustomEmoji = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api_crud/src/custom_emoji/delete.rs b/crates/api_crud/src/custom_emoji/delete.rs index dcca88392..45dc6eaee 100644 --- a/crates/api_crud/src/custom_emoji/delete.rs +++ b/crates/api_crud/src/custom_emoji/delete.rs @@ -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, - _websocket_id: Option, ) -> Result { let data: &DeleteCustomEmoji = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api_crud/src/custom_emoji/update.rs b/crates/api_crud/src/custom_emoji/update.rs index 67a2bed9f..f56763e9d 100644 --- a/crates/api_crud/src/custom_emoji/update.rs +++ b/crates/api_crud/src/custom_emoji/update.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(self, context))] + async fn perform(&self, context: &Data) -> Result { let data: &EditCustomEmoji = self; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; diff --git a/crates/api_crud/src/lib.rs b/crates/api_crud/src/lib.rs index 70d5d44d4..a10309fc9 100644 --- a/crates/api_crud/src/lib.rs +++ b/crates/api_crud/src/lib.rs @@ -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, - websocket_id: Option, - ) -> Result; + async fn perform(&self, context: &Data) -> Result; } diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index e0c1a5d13..cd2cf1c3d 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/post/delete.rs b/crates/api_crud/src/post/delete.rs index 82efeaa17..6e6a4c076 100644 --- a/crates/api_crud/src/post/delete.rs +++ b/crates/api_crud/src/post/delete.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/post/read.rs b/crates/api_crud/src/post/read.rs index cda2f65b6..85106afe4 100644 --- a/crates/api_crud/src/post/read.rs +++ b/crates/api_crud/src/post/read.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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, }) } diff --git a/crates/api_crud/src/post/remove.rs b/crates/api_crud/src/post/remove.rs index 9081d911e..7f379169e 100644 --- a/crates/api_crud/src/post/remove.rs +++ b/crates/api_crud/src/post/remove.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index 2bd101c09..af2c63c50 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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 } } diff --git a/crates/api_crud/src/private_message/create.rs b/crates/api_crud/src/private_message/create.rs index 6fd369008..3b3dd70c1 100644 --- a/crates/api_crud/src/private_message/create.rs +++ b/crates/api_crud/src/private_message/create.rs @@ -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, - websocket_id: Option, ) -> Result { 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, + }) } } diff --git a/crates/api_crud/src/private_message/delete.rs b/crates/api_crud/src/private_message/delete.rs index f494edffa..b8e3c3b11 100644 --- a/crates/api_crud/src/private_message/delete.rs +++ b/crates/api_crud/src/private_message/delete.rs @@ -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, - websocket_id: Option, ) -> Result { 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, + }) } } diff --git a/crates/api_crud/src/private_message/read.rs b/crates/api_crud/src/private_message/read.rs index da2bc690b..679cd09f7 100644 --- a/crates/api_crud/src/private_message/read.rs +++ b/crates/api_crud/src/private_message/read.rs @@ -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, - _websocket_id: Option, ) -> Result { let data: &GetPrivateMessages = self; let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?; diff --git a/crates/api_crud/src/private_message/update.rs b/crates/api_crud/src/private_message/update.rs index a485a5093..cc3c377b8 100644 --- a/crates/api_crud/src/private_message/update.rs +++ b/crates/api_crud/src/private_message/update.rs @@ -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, - websocket_id: Option, ) -> Result { 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, + }) } } diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index 05b41e35a..c16f3bc56 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &CreateSite = self; let local_site = LocalSite::read(context.pool()).await?; diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index 1e40cabdd..f6c663ac0 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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, diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 31c4e4838..b1b298167 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -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, - websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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) } } diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index 8ae6de390..c88833930 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(self, context))] + async fn perform(&self, context: &Data) -> Result { 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)?; diff --git a/crates/api_crud/src/user/delete.rs b/crates/api_crud/src/user/delete.rs index 731f90721..7ce0312cf 100644 --- a/crates/api_crud/src/user/delete.rs +++ b/crates/api_crud/src/user/delete.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(self, context))] + async fn perform(&self, context: &Data) -> Result { let data = self; let local_user_view = local_user_view_from_jwt(data.auth.as_ref(), context).await?; diff --git a/crates/apub/Cargo.toml b/crates/apub/Cargo.toml index 4a5c8fc8f..65aeb0b2f 100644 --- a/crates/apub/Cargo.toml +++ b/crates/apub/Cargo.toml @@ -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 } diff --git a/crates/apub/assets/friendica/activities/create_page_1.json b/crates/apub/assets/friendica/activities/create_page_1.json index a0ca46830..72e466478 100644 --- a/crates/apub/assets/friendica/activities/create_page_1.json +++ b/crates/apub/assets/friendica/activities/create_page_1.json @@ -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": "

Test post to community

@lemmy_community

", "contentMap": { - "de": "!testcom 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.
ISS astronauts perform final spacewalk of Expedition 66" - }, - "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&d=mm&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": "

Test post to community

@lemmy_community

" }, "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": [] + } + } } } diff --git a/crates/apub/assets/mastodon/objects/person.json b/crates/apub/assets/mastodon/objects/person.json index e50e6b8a8..afcde4ebf 100644 --- a/crates/apub/assets/mastodon/objects/person.json +++ b/crates/apub/assets/mastodon/objects/person.json @@ -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", @@ -48,46 +51,42 @@ "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": "

#Lemmy Maintainer

", - "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" } } diff --git a/crates/apub/src/activities/community/report.rs b/crates/apub/src/activities/community/report.rs index aaa1e5108..750672edb 100644 --- a/crates/apub/src/activities/community/report.rs +++ b/crates/apub/src/activities/community/report.rs @@ -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(()) diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index 5cf1881a3..f8bbfa6ce 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -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(()) } } diff --git a/crates/apub/src/activities/create_or_update/comment.rs b/crates/apub/src/activities/create_or_update/comment.rs index d07a8e663..814ec0f87 100644 --- a/crates/apub/src/activities/create_or_update/comment.rs +++ b/crates/apub/src/activities/create_or_update/comment.rs @@ -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(¬if_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(()) } } diff --git a/crates/apub/src/activities/create_or_update/mod.rs b/crates/apub/src/activities/create_or_update/mod.rs index 9e4fa51b2..c69e00e91 100644 --- a/crates/apub/src/activities/create_or_update/mod.rs +++ b/crates/apub/src/activities/create_or_update/mod.rs @@ -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, - comment: &Comment, - do_send_email: bool, - context: &Data, -) -> Result, 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 -} diff --git a/crates/apub/src/activities/create_or_update/post.rs b/crates/apub/src/activities/create_or_update/post.rs index 771e3c3c4..b545f5239 100644 --- a/crates/apub/src/activities/create_or_update/post.rs +++ b/crates/apub/src/activities/create_or_update/post.rs @@ -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(¬if_type, post.id, None, None) - .await?; Ok(()) } } diff --git a/crates/apub/src/activities/create_or_update/private_message.rs b/crates/apub/src/activities/create_or_update/private_message.rs index 85051344f..691eff300 100644 --- a/crates/apub/src/activities/create_or_update/private_message.rs +++ b/crates/apub/src/activities/create_or_update/private_message.rs @@ -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) -> 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(¬if_type, private_message.id, None) - .await?; - + ApubPrivateMessage::from_json(self.object, context).await?; Ok(()) } } diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 1bb3b6c41..dfa709c36 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -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, context: &Data, ) -> 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!(), } diff --git a/crates/apub/src/activities/deletion/mod.rs b/crates/apub/src/activities/deletion/mod.rs index ea6f4a67d..3bde90f93 100644 --- a/crates/apub/src/activities/deletion/mod.rs +++ b/crates/apub/src/activities/deletion/mod.rs @@ -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(()) diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index 13a32cabc..00768580d 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -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, ) -> 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!(), } diff --git a/crates/apub/src/activities/following/accept.rs b/crates/apub/src/activities/following/accept.rs index 34dc976de..7b9ab6802 100644 --- a/crates/apub/src/activities/following/accept.rs +++ b/crates/apub/src/activities/following/accept.rs @@ -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(()) } } diff --git a/crates/apub/src/activities/unfederated.rs b/crates/apub/src/activities/unfederated.rs index 0a7981a47..4b9e6b5a9 100644 --- a/crates/apub/src/activities/unfederated.rs +++ b/crates/apub/src/activities/unfederated.rs @@ -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; } diff --git a/crates/apub/src/activities/voting/mod.rs b/crates/apub/src/activities/voting/mod.rs index 60015b137..8bae05577 100644 --- a/crates/apub/src/activities/voting/mod.rs +++ b/crates/apub/src/activities/voting/mod.rs @@ -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(()) } diff --git a/crates/apub/src/api/list_comments.rs b/crates/apub/src/api/list_comments.rs index f697a7358..b3a1b7cf2 100644 --- a/crates/apub/src/api/list_comments.rs +++ b/crates/apub/src/api/list_comments.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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?; diff --git a/crates/apub/src/api/list_posts.rs b/crates/apub/src/api/list_posts.rs index 58c31b2e6..99c790c73 100644 --- a/crates/apub/src/api/list_posts.rs +++ b/crates/apub/src/api/list_posts.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { 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?; diff --git a/crates/apub/src/api/mod.rs b/crates/apub/src/api/mod.rs index 9099dbd09..d95c9b51b 100644 --- a/crates/apub/src/api/mod.rs +++ b/crates/apub/src/api/mod.rs @@ -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, - websocket_id: Option, - ) -> Result; + async fn perform(&self, context: &Data) -> Result; } /// Returns default listing type, depending if the query is for frontpage or community. diff --git a/crates/apub/src/api/read_community.rs b/crates/apub/src/api/read_community.rs index 53469cf84..a19758990 100644 --- a/crates/apub/src/api/read_community.rs +++ b/crates/apub/src/api/read_community.rs @@ -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, - _websocket_id: Option, ) -> Result { 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, }; diff --git a/crates/apub/src/api/read_person.rs b/crates/apub/src/api/read_person.rs index 9d453acee..1e4797fa4 100644 --- a/crates/apub/src/api/read_person.rs +++ b/crates/apub/src/api/read_person.rs @@ -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, - _websocket_id: Option, ) -> Result { let data: &GetPersonDetails = self; diff --git a/crates/apub/src/api/resolve_object.rs b/crates/apub/src/api/resolve_object.rs index 193494ddb..951cd4551 100644 --- a/crates/apub/src/api/resolve_object.rs +++ b/crates/apub/src/api/resolve_object.rs @@ -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, - _websocket_id: Option, ) -> Result { let local_user_view = local_user_view_from_jwt(&self.auth, context).await?; let local_site = LocalSite::read(context.pool()).await?; diff --git a/crates/apub/src/api/search.rs b/crates/apub/src/api/search.rs index 6cbd6b1e5..025d1408a 100644 --- a/crates/apub/src/api/search.rs +++ b/crates/apub/src/api/search.rs @@ -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, - _websocket_id: Option, - ) -> Result { + #[tracing::instrument(skip(context))] + async fn perform(&self, context: &Data) -> Result { let data: &Search = self; let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; diff --git a/crates/apub/src/objects/mod.rs b/crates/apub/src/objects/mod.rs index 1dbc7c63a..5d133e9b8 100644 --- a/crates/apub/src/objects/mod.rs +++ b/crates/apub/src/objects/mod.rs @@ -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) diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index 3259fd17d..faf08938b 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -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::)) .route("/ban_user", web::post().to(route_post::)) - .route("/mod", web::post().to(route_post::)) - .route("/join", web::post().to(route_post::)) - .route("/mod/join", web::post().to(route_post::)), + .route("/mod", web::post().to(route_post::)), ) .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::)) .route("/like", web::post().to(route_post::)) .route("/save", web::put().to(route_post::)) - .route("/join", web::post().to(route_post::)) .route("/report", web::post().to(route_post::)) .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::)), ) - .service( - // Handle captcha separately - web::resource("/user/get_captcha") - .wrap(rate_limit.post()) - .route(web::get().to(route_get::)), - ) // 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::), ) .route("/replies", web::get().to(route_get::)) - .route("/join", web::post().to(route_post::)) // Admin action. I don't like that it's in /user .route("/ban", web::post().to(route_post::)) .route("/banned", web::get().to(route_get::)) @@ -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)) } diff --git a/src/lib.rs b/src/lib.rs index 21a4c25b5..7cf3d8010 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(),