diff --git a/lemmy_apub/src/activities/receive/comment.rs b/lemmy_apub/src/activities/receive/comment.rs index 6f6a22da8..da29a3b7e 100644 --- a/lemmy_apub/src/activities/receive/comment.rs +++ b/lemmy_apub/src/activities/receive/comment.rs @@ -3,7 +3,7 @@ use activitystreams::{ activity::{ActorAndObjectRefExt, Create, Dislike, Like, Remove, Update}, base::ExtendsExt, }; -use anyhow::{anyhow, Context}; +use anyhow::Context; use lemmy_db::{ comment::{Comment, CommentLike, CommentLikeForm}, comment_view::CommentView, @@ -23,14 +23,10 @@ pub(crate) async fn receive_create_comment( let note = NoteExt::from_any_base(create.object().to_owned().one().context(location_info!())?)? .context(location_info!())?; - // TODO: need to do the check for locked post before calling this let comment = Comment::from_apub(¬e, context, Some(user.actor_id()?), request_counter).await?; let post_id = comment.post_id; let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??; - if post.locked { - return Err(anyhow!("Post is locked").into()); - } // Note: // Although mentions could be gotten from the post tags (they are included there), or the ccs, diff --git a/lemmy_apub/src/objects/comment.rs b/lemmy_apub/src/objects/comment.rs index b92411e72..1454a738c 100644 --- a/lemmy_apub/src/objects/comment.rs +++ b/lemmy_apub/src/objects/comment.rs @@ -20,7 +20,7 @@ use activitystreams::{ object::{kind::NoteType, ApObject, Note, Tombstone}, prelude::*, }; -use anyhow::Context; +use anyhow::{anyhow, Context}; use lemmy_db::{ comment::{Comment, CommentForm}, community::Community, @@ -114,6 +114,12 @@ impl FromApub for Comment { } else { let comment_form = CommentForm::from_apub(note, context, expected_domain, request_counter).await?; + let post_id = comment_form.post_id; + let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??; + if post.locked { + return Err(anyhow!("Post is locked").into()); + } + let comment = blocking(context.pool(), move |conn| { Comment::upsert(conn, &comment_form) })