1 use crate::activities::receive::get_actor_as_user;
2 use activitystreams::activity::{Dislike, Like};
3 use lemmy_api_structs::{blocking, post::PostResponse};
4 use lemmy_db_queries::{source::post::Post_, Likeable};
5 use lemmy_db_schema::source::post::{Post, PostLike};
6 use lemmy_db_views::post_view::PostView;
7 use lemmy_utils::LemmyError;
8 use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
10 pub(crate) async fn receive_undo_like_post(
13 context: &LemmyContext,
14 request_counter: &mut i32,
15 ) -> Result<(), LemmyError> {
16 let user = get_actor_as_user(like, context, request_counter).await?;
18 let post_id = post.id;
19 let user_id = user.id;
20 blocking(context.pool(), move |conn| {
21 PostLike::remove(conn, user_id, post_id)
26 let post_view = blocking(context.pool(), move |conn| {
27 PostView::read(conn, post_id, None)
31 let res = PostResponse { post_view };
33 context.chat_server().do_send(SendPost {
34 op: UserOperation::CreatePostLike,
42 pub(crate) async fn receive_undo_dislike_post(
45 context: &LemmyContext,
46 request_counter: &mut i32,
47 ) -> Result<(), LemmyError> {
48 let user = get_actor_as_user(dislike, context, request_counter).await?;
50 let post_id = post.id;
51 let user_id = user.id;
52 blocking(context.pool(), move |conn| {
53 PostLike::remove(conn, user_id, post_id)
58 let post_view = blocking(context.pool(), move |conn| {
59 PostView::read(conn, post_id, None)
63 let res = PostResponse { post_view };
65 context.chat_server().do_send(SendPost {
66 op: UserOperation::CreatePostLike,
74 pub(crate) async fn receive_undo_delete_post(
75 context: &LemmyContext,
77 ) -> Result<(), LemmyError> {
78 let deleted_post = blocking(context.pool(), move |conn| {
79 Post::update_deleted(conn, post.id, false)
84 let post_id = deleted_post.id;
85 let post_view = blocking(context.pool(), move |conn| {
86 PostView::read(conn, post_id, None)
90 let res = PostResponse { post_view };
91 context.chat_server().do_send(SendPost {
92 op: UserOperation::EditPost,
100 pub(crate) async fn receive_undo_remove_post(
101 context: &LemmyContext,
103 ) -> Result<(), LemmyError> {
104 let removed_post = blocking(context.pool(), move |conn| {
105 Post::update_removed(conn, post.id, false)
110 let post_id = removed_post.id;
111 let post_view = blocking(context.pool(), move |conn| {
112 PostView::read(conn, post_id, None)
116 let res = PostResponse { post_view };
118 context.chat_server().do_send(SendPost {
119 op: UserOperation::EditPost,