2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 comment::{CommentResponse, SaveComment},
6 get_local_user_view_from_jwt,
9 source::comment::{CommentSaved, CommentSavedForm},
12 use lemmy_db_views::comment_view::CommentView;
13 use lemmy_utils::{ConnectionId, LemmyError};
14 use lemmy_websocket::LemmyContext;
16 #[async_trait::async_trait(?Send)]
17 impl Perform for SaveComment {
18 type Response = CommentResponse;
20 #[tracing::instrument(skip(context, _websocket_id))]
23 context: &Data<LemmyContext>,
24 _websocket_id: Option<ConnectionId>,
25 ) -> Result<CommentResponse, LemmyError> {
26 let data: &SaveComment = self;
28 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
30 let comment_saved_form = CommentSavedForm {
31 comment_id: data.comment_id,
32 person_id: local_user_view.person.id,
36 let save_comment = move |conn: &'_ _| CommentSaved::save(conn, &comment_saved_form);
37 blocking(context.pool(), save_comment)
39 .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
41 let unsave_comment = move |conn: &'_ _| CommentSaved::unsave(conn, &comment_saved_form);
42 blocking(context.pool(), unsave_comment)
44 .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
47 let comment_id = data.comment_id;
48 let person_id = local_user_view.person.id;
49 let comment_view = blocking(context.pool(), move |conn| {
50 CommentView::read(conn, comment_id, Some(person_id))
56 recipient_ids: Vec::new(),