mirror of https://github.com/LemmyNet/lemmy.git
Make Note.context optional for pleroma compat (hack)
parent
03b8ae7215
commit
74523fb534
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://greenish.red/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"actor": "https://greenish.red/users/nutomic",
|
||||
"cc": [
|
||||
"https://greenish.red/users/nutomic/followers"
|
||||
],
|
||||
"context": "https://greenish.red/contexts/f6244742-0526-4b84-ac4f-ceadf1fb4e56",
|
||||
"context_id": 6336544,
|
||||
"directMessage": false,
|
||||
"id": "https://greenish.red/activities/db61d52b-9c35-486a-bf27-bbd4edc6c6a1",
|
||||
"object": {
|
||||
"actor": "https://greenish.red/users/nutomic",
|
||||
"attachment": [],
|
||||
"attributedTo": "https://greenish.red/users/nutomic",
|
||||
"cc": [
|
||||
"https://greenish.red/users/nutomic/followers"
|
||||
],
|
||||
"content": "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"ACimPLEXPDd7enu3cm\" href=\"https://enterprise.lemmy.ml/u/picard\" rel=\"ugc\">@<span>lanodan</span></a></span> test",
|
||||
"context": "https://greenish.red/contexts/f6244742-0526-4b84-ac4f-ceadf1fb4e56",
|
||||
"conversation": "https://greenish.red/contexts/f6244742-0526-4b84-ac4f-ceadf1fb4e56",
|
||||
"id": "https://greenish.red/objects/1a522f2e-d5ab-454b-93d7-e58bc0650c2a",
|
||||
"inReplyTo": "https://enterprise.lemmy.ml/post/55143",
|
||||
"published": "2021-10-26T10:28:35.602455Z",
|
||||
"sensitive": false,
|
||||
"source": "@lanodan@ds9.lemmy.ml test",
|
||||
"summary": "",
|
||||
"tag": [
|
||||
{
|
||||
"href": "https://enterprise.lemmy.ml/u/picard",
|
||||
"name": "@lanodan@ds9.lemmy.ml",
|
||||
"type": "Mention"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://enterprise.lemmy.ml/u/picard",
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Note"
|
||||
},
|
||||
"published": "2021-10-26T10:28:35.595650Z",
|
||||
"to": [
|
||||
"https://enterprise.lemmy.ml/u/picard",
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"type": "Create"
|
||||
}
|
|
@ -47,6 +47,7 @@ pub struct CreateOrUpdateComment {
|
|||
to: Vec<Url>,
|
||||
object: Note,
|
||||
cc: Vec<Url>,
|
||||
#[serde(default)]
|
||||
tag: Vec<Mention>,
|
||||
#[serde(rename = "type")]
|
||||
kind: CreateOrUpdateType,
|
||||
|
@ -142,3 +143,16 @@ impl ActivityHandler for CreateOrUpdateComment {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::objects::tests::file_to_json_object;
|
||||
use serial_test::serial;
|
||||
|
||||
#[actix_rt::test]
|
||||
#[serial]
|
||||
async fn test_parse_pleroma_create_comment() {
|
||||
let _: CreateOrUpdateComment = file_to_json_object("assets/pleroma-create-comment.json");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,8 +46,11 @@ use url::Url;
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Note {
|
||||
/// Necessary to make this optional to make Pleroma Create/Note work.
|
||||
/// TODO: change this so that context is not defined in the struct itself, but added in activity
|
||||
/// queue and http handlers
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
context: Option<OneOrMany<AnyBase>>,
|
||||
r#type: NoteType,
|
||||
id: Url,
|
||||
pub(crate) attributed_to: ObjectId<ApubPerson>,
|
||||
|
@ -202,7 +205,7 @@ impl ApubObject for ApubComment {
|
|||
};
|
||||
|
||||
let note = Note {
|
||||
context: lemmy_context(),
|
||||
context: Some(lemmy_context()),
|
||||
r#type: NoteType::Note,
|
||||
id: self.ap_id.to_owned().into_inner(),
|
||||
attributed_to: ObjectId::new(creator.actor_id),
|
||||
|
@ -274,7 +277,7 @@ impl ApubObject for ApubComment {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
use crate::objects::{
|
||||
community::ApubCommunity,
|
||||
|
@ -283,7 +286,7 @@ mod tests {
|
|||
use assert_json_diff::assert_json_include;
|
||||
use serial_test::serial;
|
||||
|
||||
async fn prepare_comment_test(
|
||||
pub(crate) async fn prepare_comment_test(
|
||||
url: &Url,
|
||||
context: &LemmyContext,
|
||||
) -> (ApubPerson, ApubCommunity, ApubPost) {
|
||||
|
@ -310,9 +313,7 @@ mod tests {
|
|||
|
||||
#[actix_rt::test]
|
||||
#[serial]
|
||||
async fn test_parse_lemmy_comment() {
|
||||
// TODO: changed ObjectId::dereference() so that it always fetches if
|
||||
// last_refreshed_at() == None. But post doesnt store that and expects to never be refetched
|
||||
pub(crate) async fn test_parse_lemmy_comment() {
|
||||
let context = init_context();
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
|
||||
let data = prepare_comment_test(&url, &context).await;
|
||||
|
|
|
@ -38,7 +38,7 @@ fn get_summary_from_string_or_source(
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub(crate) mod tests {
|
||||
use actix::Actor;
|
||||
use diesel::{
|
||||
r2d2::{ConnectionManager, Pool},
|
||||
|
|
Loading…
Reference in New Issue