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 #[tracing::instrument(skip_all)]
25 async fn vote_comment(
28 comment: &ApubComment,
29 context: &LemmyContext,
30 ) -> Result<(), LemmyError> {
31 let comment_id = comment.id;
32 let like_form = CommentLikeForm {
34 post_id: comment.post_id,
36 score: vote_type.into(),
38 let person_id = actor.id;
39 blocking(context.pool(), move |conn| {
40 CommentLike::remove(conn, person_id, comment_id)?;
41 CommentLike::like(conn, &like_form)
45 send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
49 #[tracing::instrument(skip_all)]
54 context: &LemmyContext,
55 ) -> Result<(), LemmyError> {
56 let post_id = post.id;
57 let like_form = PostLikeForm {
60 score: vote_type.into(),
62 let person_id = actor.id;
63 blocking(context.pool(), move |conn| {
64 PostLike::remove(conn, person_id, post_id)?;
65 PostLike::like(conn, &like_form)
69 send_post_ws_message(post.id, UserOperation::CreatePostLike, None, None, context).await?;
73 #[tracing::instrument(skip_all)]
74 async fn undo_vote_comment(
76 comment: &ApubComment,
77 context: &LemmyContext,
78 ) -> Result<(), LemmyError> {
79 let comment_id = comment.id;
80 let person_id = actor.id;
81 blocking(context.pool(), move |conn| {
82 CommentLike::remove(conn, person_id, comment_id)
86 send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
90 #[tracing::instrument(skip_all)]
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)
103 send_post_ws_message(post_id, UserOperation::CreatePostLike, None, None, context).await?;