traits::Crud,
};
use lemmy_utils::{
- error::LemmyError,
+ error::{LemmyError, LemmyErrorType},
utils::{markdown::markdown_to_html, time::convert_datetime},
};
use std::ops::Deref;
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),
)
#[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,
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(())
}
) -> 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,
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())
}
}
}
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();
}
#[tokio::test]
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;
}
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;
}
}