From 8755177eed16552b02aae3f3725ee3398696804c Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 29 Apr 2022 13:15:16 +0000 Subject: [PATCH] Convert incoming questions and pages into posts --- src/activitypub/activity.rs | 3 +++ src/activitypub/receiver.rs | 14 ++++++++++---- src/activitypub/vocabulary.rs | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/activitypub/activity.rs b/src/activitypub/activity.rs index 624a8a0..814482f 100644 --- a/src/activitypub/activity.rs +++ b/src/activitypub/activity.rs @@ -55,6 +55,9 @@ pub struct Object { #[serde(rename = "type")] pub object_type: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub actor: Option, diff --git a/src/activitypub/receiver.rs b/src/activitypub/receiver.rs index dadcb4d..fb570a4 100644 --- a/src/activitypub/receiver.rs +++ b/src/activitypub/receiver.rs @@ -259,9 +259,15 @@ pub async fn import_post( &config.media_dir(), &author_id, ).await?; - let content = object.content - .ok_or(ValidationError("no content"))?; + + let content = if object.object_type == PAGE { + // Lemmy Page + object.name.ok_or(ValidationError("no content"))? + } else { + object.content.ok_or(ValidationError("no content"))? + }; let content_cleaned = clean_note_content(&content)?; + let mut attachments: Vec = Vec::new(); if let Some(value) = object.attachment { let list: Vec = parse_property_value(&value) @@ -512,7 +518,7 @@ pub async fn receive_activity( follow_request_rejected(db_client, &follow_request_id).await?; FOLLOW }, - (CREATE, NOTE) => { + (CREATE, NOTE | QUESTION | PAGE) => { let object: Object = serde_json::from_value(activity.object) .map_err(|_| ValidationError("invalid object"))?; let object_id = object.id.clone(); @@ -581,7 +587,7 @@ pub async fn receive_activity( }); NOTE }, - (LIKE, _) | (EMOJI_REACT, _) => { + (EMOJI_REACT | LIKE, _) => { require_actor_signature(&activity.actor, &signer_id)?; let author = get_or_import_profile_by_actor_id( db_client, diff --git a/src/activitypub/vocabulary.rs b/src/activitypub/vocabulary.rs index 23af9a2..2cd1295 100644 --- a/src/activitypub/vocabulary.rs +++ b/src/activitypub/vocabulary.rs @@ -8,6 +8,7 @@ pub const DELETE: &str = "Delete"; pub const EMOJI_REACT: &str = "EmojiReact"; pub const FOLLOW: &str = "Follow"; pub const LIKE: &str = "Like"; +pub const QUESTION: &str = "Question"; pub const REJECT: &str = "Reject"; pub const UNDO: &str = "Undo"; pub const UPDATE: &str = "Update"; @@ -21,6 +22,7 @@ pub const DOCUMENT: &str = "Document"; pub const IMAGE: &str = "Image"; pub const MENTION: &str = "Mention"; pub const NOTE: &str = "Note"; +pub const PAGE: &str = "Page"; pub const TOMBSTONE: &str = "Tombstone"; // Collections