1 use crate::activities::{
2 comment::send_websocket_message as send_comment_message,
3 post::send_websocket_message as send_post_message,
4 voting::vote::VoteType,
6 use lemmy_api_common::blocking;
7 use lemmy_db_queries::Likeable;
8 use lemmy_db_schema::source::{
9 comment::{Comment, CommentLike, CommentLikeForm},
11 post::{Post, PostLike, PostLikeForm},
13 use lemmy_utils::LemmyError;
14 use lemmy_websocket::{LemmyContext, UserOperation};
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)
42 UserOperation::CreateCommentLike,
52 context: &LemmyContext,
53 ) -> Result<(), LemmyError> {
54 let post_id = post.id;
55 let like_form = PostLikeForm {
58 score: vote_type.into(),
60 let person_id = actor.id;
61 blocking(context.pool(), move |conn| {
62 PostLike::remove(conn, person_id, post_id)?;
63 PostLike::like(conn, &like_form)
67 send_post_message(post.id, UserOperation::CreatePostLike, context).await
70 async fn undo_vote_comment(
73 context: &LemmyContext,
74 ) -> Result<(), LemmyError> {
75 let comment_id = comment.id;
76 let person_id = actor.id;
77 blocking(context.pool(), move |conn| {
78 CommentLike::remove(conn, person_id, comment_id)
85 UserOperation::CreateCommentLike,
91 async fn undo_vote_post(
94 context: &LemmyContext,
95 ) -> Result<(), LemmyError> {
96 let post_id = post.id;
97 let person_id = actor.id;
98 blocking(context.pool(), move |conn| {
99 PostLike::remove(conn, person_id, post_id)
102 send_post_message(post.id, UserOperation::CreatePostLike, context).await