mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 19:31:33 +00:00
Accept Image objects in attachments (#2394)
This commit is contained in:
parent
2f9d8776ac
commit
08a797c986
4 changed files with 51 additions and 6 deletions
26
crates/apub/assets/lotide/activities/create_page_image.json
Normal file
26
crates/apub/assets/lotide/activities/create_page_image.json
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"actor": "http://ltthostname.local:3334/apub/users/3",
|
||||||
|
"object": {
|
||||||
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
|
"id": "http://ltthostname.local:3334/apub/posts/46",
|
||||||
|
"type": "Note",
|
||||||
|
"name": "image",
|
||||||
|
"to": "http://localhost:8536/c/elsewhere",
|
||||||
|
"cc": "https://www.w3.org/ns/activitystreams#Public",
|
||||||
|
"attributedTo": "http://ltthostname.local:3334/apub/users/3",
|
||||||
|
"attachment": [
|
||||||
|
{
|
||||||
|
"type": "Image",
|
||||||
|
"url": "http://ltthostname.local:3334/api/stable/posts/46/href"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"sensitive": false,
|
||||||
|
"published": "2022-08-06T18:35:01.043072+00:00",
|
||||||
|
"summary": "image"
|
||||||
|
},
|
||||||
|
"to": "http://localhost:8536/c/elsewhere",
|
||||||
|
"cc": "https://www.w3.org/ns/activitystreams#Public",
|
||||||
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
|
"id": "http://ltthostname.local:3334/apub/posts/46/create",
|
||||||
|
"type": "Create"
|
||||||
|
}
|
|
@ -158,8 +158,11 @@ impl ApubObject for ApubPost {
|
||||||
|
|
||||||
let form = if !page.is_mod_action(context).await? {
|
let form = if !page.is_mod_action(context).await? {
|
||||||
let url = if let Some(attachment) = page.attachment.first() {
|
let url = if let Some(attachment) = page.attachment.first() {
|
||||||
// url as sent by Lemmy (new)
|
Some(match attachment {
|
||||||
Some(attachment.href.clone())
|
// url as sent by Lemmy (new)
|
||||||
|
Attachment::Link(link) => link.href.clone(),
|
||||||
|
Attachment::Image(image) => image.url.clone(),
|
||||||
|
})
|
||||||
} else if page.kind == PageType::Video {
|
} else if page.kind == PageType::Video {
|
||||||
// we cant display videos directly, so insert a link to external video page
|
// we cant display videos directly, so insert a link to external video page
|
||||||
Some(page.id.inner().clone())
|
Some(page.id.inner().clone())
|
||||||
|
|
|
@ -52,6 +52,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_lotide_activities() {
|
fn test_parse_lotide_activities() {
|
||||||
test_json::<CreateOrUpdatePost>("assets/lotide/activities/create_page.json").unwrap();
|
test_json::<CreateOrUpdatePost>("assets/lotide/activities/create_page.json").unwrap();
|
||||||
|
test_json::<CreateOrUpdatePost>("assets/lotide/activities/create_page_image.json").unwrap();
|
||||||
test_json::<CreateOrUpdateComment>("assets/lotide/activities/create_note_reply.json").unwrap();
|
test_json::<CreateOrUpdateComment>("assets/lotide/activities/create_note_reply.json").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use activitypub_federation::{
|
||||||
},
|
},
|
||||||
traits::{ActivityHandler, ApubObject},
|
traits::{ActivityHandler, ApubObject},
|
||||||
};
|
};
|
||||||
use activitystreams_kinds::link::LinkType;
|
use activitystreams_kinds::{link::LinkType, object::ImageType};
|
||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lemmy_db_schema::newtypes::DbUrl;
|
use lemmy_db_schema::newtypes::DbUrl;
|
||||||
|
@ -66,11 +66,26 @@ pub struct Page {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub(crate) struct Attachment {
|
pub(crate) struct Link {
|
||||||
pub(crate) href: Url,
|
pub(crate) href: Url,
|
||||||
pub(crate) r#type: LinkType,
|
pub(crate) r#type: LinkType,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub(crate) struct Image {
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub(crate) kind: ImageType,
|
||||||
|
pub(crate) url: Url,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub(crate) enum Attachment {
|
||||||
|
Link(Link),
|
||||||
|
Image(Image),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub(crate) enum AttributedTo {
|
pub(crate) enum AttributedTo {
|
||||||
|
@ -174,10 +189,10 @@ impl Page {
|
||||||
|
|
||||||
impl Attachment {
|
impl Attachment {
|
||||||
pub(crate) fn new(url: DbUrl) -> Attachment {
|
pub(crate) fn new(url: DbUrl) -> Attachment {
|
||||||
Attachment {
|
Attachment::Link(Link {
|
||||||
href: url.into(),
|
href: url.into(),
|
||||||
r#type: Default::default(),
|
r#type: Default::default(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue