2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 comment::{CommentResponse, SaveComment},
6 utils::local_user_view_from_jwt,
9 source::comment::{CommentSaved, CommentSavedForm},
12 use lemmy_db_views::structs::CommentView;
13 use lemmy_utils::{error::LemmyError, ConnectionId};
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;
26 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
28 let comment_saved_form = CommentSavedForm {
29 comment_id: data.comment_id,
30 person_id: local_user_view.person.id,
34 CommentSaved::save(context.pool(), &comment_saved_form)
36 .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
38 CommentSaved::unsave(context.pool(), &comment_saved_form)
40 .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
43 let comment_id = data.comment_id;
44 let person_id = local_user_view.person.id;
45 let comment_view = CommentView::read(context.pool(), comment_id, Some(person_id)).await?;
49 recipient_ids: Vec::new(),