1 use crate::activities::voting::vote::VoteType;
2 use lemmy_api_common::blocking;
3 use lemmy_db_queries::Likeable;
4 use lemmy_db_schema::source::{
5 comment::{Comment, CommentLike, CommentLikeForm},
7 post::{Post, PostLike, PostLikeForm},
9 use lemmy_utils::LemmyError;
10 use lemmy_websocket::{
11 send::{send_comment_ws_message_simple, send_post_ws_message},
19 async fn vote_comment(
23 context: &LemmyContext,
24 ) -> Result<(), LemmyError> {
25 let comment_id = comment.id;
26 let like_form = CommentLikeForm {
28 post_id: comment.post_id,
30 score: vote_type.into(),
32 let person_id = actor.id;
33 blocking(context.pool(), move |conn| {
34 CommentLike::remove(conn, person_id, comment_id)?;
35 CommentLike::like(conn, &like_form)
39 send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
47 context: &LemmyContext,
48 ) -> Result<(), LemmyError> {
49 let post_id = post.id;
50 let like_form = PostLikeForm {
53 score: vote_type.into(),
55 let person_id = actor.id;
56 blocking(context.pool(), move |conn| {
57 PostLike::remove(conn, person_id, post_id)?;
58 PostLike::like(conn, &like_form)
62 send_post_ws_message(post.id, UserOperation::CreatePostLike, None, None, context).await?;
66 async fn undo_vote_comment(
69 context: &LemmyContext,
70 ) -> Result<(), LemmyError> {
71 let comment_id = comment.id;
72 let person_id = actor.id;
73 blocking(context.pool(), move |conn| {
74 CommentLike::remove(conn, person_id, comment_id)
78 send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
82 async fn undo_vote_post(
85 context: &LemmyContext,
86 ) -> Result<(), LemmyError> {
87 let post_id = post.id;
88 let person_id = actor.id;
89 blocking(context.pool(), move |conn| {
90 PostLike::remove(conn, person_id, post_id)
94 send_post_ws_message(post_id, UserOperation::CreatePostLike, None, None, context).await?;