]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/objects/comment.rs
Moving settings to Database. (#2492)
[lemmy.git] / crates / apub / src / objects / comment.rs
index e292d2b671ac58b13349d4bf9e703fe1507c8235..154bd41c982e78884667da38c9dc4553389f3569 100644 (file)
@@ -1,6 +1,7 @@
 use crate::{
   activities::{verify_is_public, verify_person_in_community},
   check_apub_id_valid_with_strictness,
+  fetch_local_site_data,
   local_instance,
   mentions::collect_non_local_mentions,
   objects::{read_from_string_or_source, verify_is_remote_object},
@@ -18,11 +19,12 @@ use activitypub_federation::{
 };
 use activitystreams_kinds::{object::NoteType, public};
 use chrono::NaiveDateTime;
-use lemmy_api_common::utils::blocking;
+use lemmy_api_common::utils::{blocking, local_site_opt_to_slur_regex};
 use lemmy_db_schema::{
   source::{
-    comment::{Comment, CommentForm},
+    comment::{Comment, CommentInsertForm, CommentUpdateForm},
     community::Community,
+    local_site::LocalSite,
     person::Person,
     post::Post,
   },
@@ -81,7 +83,8 @@ impl ApubObject for ApubComment {
   async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
     if !self.deleted {
       blocking(context.pool(), move |conn| {
-        Comment::update_deleted(conn, self.id, true)
+        let form = CommentUpdateForm::builder().deleted(Some(true)).build();
+        Comment::update(conn, self.id, &form)
       })
       .await??;
     }
@@ -148,7 +151,14 @@ impl ApubObject for ApubComment {
       Community::read(conn, community_id)
     })
     .await??;
-    check_apub_id_valid_with_strictness(note.id.inner(), community.local, context.settings())?;
+    let local_site_data = blocking(context.pool(), fetch_local_site_data).await??;
+
+    check_apub_id_valid_with_strictness(
+      note.id.inner(),
+      community.local,
+      &local_site_data,
+      context.settings(),
+    )?;
     verify_is_remote_object(note.id.inner(), context.settings())?;
     verify_person_in_community(
       &note.attributed_to,
@@ -179,10 +189,13 @@ impl ApubObject for ApubComment {
     let (post, parent_comment) = note.get_parents(context, request_counter).await?;
 
     let content = read_from_string_or_source(&note.content, &note.media_type, &note.source);
-    let content_slurs_removed = remove_slurs(&content, &context.settings().slur_regex());
+
+    let local_site = blocking(context.pool(), LocalSite::read).await?.ok();
+    let slur_regex = &local_site_opt_to_slur_regex(&local_site);
+    let content_slurs_removed = remove_slurs(&content, slur_regex);
     let language_id = LanguageTag::to_language_id_single(note.language, context.pool()).await?;
 
-    let form = CommentForm {
+    let form = CommentInsertForm {
       creator_id: creator.id,
       post_id: post.id,
       content: content_slurs_removed,
@@ -244,6 +257,7 @@ pub(crate) mod tests {
     Community::delete(conn, data.1.id).unwrap();
     Person::delete(conn, data.0.id).unwrap();
     Site::delete(conn, data.3.id).unwrap();
+    LocalSite::delete(conn).unwrap();
   }
 
   #[actix_rt::test]