|
|
|
@ -6,6 +6,7 @@ use crate::{
|
|
|
|
|
create_tombstone,
|
|
|
|
|
extensions::page_extension::PageExtension,
|
|
|
|
|
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
|
|
|
|
get_apub_protocol_string,
|
|
|
|
|
ActorType,
|
|
|
|
|
ApubLikeableType,
|
|
|
|
|
ApubObjectType,
|
|
|
|
@ -22,11 +23,12 @@ use crate::{
|
|
|
|
|
Crud,
|
|
|
|
|
},
|
|
|
|
|
routes::DbPoolParam,
|
|
|
|
|
Settings,
|
|
|
|
|
};
|
|
|
|
|
use activitystreams::{
|
|
|
|
|
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
|
|
|
|
context,
|
|
|
|
|
object::{kind::PageType, properties::ObjectProperties, Page, Tombstone},
|
|
|
|
|
object::{kind::PageType, properties::ObjectProperties, AnyImage, Image, Page, Tombstone},
|
|
|
|
|
BaseBox,
|
|
|
|
|
};
|
|
|
|
|
use activitystreams_ext::Ext1;
|
|
|
|
@ -86,6 +88,46 @@ impl ToApub for Post {
|
|
|
|
|
let url = self.url.as_ref().filter(|u| !u.is_empty());
|
|
|
|
|
if let Some(u) = url {
|
|
|
|
|
oprops.set_url_xsd_any_uri(u.to_owned())?;
|
|
|
|
|
|
|
|
|
|
// Embeds
|
|
|
|
|
let mut page_preview = Page::new();
|
|
|
|
|
page_preview
|
|
|
|
|
.object_props
|
|
|
|
|
.set_url_xsd_any_uri(u.to_owned())?;
|
|
|
|
|
|
|
|
|
|
if let Some(embed_title) = &self.embed_title {
|
|
|
|
|
page_preview
|
|
|
|
|
.object_props
|
|
|
|
|
.set_name_xsd_string(embed_title.to_owned())?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(embed_description) = &self.embed_description {
|
|
|
|
|
page_preview
|
|
|
|
|
.object_props
|
|
|
|
|
.set_summary_xsd_string(embed_description.to_owned())?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(embed_html) = &self.embed_html {
|
|
|
|
|
page_preview
|
|
|
|
|
.object_props
|
|
|
|
|
.set_content_xsd_string(embed_html.to_owned())?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oprops.set_preview_base_box(page_preview)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(thumbnail_url) = &self.thumbnail_url {
|
|
|
|
|
let full_url = format!(
|
|
|
|
|
"{}://{}/pictshare/{}",
|
|
|
|
|
get_apub_protocol_string(),
|
|
|
|
|
Settings::get().hostname,
|
|
|
|
|
thumbnail_url
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let mut image = Image::new();
|
|
|
|
|
image.object_props.set_url_xsd_any_uri(full_url)?;
|
|
|
|
|
let any_image = AnyImage::from_concrete(image)?;
|
|
|
|
|
oprops.set_image_any_image(any_image)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(u) = self.updated {
|
|
|
|
@ -121,9 +163,40 @@ impl FromApub for PostForm {
|
|
|
|
|
let community_actor_id = &oprops.get_to_xsd_any_uri().unwrap().to_string();
|
|
|
|
|
let community = get_or_fetch_and_upsert_remote_community(&community_actor_id, &conn)?;
|
|
|
|
|
|
|
|
|
|
let thumbnail_url = match oprops.get_image_any_image() {
|
|
|
|
|
Some(any_image) => any_image
|
|
|
|
|
.to_owned()
|
|
|
|
|
.into_concrete::<Image>()?
|
|
|
|
|
.object_props
|
|
|
|
|
.get_url_xsd_any_uri()
|
|
|
|
|
.map(|u| u.to_string()),
|
|
|
|
|
None => None,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let url = oprops.get_url_xsd_any_uri().map(|u| u.to_string());
|
|
|
|
|
let (embed_title, embed_description, embed_html) = match oprops.get_preview_base_box() {
|
|
|
|
|
Some(preview) => {
|
|
|
|
|
let preview_page = preview.to_owned().into_concrete::<Page>()?;
|
|
|
|
|
let name = preview_page
|
|
|
|
|
.object_props
|
|
|
|
|
.get_name_xsd_string()
|
|
|
|
|
.map(|n| n.to_string());
|
|
|
|
|
let summary = preview_page
|
|
|
|
|
.object_props
|
|
|
|
|
.get_summary_xsd_string()
|
|
|
|
|
.map(|s| s.to_string());
|
|
|
|
|
let content = preview_page
|
|
|
|
|
.object_props
|
|
|
|
|
.get_content_xsd_string()
|
|
|
|
|
.map(|c| c.to_string());
|
|
|
|
|
(name, summary, content)
|
|
|
|
|
}
|
|
|
|
|
None => (None, None, None),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Ok(PostForm {
|
|
|
|
|
name: oprops.get_summary_xsd_string().unwrap().to_string(),
|
|
|
|
|
url: oprops.get_url_xsd_any_uri().map(|u| u.to_string()),
|
|
|
|
|
url,
|
|
|
|
|
body: oprops.get_content_xsd_string().map(|c| c.to_string()),
|
|
|
|
|
creator_id: creator.id,
|
|
|
|
|
community_id: community.id,
|
|
|
|
@ -137,11 +210,11 @@ impl FromApub for PostForm {
|
|
|
|
|
.map(|u| u.as_ref().to_owned().naive_local()),
|
|
|
|
|
deleted: None,
|
|
|
|
|
nsfw: ext.sensitive,
|
|
|
|
|
stickied: None, // -> put it in "featured" collection of the community
|
|
|
|
|
embed_title: None, // -> attachment? or fetch the embed locally
|
|
|
|
|
embed_description: None,
|
|
|
|
|
embed_html: None,
|
|
|
|
|
thumbnail_url: None,
|
|
|
|
|
stickied: None, // -> put it in "featured" collection of the community
|
|
|
|
|
embed_title,
|
|
|
|
|
embed_description,
|
|
|
|
|
embed_html,
|
|
|
|
|
thumbnail_url,
|
|
|
|
|
ap_id: oprops.get_id().unwrap().to_string(),
|
|
|
|
|
local: false,
|
|
|
|
|
})
|
|
|
|
|