]> Untitled Git - lemmy.git/blobdiff - crates/api/src/comment.rs
Rewrite fetcher (#1792)
[lemmy.git] / crates / api / src / comment.rs
index f92e679f7afe4b455a239f42d8234d8d353f7625..0af3324fae0b082159496a614a384ff858081944 100644 (file)
@@ -4,6 +4,7 @@ use lemmy_api_common::{
   blocking,
   check_community_ban,
   check_downvotes_enabled,
+  check_person_block,
   comment::*,
   get_local_user_view_from_jwt,
 };
@@ -12,13 +13,13 @@ use lemmy_apub::{
     undo_vote::UndoVote,
     vote::{Vote, VoteType},
   },
-  PostOrComment,
+  fetcher::post_or_comment::PostOrComment,
 };
 use lemmy_db_queries::{source::comment::Comment_, Likeable, Saveable};
 use lemmy_db_schema::{source::comment::*, LocalUserId};
 use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView};
 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
-use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
+use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation};
 use std::convert::TryInto;
 
 #[async_trait::async_trait(?Send)]
@@ -151,6 +152,13 @@ impl Perform for CreateCommentLike {
     )
     .await?;
 
+    check_person_block(
+      local_user_view.person.id,
+      orig_comment.get_recipient_id(),
+      context.pool(),
+    )
+    .await?;
+
     // Add parent user to recipients
     let recipient_id = orig_comment.get_recipient_id();
     if let Ok(local_recipient) = blocking(context.pool(), move |conn| {
@@ -206,26 +214,15 @@ impl Perform for CreateCommentLike {
       .await?;
     }
 
-    // Have to refetch the comment to get the current state
-    let comment_id = data.comment_id;
-    let person_id = local_user_view.person.id;
-    let liked_comment = blocking(context.pool(), move |conn| {
-      CommentView::read(conn, comment_id, Some(person_id))
-    })
-    .await??;
-
-    let res = CommentResponse {
-      comment_view: liked_comment,
-      recipient_ids,
-      form_id: None,
-    };
-
-    context.chat_server().do_send(SendComment {
-      op: UserOperation::CreateCommentLike,
-      comment: res.clone(),
+    send_comment_ws_message(
+      data.comment_id,
+      UserOperation::CreateCommentLike,
       websocket_id,
-    });
-
-    Ok(res)
+      None,
+      Some(local_user_view.person.id),
+      recipient_ids,
+      context,
+    )
+    .await
   }
 }