Rearrange comments somewhat

This commit is contained in:
SleeplessOne1917 2024-12-17 20:07:08 -05:00
parent d9905824eb
commit a5ac8eca3d
4 changed files with 46 additions and 45 deletions

View file

@ -1,5 +1,5 @@
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::{Json, Path};
use lemmy_api_common::{ use lemmy_api_common::{
build_response::{build_comment_response, send_local_notifs}, build_response::{build_comment_response, send_local_notifs},
comment::{CommentResponse, DeleteComment}, comment::{CommentResponse, DeleteComment},
@ -8,6 +8,7 @@ use lemmy_api_common::{
utils::check_community_user_action, utils::check_community_user_action,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::CommentId,
source::comment::{Comment, CommentUpdateForm}, source::comment::{Comment, CommentUpdateForm},
traits::Crud, traits::Crud,
}; };
@ -19,8 +20,9 @@ pub async fn delete_comment(
data: Json<DeleteComment>, data: Json<DeleteComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
path: Path<CommentId>,
) -> LemmyResult<Json<CommentResponse>> { ) -> LemmyResult<Json<CommentResponse>> {
let comment_id = data.comment_id; let comment_id = path.into_inner();
let orig_comment = CommentView::read( let orig_comment = CommentView::read(
&mut context.pool(), &mut context.pool(),
comment_id, comment_id,
@ -67,7 +69,6 @@ pub async fn delete_comment(
Some(&local_user_view), Some(&local_user_view),
) )
.await?; .await?;
let updated_comment_id = updated_comment.id;
ActivityChannel::submit_activity( ActivityChannel::submit_activity(
SendActivityData::DeleteComment( SendActivityData::DeleteComment(
@ -79,12 +80,6 @@ pub async fn delete_comment(
)?; )?;
Ok(Json( Ok(Json(
build_comment_response( build_comment_response(&context, comment_id, Some(local_user_view), recipient_ids).await?,
&context,
updated_comment_id,
Some(local_user_view),
recipient_ids,
)
.await?,
)) ))
} }

View file

@ -1,25 +1,24 @@
use actix_web::web::{Data, Json, Query}; use actix_web::web::{Data, Json, Path};
use lemmy_api_common::{ use lemmy_api_common::{
build_response::build_comment_response, build_response::build_comment_response, comment::CommentResponse, context::LemmyContext,
comment::{CommentResponse, GetComment},
context::LemmyContext,
utils::check_private_instance, utils::check_private_instance,
}; };
use lemmy_db_schema::source::local_site::LocalSite; use lemmy_db_schema::{newtypes::CommentId, source::local_site::LocalSite};
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
pub async fn get_comment( pub async fn get_comment(
data: Query<GetComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>, local_user_view: Option<LocalUserView>,
path: Path<CommentId>,
) -> LemmyResult<Json<CommentResponse>> { ) -> LemmyResult<Json<CommentResponse>> {
let id = path.into_inner();
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?; check_private_instance(&local_user_view, &local_site)?;
Ok(Json( Ok(Json(
build_comment_response(&context, data.id, local_user_view, vec![]).await?, build_comment_response(&context, id, local_user_view, vec![]).await?,
)) ))
} }

View file

@ -1,5 +1,5 @@
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::{Json, Path};
use chrono::Utc; use chrono::Utc;
use lemmy_api_common::{ use lemmy_api_common::{
build_response::{build_comment_response, send_local_notifs}, build_response::{build_comment_response, send_local_notifs},
@ -7,14 +7,12 @@ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
send_activity::{ActivityChannel, SendActivityData}, send_activity::{ActivityChannel, SendActivityData},
utils::{ utils::{
check_community_user_action, check_community_user_action, get_url_blocklist, local_site_to_slur_regex, process_markdown_opt,
get_url_blocklist,
local_site_to_slur_regex,
process_markdown_opt,
}, },
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
impls::actor_language::validate_post_language, impls::actor_language::validate_post_language,
newtypes::CommentId,
source::{ source::{
comment::{Comment, CommentUpdateForm}, comment::{Comment, CommentUpdateForm},
local_site::LocalSite, local_site::LocalSite,
@ -32,10 +30,11 @@ pub async fn update_comment(
data: Json<EditComment>, data: Json<EditComment>,
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
path: Path<CommentId>,
) -> LemmyResult<Json<CommentResponse>> { ) -> LemmyResult<Json<CommentResponse>> {
let comment_id = path.into_inner();
let local_site = LocalSite::read(&mut context.pool()).await?; let local_site = LocalSite::read(&mut context.pool()).await?;
let comment_id = data.comment_id;
let orig_comment = CommentView::read( let orig_comment = CommentView::read(
&mut context.pool(), &mut context.pool(),
comment_id, comment_id,
@ -70,7 +69,6 @@ pub async fn update_comment(
is_valid_body_field(content, false)?; is_valid_body_field(content, false)?;
} }
let comment_id = data.comment_id;
let form = CommentUpdateForm { let form = CommentUpdateForm {
content, content,
language_id: Some(language_id), language_id: Some(language_id),

View file

@ -224,28 +224,37 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) {
.route("/site_metadata", get().to(get_link_metadata)), .route("/site_metadata", get().to(get_link_metadata)),
) )
// Comment // Comment
.service(
scope("/comments")
.route("", get().to(list_comments))
.service( .service(
// Handle POST to /comment separately to add the comment() rate limitter // Handle POST to /comment separately to add the comment() rate limitter
resource("/comment") resource("")
.guard(guard::Post()) .guard(guard::Post())
.wrap(rate_limit.comment()) .wrap(rate_limit.comment())
.route(post().to(create_comment)), .route(post().to(create_comment)),
) )
.service( .service(
scope("/comment") scope("/{comment_id}")
.route("", get().to(get_comment)) .route("", get().to(get_comment))
.route("", put().to(update_comment)) .route("", put().to(update_comment))
.route("/delete", post().to(delete_comment)) .route("", delete().to(delete_comment))
.route("/remove", post().to(remove_comment)) .route("/remove", post().to(remove_comment))
.route("/mark_as_read", post().to(mark_reply_as_read)) .route("/mark-as-read", post().to(mark_reply_as_read))
.route("/distinguish", post().to(distinguish_comment)) .route("/distinguish", post().to(distinguish_comment))
.route("/like", post().to(like_comment))
.route("/like/list", get().to(list_comment_likes))
.route("/save", put().to(save_comment)) .route("/save", put().to(save_comment))
.route("/list", get().to(list_comments)) .service(
.route("/report", post().to(create_comment_report)) resource("/likes")
.route("/report/resolve", put().to(resolve_comment_report)) .route(get().to(list_comment_likes))
.route("/report/list", get().to(list_comment_reports)), .route(post().to(like_comment)),
)
.service(
scope("/reports")
.route("", get().to(list_comment_reports))
.route("", post().to(create_comment_report))
.service(scope("/{report_id}").route("", delete().to(resolve_comment_report))),
),
),
) )
// Private Message // Private Message
.service( .service(