1 use lemmy_api_common::blocking;
4 comment::{CommentLike, CommentLikeForm},
5 post::{PostLike, PostLikeForm},
9 use lemmy_utils::LemmyError;
10 use lemmy_websocket::{
11 send::{send_comment_ws_message_simple, send_post_ws_message},
17 objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
18 protocol::activities::voting::vote::VoteType,
24 async fn vote_comment(
27 comment: &ApubComment,
28 context: &LemmyContext,
29 ) -> Result<(), LemmyError> {
30 let comment_id = comment.id;
31 let like_form = CommentLikeForm {
33 post_id: comment.post_id,
35 score: vote_type.into(),
37 let person_id = actor.id;
38 blocking(context.pool(), move |conn| {
39 CommentLike::remove(conn, person_id, comment_id)?;
40 CommentLike::like(conn, &like_form)
44 send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
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_ws_message(post.id, UserOperation::CreatePostLike, None, None, context).await?;
71 async fn undo_vote_comment(
73 comment: &ApubComment,
74 context: &LemmyContext,
75 ) -> Result<(), LemmyError> {
76 let comment_id = comment.id;
77 let person_id = actor.id;
78 blocking(context.pool(), move |conn| {
79 CommentLike::remove(conn, person_id, comment_id)
83 send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
87 async fn undo_vote_post(
90 context: &LemmyContext,
91 ) -> Result<(), LemmyError> {
92 let post_id = post.id;
93 let person_id = actor.id;
94 blocking(context.pool(), move |conn| {
95 PostLike::remove(conn, person_id, post_id)
99 send_post_ws_message(post_id, UserOperation::CreatePostLike, None, None, context).await?;