-#[async_trait::async_trait(?Send)]
-impl FromApubToForm<NoteExt> for PrivateMessageForm {
- async fn from_apub(
- note: &NoteExt,
- context: &LemmyContext,
- expected_domain: Url,
- request_counter: &mut i32,
- ) -> Result<PrivateMessageForm, LemmyError> {
- let creator_actor_id = note
- .attributed_to()
- .context(location_info!())?
- .clone()
- .single_xsd_any_uri()
- .context(location_info!())?;
-
- let creator = get_or_fetch_and_upsert_user(&creator_actor_id, context, request_counter).await?;
- let recipient_actor_id = note
- .to()
- .context(location_info!())?
- .clone()
- .single_xsd_any_uri()
- .context(location_info!())?;
- let recipient =
- get_or_fetch_and_upsert_user(&recipient_actor_id, context, request_counter).await?;
- let ap_id = note.id_unchecked().context(location_info!())?.to_string();
- check_is_apub_id_valid(&Url::parse(&ap_id)?)?;
-
- let content = get_source_markdown_value(note)?.context(location_info!())?;
-
- Ok(PrivateMessageForm {
- creator_id: creator.id,
- recipient_id: recipient.id,
- content,
- published: note.published().map(|u| u.to_owned().naive_local()),
- updated: note.updated().map(|u| u.to_owned().naive_local()),
- deleted: None,
- read: None,
- ap_id: Some(check_object_domain(note, expected_domain)?),
- local: false,
- })
+ async fn cleanup(data: (ApubPerson, ApubPerson, ApubSite), context: &Data<LemmyContext>) {
+ 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]
+ #[serial]
+ async fn test_parse_lemmy_pm() {
+ let context = init_context().await;
+ let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
+ let data = prepare_comment_test(&url, &context).await;
+ let json: ChatMessage = file_to_json_object("assets/lemmy/objects/chat_message.json").unwrap();
+ ApubPrivateMessage::verify(&json, &url, &context)
+ .await
+ .unwrap();
+ let pm = ApubPrivateMessage::from_json(json.clone(), &context)
+ .await
+ .unwrap();
+
+ assert_eq!(pm.ap_id.clone(), url.into());
+ assert_eq!(pm.content.len(), 20);
+ assert_eq!(context.request_count(), 0);
+
+ let pm_id = pm.id;
+ let to_apub = pm.into_json(&context).await.unwrap();
+ assert_json_include!(actual: json, expected: to_apub);
+
+ PrivateMessage::delete(&mut context.pool(), pm_id)
+ .await
+ .unwrap();
+ cleanup(data, &context).await;
+ }
+
+ #[tokio::test]
+ #[serial]
+ async fn test_parse_pleroma_pm() {
+ let context = init_context().await;
+ let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
+ let data = prepare_comment_test(&url, &context).await;
+ let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/2").unwrap();
+ let json = file_to_json_object("assets/pleroma/objects/chat_message.json").unwrap();
+ ApubPrivateMessage::verify(&json, &pleroma_url, &context)
+ .await
+ .unwrap();
+ let pm = ApubPrivateMessage::from_json(json, &context).await.unwrap();
+
+ assert_eq!(pm.ap_id, pleroma_url.into());
+ assert_eq!(pm.content.len(), 3);
+ assert_eq!(context.request_count(), 0);
+
+ PrivateMessage::delete(&mut context.pool(), pm.id)
+ .await
+ .unwrap();
+ cleanup(data, &context).await;