Convert incoming questions and pages into posts

This commit is contained in:
silverpill 2022-04-29 13:15:16 +00:00
parent 1c2d87b729
commit 8755177eed
3 changed files with 15 additions and 4 deletions

View file

@ -55,6 +55,9 @@ pub struct Object {
#[serde(rename = "type")]
pub object_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub actor: Option<String>,

View file

@ -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<Uuid> = Vec::new();
if let Some(value) = object.attachment {
let list: Vec<Attachment> = 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,

View file

@ -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