Convert incoming questions and pages into posts
This commit is contained in:
parent
1c2d87b729
commit
8755177eed
3 changed files with 15 additions and 4 deletions
|
@ -55,6 +55,9 @@ pub struct Object {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub object_type: String,
|
pub object_type: String,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub name: Option<String>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub actor: Option<String>,
|
pub actor: Option<String>,
|
||||||
|
|
||||||
|
|
|
@ -259,9 +259,15 @@ pub async fn import_post(
|
||||||
&config.media_dir(),
|
&config.media_dir(),
|
||||||
&author_id,
|
&author_id,
|
||||||
).await?;
|
).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 content_cleaned = clean_note_content(&content)?;
|
||||||
|
|
||||||
let mut attachments: Vec<Uuid> = Vec::new();
|
let mut attachments: Vec<Uuid> = Vec::new();
|
||||||
if let Some(value) = object.attachment {
|
if let Some(value) = object.attachment {
|
||||||
let list: Vec<Attachment> = parse_property_value(&value)
|
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_request_rejected(db_client, &follow_request_id).await?;
|
||||||
FOLLOW
|
FOLLOW
|
||||||
},
|
},
|
||||||
(CREATE, NOTE) => {
|
(CREATE, NOTE | QUESTION | PAGE) => {
|
||||||
let object: Object = serde_json::from_value(activity.object)
|
let object: Object = serde_json::from_value(activity.object)
|
||||||
.map_err(|_| ValidationError("invalid object"))?;
|
.map_err(|_| ValidationError("invalid object"))?;
|
||||||
let object_id = object.id.clone();
|
let object_id = object.id.clone();
|
||||||
|
@ -581,7 +587,7 @@ pub async fn receive_activity(
|
||||||
});
|
});
|
||||||
NOTE
|
NOTE
|
||||||
},
|
},
|
||||||
(LIKE, _) | (EMOJI_REACT, _) => {
|
(EMOJI_REACT | LIKE, _) => {
|
||||||
require_actor_signature(&activity.actor, &signer_id)?;
|
require_actor_signature(&activity.actor, &signer_id)?;
|
||||||
let author = get_or_import_profile_by_actor_id(
|
let author = get_or_import_profile_by_actor_id(
|
||||||
db_client,
|
db_client,
|
||||||
|
|
|
@ -8,6 +8,7 @@ pub const DELETE: &str = "Delete";
|
||||||
pub const EMOJI_REACT: &str = "EmojiReact";
|
pub const EMOJI_REACT: &str = "EmojiReact";
|
||||||
pub const FOLLOW: &str = "Follow";
|
pub const FOLLOW: &str = "Follow";
|
||||||
pub const LIKE: &str = "Like";
|
pub const LIKE: &str = "Like";
|
||||||
|
pub const QUESTION: &str = "Question";
|
||||||
pub const REJECT: &str = "Reject";
|
pub const REJECT: &str = "Reject";
|
||||||
pub const UNDO: &str = "Undo";
|
pub const UNDO: &str = "Undo";
|
||||||
pub const UPDATE: &str = "Update";
|
pub const UPDATE: &str = "Update";
|
||||||
|
@ -21,6 +22,7 @@ pub const DOCUMENT: &str = "Document";
|
||||||
pub const IMAGE: &str = "Image";
|
pub const IMAGE: &str = "Image";
|
||||||
pub const MENTION: &str = "Mention";
|
pub const MENTION: &str = "Mention";
|
||||||
pub const NOTE: &str = "Note";
|
pub const NOTE: &str = "Note";
|
||||||
|
pub const PAGE: &str = "Page";
|
||||||
pub const TOMBSTONE: &str = "Tombstone";
|
pub const TOMBSTONE: &str = "Tombstone";
|
||||||
|
|
||||||
// Collections
|
// Collections
|
||||||
|
|
Loading…
Reference in a new issue