1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
7 get_local_user_view_from_jwt,
10 use lemmy_apub::ApubObjectType;
11 use lemmy_db_queries::{source::comment::Comment_, DeleteableOrRemoveable};
12 use lemmy_db_schema::source::comment::*;
13 use lemmy_db_views::comment_view::CommentView;
15 utils::{remove_slurs, scrape_text_for_mentions},
20 use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperationCrud};
22 #[async_trait::async_trait(?Send)]
23 impl PerformCrud for EditComment {
24 type Response = CommentResponse;
28 context: &Data<LemmyContext>,
29 websocket_id: Option<ConnectionId>,
30 ) -> Result<CommentResponse, LemmyError> {
31 let data: &EditComment = self;
32 let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
34 let comment_id = data.comment_id;
35 let orig_comment = blocking(context.pool(), move |conn| {
36 CommentView::read(conn, comment_id, None)
41 local_user_view.person.id,
42 orig_comment.community.id,
47 // Verify that only the creator can edit
48 if local_user_view.person.id != orig_comment.creator.id {
49 return Err(ApiError::err("no_comment_edit_allowed").into());
53 let content_slurs_removed = remove_slurs(&data.content.to_owned());
54 let comment_id = data.comment_id;
55 let updated_comment = blocking(context.pool(), move |conn| {
56 Comment::update_content(conn, comment_id, &content_slurs_removed)
59 .map_err(|_| ApiError::err("couldnt_update_comment"))?;
61 // Send the apub update
63 .send_update(&local_user_view.person, context)
66 // Do the mentions / recipients
67 let updated_comment_content = updated_comment.content.to_owned();
68 let mentions = scrape_text_for_mentions(&updated_comment_content);
69 let recipient_ids = send_local_notifs(
72 local_user_view.person.clone(),
79 let comment_id = data.comment_id;
80 let person_id = local_user_view.person.id;
81 let mut comment_view = blocking(context.pool(), move |conn| {
82 CommentView::read(conn, comment_id, Some(person_id))
86 // Blank out deleted or removed info
87 if comment_view.comment.deleted || comment_view.comment.removed {
88 comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
91 let res = CommentResponse {
94 form_id: data.form_id.to_owned(),
97 context.chat_server().do_send(SendComment {
98 op: UserOperationCrud::EditComment,