diff --git a/crates/api/src/private_message/mark_read.rs b/crates/api/src/private_message/mark_read.rs index 7c213464b..352963449 100644 --- a/crates/api/src/private_message/mark_read.rs +++ b/crates/api/src/private_message/mark_read.rs @@ -1,9 +1,10 @@ -use actix_web::web::{Data, Json}; +use actix_web::web::{Data, Json, Path}; use lemmy_api_common::{ context::LemmyContext, private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse}, }; use lemmy_db_schema::{ + newtypes::PrivateMessageId, source::private_message::{PrivateMessage, PrivateMessageUpdateForm}, traits::Crud, }; @@ -15,16 +16,16 @@ pub async fn mark_pm_as_read( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { // Checking permissions - let private_message_id = data.private_message_id; + let private_message_id = path.into_inner(); let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?; if local_user_view.person.id != orig_private_message.recipient_id { Err(LemmyErrorType::CouldntUpdatePrivateMessage)? } // Doing the update - let private_message_id = data.private_message_id; let read = data.read; PrivateMessage::update( &mut context.pool(), diff --git a/crates/api_crud/src/private_message/delete.rs b/crates/api_crud/src/private_message/delete.rs index 30efc020c..71b8b90f0 100644 --- a/crates/api_crud/src/private_message/delete.rs +++ b/crates/api_crud/src/private_message/delete.rs @@ -1,11 +1,12 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use lemmy_api_common::{ context::LemmyContext, private_message::{DeletePrivateMessage, PrivateMessageResponse}, send_activity::{ActivityChannel, SendActivityData}, }; use lemmy_db_schema::{ + newtypes::PrivateMessageId, source::private_message::{PrivateMessage, PrivateMessageUpdateForm}, traits::Crud, }; @@ -17,16 +18,16 @@ pub async fn delete_private_message( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { // Checking permissions - let private_message_id = data.private_message_id; + let private_message_id = path.into_inner(); let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?; if local_user_view.person.id != orig_private_message.creator_id { Err(LemmyErrorType::EditPrivateMessageNotAllowed)? } // Doing the update - let private_message_id = data.private_message_id; let deleted = data.deleted; let private_message = PrivateMessage::update( &mut context.pool(), diff --git a/crates/api_crud/src/private_message/update.rs b/crates/api_crud/src/private_message/update.rs index b9e4785ef..1d09f8de7 100644 --- a/crates/api_crud/src/private_message/update.rs +++ b/crates/api_crud/src/private_message/update.rs @@ -1,5 +1,5 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use chrono::Utc; use lemmy_api_common::{ context::LemmyContext, @@ -8,6 +8,7 @@ use lemmy_api_common::{ utils::{get_url_blocklist, local_site_to_slur_regex, process_markdown}, }; use lemmy_db_schema::{ + newtypes::PrivateMessageId, source::{ local_site::LocalSite, private_message::{PrivateMessage, PrivateMessageUpdateForm}, @@ -25,11 +26,12 @@ pub async fn update_private_message( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { + let private_message_id = path.into_inner(); let local_site = LocalSite::read(&mut context.pool()).await?; // Checking permissions - let private_message_id = data.private_message_id; let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?; if local_user_view.person.id != orig_private_message.creator_id { Err(LemmyErrorType::EditPrivateMessageNotAllowed)? @@ -41,7 +43,6 @@ pub async fn update_private_message( let content = process_markdown(&data.content, &slur_regex, &url_blocklist, &context).await?; is_valid_body_field(&content, false)?; - let private_message_id = data.private_message_id; PrivateMessage::update( &mut context.pool(), private_message_id, diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index acf00097a..ee9331d50 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -258,15 +258,21 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { ) // Private Message .service( - scope("/private_message") - .route("/list", get().to(get_private_message)) + scope("/direct-messages") + .route("", get().to(get_private_message)) .route("", post().to(create_private_message)) - .route("", put().to(update_private_message)) - .route("/delete", post().to(delete_private_message)) - .route("/mark_as_read", post().to(mark_pm_as_read)) - .route("/report", post().to(create_pm_report)) - .route("/report/resolve", put().to(resolve_pm_report)) - .route("/report/list", get().to(list_pm_reports)), + .service( + scope("/{message_id}") + .route("", put().to(update_private_message)) + .route("", delete().to(delete_private_message)) + .route("/mark-as-read", post().to(mark_pm_as_read)) + .service( + scope("/reports") + .route("", get().to(list_pm_reports)) + .route("", post().to(create_pm_report)) + .service(scope("/{report_id}").route("", delete().to(resolve_pm_report))), + ), + ), ) // User .service(