2 objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
3 protocol::activities::voting::vote::VoteType,
7 comment::{CommentLike, CommentLikeForm},
8 post::{PostLike, PostLikeForm},
12 use lemmy_utils::error::LemmyError;
13 use lemmy_websocket::{
14 send::{send_comment_ws_message_simple, send_post_ws_message},
22 #[tracing::instrument(skip_all)]
23 async fn vote_comment(
26 comment: &ApubComment,
27 context: &LemmyContext,
28 ) -> Result<(), LemmyError> {
29 let comment_id = comment.id;
30 let like_form = CommentLikeForm {
32 post_id: comment.post_id,
34 score: vote_type.into(),
36 let person_id = actor.id;
37 CommentLike::remove(context.pool(), person_id, comment_id).await?;
38 CommentLike::like(context.pool(), &like_form).await?;
40 send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
44 #[tracing::instrument(skip_all)]
49 context: &LemmyContext,
50 ) -> Result<(), LemmyError> {
51 let post_id = post.id;
52 let like_form = PostLikeForm {
55 score: vote_type.into(),
57 let person_id = actor.id;
58 PostLike::remove(context.pool(), person_id, post_id).await?;
59 PostLike::like(context.pool(), &like_form).await?;
61 send_post_ws_message(post.id, UserOperation::CreatePostLike, None, None, context).await?;
65 #[tracing::instrument(skip_all)]
66 async fn undo_vote_comment(
68 comment: &ApubComment,
69 context: &LemmyContext,
70 ) -> Result<(), LemmyError> {
71 let comment_id = comment.id;
72 let person_id = actor.id;
73 CommentLike::remove(context.pool(), person_id, comment_id).await?;
75 send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
79 #[tracing::instrument(skip_all)]
80 async fn undo_vote_post(
83 context: &LemmyContext,
84 ) -> Result<(), LemmyError> {
85 let post_id = post.id;
86 let person_id = actor.id;
87 PostLike::remove(context.pool(), person_id, post_id).await?;
89 send_post_ws_message(post_id, UserOperation::CreatePostLike, None, None, context).await?;