--- /dev/null
+{
+ "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"
+}
let form = if !page.is_mod_action(context).await? {
let url = if let Some(attachment) = page.attachment.first() {
- // url as sent by Lemmy (new)
- Some(attachment.href.clone())
+ Some(match attachment {
+ // url as sent by Lemmy (new)
+ Attachment::Link(link) => link.href.clone(),
+ Attachment::Image(image) => image.url.clone(),
+ })
} else if page.kind == PageType::Video {
// we cant display videos directly, so insert a link to external video page
Some(page.id.inner().clone())
#[test]
fn test_parse_lotide_activities() {
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();
}
},
traits::{ActivityHandler, ApubObject},
};
-use activitystreams_kinds::link::LinkType;
+use activitystreams_kinds::{link::LinkType, object::ImageType};
use chrono::{DateTime, FixedOffset};
use itertools::Itertools;
use lemmy_db_schema::newtypes::DbUrl;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
-pub(crate) struct Attachment {
+pub(crate) struct Link {
pub(crate) href: Url,
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)]
#[serde(untagged)]
pub(crate) enum AttributedTo {
impl Attachment {
pub(crate) fn new(url: DbUrl) -> Attachment {
- Attachment {
+ Attachment::Link(Link {
href: url.into(),
r#type: Default::default(),
- }
+ })
}
}