2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 comment::{CommentResponse, SaveComment},
5 utils::{blocking, get_local_user_view_from_jwt},
8 source::comment::{CommentSaved, CommentSavedForm},
11 use lemmy_db_views::structs::CommentView;
12 use lemmy_utils::{ConnectionId, LemmyError};
13 use lemmy_websocket::LemmyContext;
15 #[async_trait::async_trait(?Send)]
16 impl Perform for SaveComment {
17 type Response = CommentResponse;
19 #[tracing::instrument(skip(context, _websocket_id))]
22 context: &Data<LemmyContext>,
23 _websocket_id: Option<ConnectionId>,
24 ) -> Result<CommentResponse, LemmyError> {
25 let data: &SaveComment = self;
27 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
29 let comment_saved_form = CommentSavedForm {
30 comment_id: data.comment_id,
31 person_id: local_user_view.person.id,
35 let save_comment = move |conn: &'_ _| CommentSaved::save(conn, &comment_saved_form);
36 blocking(context.pool(), save_comment)
38 .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
40 let unsave_comment = move |conn: &'_ _| CommentSaved::unsave(conn, &comment_saved_form);
41 blocking(context.pool(), unsave_comment)
43 .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
46 let comment_id = data.comment_id;
47 let person_id = local_user_view.person.id;
48 let comment_view = blocking(context.pool(), move |conn| {
49 CommentView::read(conn, comment_id, Some(person_id))
55 recipient_ids: Vec::new(),