1 use actix_web::web::{Data, Json};
2 use lemmy_api_common::{
3 comment::{CommentResponse, SaveComment},
5 utils::local_user_view_from_jwt,
8 source::comment::{CommentSaved, CommentSavedForm},
11 use lemmy_db_views::structs::CommentView;
12 use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
14 #[tracing::instrument(skip(context))]
15 pub async fn save_comment(
16 data: Json<SaveComment>,
17 context: Data<LemmyContext>,
18 ) -> Result<Json<CommentResponse>, LemmyError> {
19 let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
21 let comment_saved_form = CommentSavedForm {
22 comment_id: data.comment_id,
23 person_id: local_user_view.person.id,
27 CommentSaved::save(&mut context.pool(), &comment_saved_form)
29 .with_lemmy_type(LemmyErrorType::CouldntSaveComment)?;
31 CommentSaved::unsave(&mut context.pool(), &comment_saved_form)
33 .with_lemmy_type(LemmyErrorType::CouldntSaveComment)?;
36 let comment_id = data.comment_id;
37 let person_id = local_user_view.person.id;
38 let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
40 Ok(Json(CommentResponse {
42 recipient_ids: Vec::new(),