]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/objects/private_message.rs
Cache & Optimize Woodpecker CI (#3450)
[lemmy.git] / crates / apub / src / objects / private_message.rs
index 01f576ff8ff667f7ed8679850271ad9cc9a8d4f1..69a2638ad09dfc745539fcae548c1c1165aec931 100644 (file)
@@ -1,6 +1,5 @@
 use crate::{
   check_apub_id_valid_with_strictness,
-  fetch_local_site_data,
   objects::read_from_string_or_source,
   protocol::{
     objects::chat_message::{ChatMessage, ChatMessageType},
@@ -22,7 +21,7 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_utils::{
-  error::LemmyError,
+  error::{LemmyError, LemmyErrorType},
   utils::{markdown::markdown_to_html, time::convert_datetime},
 };
 use std::ops::Deref;
@@ -60,7 +59,7 @@ impl Object for ApubPrivateMessage {
     context: &Data<Self::DataType>,
   ) -> Result<Option<Self>, LemmyError> {
     Ok(
-      PrivateMessage::read_from_apub_id(context.pool(), object_id)
+      PrivateMessage::read_from_apub_id(&mut context.pool(), object_id)
         .await?
         .map(Into::into),
     )
@@ -74,10 +73,10 @@ impl Object for ApubPrivateMessage {
   #[tracing::instrument(skip_all)]
   async fn into_json(self, context: &Data<Self::DataType>) -> Result<ChatMessage, LemmyError> {
     let creator_id = self.creator_id;
-    let creator = Person::read(context.pool(), creator_id).await?;
+    let creator = Person::read(&mut context.pool(), creator_id).await?;
 
     let recipient_id = self.recipient_id;
-    let recipient = Person::read(context.pool(), recipient_id).await?;
+    let recipient = Person::read(&mut context.pool(), recipient_id).await?;
 
     let note = ChatMessage {
       r#type: ChatMessageType::ChatMessage,
@@ -102,17 +101,10 @@ impl Object for ApubPrivateMessage {
     verify_domains_match(note.id.inner(), expected_domain)?;
     verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
 
-    let local_site_data = fetch_local_site_data(context.pool()).await?;
-
-    check_apub_id_valid_with_strictness(
-      note.id.inner(),
-      false,
-      &local_site_data,
-      context.settings(),
-    )?;
+    check_apub_id_valid_with_strictness(note.id.inner(), false, context).await?;
     let person = note.attributed_to.dereference(context).await?;
     if person.banned {
-      return Err(LemmyError::from_message("Person is banned from site"));
+      return Err(LemmyErrorType::PersonIsBannedFromSite)?;
     }
     Ok(())
   }
@@ -124,7 +116,7 @@ impl Object for ApubPrivateMessage {
   ) -> Result<ApubPrivateMessage, LemmyError> {
     let creator = note.attributed_to.dereference(context).await?;
     let recipient = note.to[0].dereference(context).await?;
-    check_person_block(creator.id, recipient.id, context.pool()).await?;
+    check_person_block(creator.id, recipient.id, &mut context.pool()).await?;
 
     let form = PrivateMessageInsertForm {
       creator_id: creator.id,
@@ -137,13 +129,16 @@ impl Object for ApubPrivateMessage {
       ap_id: Some(note.id.into()),
       local: Some(false),
     };
-    let pm = PrivateMessage::create(context.pool(), &form).await?;
+    let pm = PrivateMessage::create(&mut context.pool(), &form).await?;
     Ok(pm.into())
   }
 }
 
 #[cfg(test)]
 mod tests {
+  #![allow(clippy::unwrap_used)]
+  #![allow(clippy::indexing_slicing)]
+
   use super::*;
   use crate::{
     objects::{
@@ -182,12 +177,16 @@ mod tests {
   }
 
   async fn cleanup(data: (ApubPerson, ApubPerson, ApubSite), context: &Data<LemmyContext>) {
-    Person::delete(context.pool(), data.0.id).await.unwrap();
-    Person::delete(context.pool(), data.1.id).await.unwrap();
-    Site::delete(context.pool(), data.2.id).await.unwrap();
+    Person::delete(&mut context.pool(), data.0.id)
+      .await
+      .unwrap();
+    Person::delete(&mut context.pool(), data.1.id)
+      .await
+      .unwrap();
+    Site::delete(&mut context.pool(), data.2.id).await.unwrap();
   }
 
-  #[actix_rt::test]
+  #[tokio::test]
   #[serial]
   async fn test_parse_lemmy_pm() {
     let context = init_context().await;
@@ -209,11 +208,13 @@ mod tests {
     let to_apub = pm.into_json(&context).await.unwrap();
     assert_json_include!(actual: json, expected: to_apub);
 
-    PrivateMessage::delete(context.pool(), pm_id).await.unwrap();
+    PrivateMessage::delete(&mut context.pool(), pm_id)
+      .await
+      .unwrap();
     cleanup(data, &context).await;
   }
 
-  #[actix_rt::test]
+  #[tokio::test]
   #[serial]
   async fn test_parse_pleroma_pm() {
     let context = init_context().await;
@@ -230,7 +231,9 @@ mod tests {
     assert_eq!(pm.content.len(), 3);
     assert_eq!(context.request_count(), 0);
 
-    PrivateMessage::delete(context.pool(), pm.id).await.unwrap();
+    PrivateMessage::delete(&mut context.pool(), pm.id)
+      .await
+      .unwrap();
     cleanup(data, &context).await;
   }
 }