use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
- blocking,
- check_community_ban,
- check_downvotes_enabled,
comment::{CommentResponse, CreateCommentLike},
- get_local_user_view_from_jwt,
+ utils::{blocking, check_community_ban, check_downvotes_enabled, get_local_user_view_from_jwt},
};
use lemmy_apub::{
fetcher::post_or_comment::PostOrComment,
};
use lemmy_db_schema::{
newtypes::LocalUserId,
- source::comment::{CommentLike, CommentLikeForm},
+ source::{
+ comment::{CommentLike, CommentLikeForm},
+ comment_reply::CommentReply,
+ local_site::LocalSite,
+ },
traits::Likeable,
};
-use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView};
-use lemmy_utils::{ConnectionId, LemmyError};
+use lemmy_db_views::structs::{CommentView, LocalUserView};
+use lemmy_utils::{error::LemmyError, ConnectionId};
use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation};
use std::convert::TryInto;
websocket_id: Option<ConnectionId>,
) -> Result<CommentResponse, LemmyError> {
let data: &CreateCommentLike = self;
+ let local_site = blocking(context.pool(), LocalSite::read).await??;
let local_user_view =
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
let mut recipient_ids = Vec::<LocalUserId>::new();
// Don't do a downvote if site has downvotes disabled
- check_downvotes_enabled(data.score, context.pool()).await?;
+ check_downvotes_enabled(data.score, &local_site)?;
let comment_id = data.comment_id;
let orig_comment = blocking(context.pool(), move |conn| {
)
.await?;
- // Add parent user to recipients
- let recipient_id = orig_comment.get_recipient_id();
- if let Ok(local_recipient) = blocking(context.pool(), move |conn| {
- LocalUserView::read_person(conn, recipient_id)
+ // Add parent poster or commenter to recipients
+ let comment_reply = blocking(context.pool(), move |conn| {
+ CommentReply::read_by_comment(conn, comment_id)
})
- .await?
- {
- recipient_ids.push(local_recipient.local_user.id);
+ .await?;
+ if let Ok(reply) = comment_reply {
+ let recipient_id = reply.recipient_id;
+ if let Ok(local_recipient) = blocking(context.pool(), move |conn| {
+ LocalUserView::read_person(conn, recipient_id)
+ })
+ .await?
+ {
+ recipient_ids.push(local_recipient.local_user.id);
+ }
}
let like_form = CommentLikeForm {
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add {
let like_form2 = like_form.clone();
- let like = move |conn: &'_ _| CommentLike::like(conn, &like_form2);
+ let like = move |conn: &mut _| CommentLike::like(conn, &like_form2);
blocking(context.pool(), like)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;