mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-31 17:50:01 +00:00
150 lines
3.7 KiB
Rust
150 lines
3.7 KiB
Rust
use crate::activities::receive::get_actor_as_person;
|
|
use activitystreams::activity::{Dislike, Like};
|
|
use lemmy_api_structs::{blocking, comment::CommentResponse};
|
|
use lemmy_db_queries::{source::comment::Comment_, Likeable};
|
|
use lemmy_db_schema::source::comment::{Comment, CommentLike};
|
|
use lemmy_db_views::comment_view::CommentView;
|
|
use lemmy_utils::LemmyError;
|
|
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
|
|
|
|
pub(crate) async fn receive_undo_like_comment(
|
|
like: &Like,
|
|
comment: Comment,
|
|
context: &LemmyContext,
|
|
request_counter: &mut i32,
|
|
) -> Result<(), LemmyError> {
|
|
let person = get_actor_as_person(like, context, request_counter).await?;
|
|
|
|
let comment_id = comment.id;
|
|
let person_id = person.id;
|
|
blocking(context.pool(), move |conn| {
|
|
CommentLike::remove(conn, person_id, comment_id)
|
|
})
|
|
.await??;
|
|
|
|
// Refetch the view
|
|
let comment_view = blocking(context.pool(), move |conn| {
|
|
CommentView::read(conn, comment_id, None)
|
|
})
|
|
.await??;
|
|
|
|
// TODO get those recipient actor ids from somewhere
|
|
let recipient_ids = vec![];
|
|
let res = CommentResponse {
|
|
comment_view,
|
|
recipient_ids,
|
|
form_id: None,
|
|
};
|
|
|
|
context.chat_server().do_send(SendComment {
|
|
op: UserOperation::CreateCommentLike,
|
|
comment: res,
|
|
websocket_id: None,
|
|
});
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub(crate) async fn receive_undo_dislike_comment(
|
|
dislike: &Dislike,
|
|
comment: Comment,
|
|
context: &LemmyContext,
|
|
request_counter: &mut i32,
|
|
) -> Result<(), LemmyError> {
|
|
let person = get_actor_as_person(dislike, context, request_counter).await?;
|
|
|
|
let comment_id = comment.id;
|
|
let person_id = person.id;
|
|
blocking(context.pool(), move |conn| {
|
|
CommentLike::remove(conn, person_id, comment_id)
|
|
})
|
|
.await??;
|
|
|
|
// Refetch the view
|
|
let comment_view = blocking(context.pool(), move |conn| {
|
|
CommentView::read(conn, comment_id, None)
|
|
})
|
|
.await??;
|
|
|
|
// TODO get those recipient actor ids from somewhere
|
|
let recipient_ids = vec![];
|
|
let res = CommentResponse {
|
|
comment_view,
|
|
recipient_ids,
|
|
form_id: None,
|
|
};
|
|
|
|
context.chat_server().do_send(SendComment {
|
|
op: UserOperation::CreateCommentLike,
|
|
comment: res,
|
|
websocket_id: None,
|
|
});
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub(crate) async fn receive_undo_delete_comment(
|
|
context: &LemmyContext,
|
|
comment: Comment,
|
|
) -> Result<(), LemmyError> {
|
|
let deleted_comment = blocking(context.pool(), move |conn| {
|
|
Comment::update_deleted(conn, comment.id, false)
|
|
})
|
|
.await??;
|
|
|
|
// Refetch the view
|
|
let comment_id = deleted_comment.id;
|
|
let comment_view = blocking(context.pool(), move |conn| {
|
|
CommentView::read(conn, comment_id, None)
|
|
})
|
|
.await??;
|
|
|
|
// TODO get those recipient actor ids from somewhere
|
|
let recipient_ids = vec![];
|
|
let res = CommentResponse {
|
|
comment_view,
|
|
recipient_ids,
|
|
form_id: None,
|
|
};
|
|
|
|
context.chat_server().do_send(SendComment {
|
|
op: UserOperation::EditComment,
|
|
comment: res,
|
|
websocket_id: None,
|
|
});
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub(crate) async fn receive_undo_remove_comment(
|
|
context: &LemmyContext,
|
|
comment: Comment,
|
|
) -> Result<(), LemmyError> {
|
|
let removed_comment = blocking(context.pool(), move |conn| {
|
|
Comment::update_removed(conn, comment.id, false)
|
|
})
|
|
.await??;
|
|
|
|
// Refetch the view
|
|
let comment_id = removed_comment.id;
|
|
let comment_view = blocking(context.pool(), move |conn| {
|
|
CommentView::read(conn, comment_id, None)
|
|
})
|
|
.await??;
|
|
|
|
// TODO get those recipient actor ids from somewhere
|
|
let recipient_ids = vec![];
|
|
let res = CommentResponse {
|
|
comment_view,
|
|
recipient_ids,
|
|
form_id: None,
|
|
};
|
|
|
|
context.chat_server().do_send(SendComment {
|
|
op: UserOperation::EditComment,
|
|
comment: res,
|
|
websocket_id: None,
|
|
});
|
|
|
|
Ok(())
|
|
}
|