mirror of https://github.com/LemmyNet/lemmy.git
Federate nsfw/locked info for posts
parent
b177cbce1d
commit
7485f1a5b4
|
@ -359,9 +359,9 @@ impl Perform for Oper<GetSite> {
|
||||||
let create_site = CreateSite {
|
let create_site = CreateSite {
|
||||||
name: setup.site_name.to_owned(),
|
name: setup.site_name.to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
enable_downvotes: false,
|
enable_downvotes: true,
|
||||||
open_registration: false,
|
open_registration: true,
|
||||||
enable_nsfw: false,
|
enable_nsfw: true,
|
||||||
auth: login_response.jwt,
|
auth: login_response.jwt,
|
||||||
};
|
};
|
||||||
Oper::new(create_site).perform(pool, websocket_info.clone())?;
|
Oper::new(create_site).perform(pool, websocket_info.clone())?;
|
||||||
|
|
|
@ -39,7 +39,7 @@ where
|
||||||
pub enum SearchAcceptedObjects {
|
pub enum SearchAcceptedObjects {
|
||||||
Person(Box<PersonExt>),
|
Person(Box<PersonExt>),
|
||||||
Group(Box<GroupExt>),
|
Group(Box<GroupExt>),
|
||||||
Page(Box<Page>),
|
Page(Box<PageExt>),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to parse the query as URL, and fetch an ActivityPub object from it.
|
/// Attempt to parse the query as URL, and fetch an ActivityPub object from it.
|
||||||
|
|
|
@ -3,6 +3,7 @@ pub mod comment;
|
||||||
pub mod community;
|
pub mod community;
|
||||||
pub mod community_inbox;
|
pub mod community_inbox;
|
||||||
pub mod fetcher;
|
pub mod fetcher;
|
||||||
|
pub mod page_extension;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod shared_inbox;
|
pub mod shared_inbox;
|
||||||
pub mod signatures;
|
pub mod signatures;
|
||||||
|
@ -65,7 +66,9 @@ use crate::websocket::{
|
||||||
};
|
};
|
||||||
use crate::{convert_datetime, naive_now, Settings};
|
use crate::{convert_datetime, naive_now, Settings};
|
||||||
|
|
||||||
|
use crate::apub::page_extension::PageExtension;
|
||||||
use activities::{populate_object_props, send_activity};
|
use activities::{populate_object_props, send_activity};
|
||||||
|
use activitystreams::Base;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user};
|
use fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user};
|
||||||
use signatures::verify;
|
use signatures::verify;
|
||||||
|
@ -73,6 +76,7 @@ use signatures::{sign, PublicKey, PublicKeyExtension};
|
||||||
|
|
||||||
type GroupExt = Ext<Ext<Group, ApActorProperties>, PublicKeyExtension>;
|
type GroupExt = Ext<Ext<Group, ApActorProperties>, PublicKeyExtension>;
|
||||||
type PersonExt = Ext<Ext<Person, ApActorProperties>, PublicKeyExtension>;
|
type PersonExt = Ext<Ext<Person, ApActorProperties>, PublicKeyExtension>;
|
||||||
|
type PageExt = Ext<Page, PageExtension>;
|
||||||
|
|
||||||
pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
|
pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct PageExtension {
|
||||||
|
pub comments_enabled: bool,
|
||||||
|
pub sensitive: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Extension<T> for PageExtension where T: Base {}
|
|
@ -20,10 +20,10 @@ pub async fn get_apub_post(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToApub for Post {
|
impl ToApub for Post {
|
||||||
type Response = Page;
|
type Response = PageExt;
|
||||||
|
|
||||||
// Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
|
// Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
|
||||||
fn to_apub(&self, conn: &PgConnection) -> Result<Page, Error> {
|
fn to_apub(&self, conn: &PgConnection) -> Result<PageExt, Error> {
|
||||||
let mut page = Page::default();
|
let mut page = Page::default();
|
||||||
let oprops: &mut ObjectProperties = page.as_mut();
|
let oprops: &mut ObjectProperties = page.as_mut();
|
||||||
let creator = User_::read(conn, self.creator_id)?;
|
let creator = User_::read(conn, self.creator_id)?;
|
||||||
|
@ -31,6 +31,8 @@ impl ToApub for Post {
|
||||||
|
|
||||||
oprops
|
oprops
|
||||||
// Not needed when the Post is embedded in a collection (like for community outbox)
|
// Not needed when the Post is embedded in a collection (like for community outbox)
|
||||||
|
// TODO: need to set proper context defining sensitive/commentsEnabled fields
|
||||||
|
// https://git.asonix.dog/Aardwolf/activitystreams/issues/5
|
||||||
.set_context_xsd_any_uri(context())?
|
.set_context_xsd_any_uri(context())?
|
||||||
.set_id(self.ap_id.to_owned())?
|
.set_id(self.ap_id.to_owned())?
|
||||||
// Use summary field to be consistent with mastodon content warning.
|
// Use summary field to be consistent with mastodon content warning.
|
||||||
|
@ -45,7 +47,7 @@ impl ToApub for Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: hacky code because we get self.url == Some("")
|
// TODO: hacky code because we get self.url == Some("")
|
||||||
// https://github.com/dessalines/lemmy/issues/602
|
// https://github.com/LemmyNet/lemmy/issues/602
|
||||||
let url = self.url.as_ref().filter(|u| !u.is_empty());
|
let url = self.url.as_ref().filter(|u| !u.is_empty());
|
||||||
if let Some(u) = url {
|
if let Some(u) = url {
|
||||||
oprops.set_url_xsd_any_uri(u.to_owned())?;
|
oprops.set_url_xsd_any_uri(u.to_owned())?;
|
||||||
|
@ -55,7 +57,11 @@ impl ToApub for Post {
|
||||||
oprops.set_updated(convert_datetime(u))?;
|
oprops.set_updated(convert_datetime(u))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(page)
|
let ext = PageExtension {
|
||||||
|
comments_enabled: !self.locked,
|
||||||
|
sensitive: self.nsfw,
|
||||||
|
};
|
||||||
|
Ok(page.extend(ext))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_tombstone(&self) -> Result<Tombstone, Error> {
|
fn to_tombstone(&self) -> Result<Tombstone, Error> {
|
||||||
|
@ -69,10 +75,12 @@ impl ToApub for Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromApub for PostForm {
|
impl FromApub for PostForm {
|
||||||
type ApubType = Page;
|
type ApubType = PageExt;
|
||||||
|
|
||||||
/// Parse an ActivityPub page received from another instance into a Lemmy post.
|
/// Parse an ActivityPub page received from another instance into a Lemmy post.
|
||||||
fn from_apub(page: &Page, conn: &PgConnection) -> Result<PostForm, Error> {
|
fn from_apub(page: &PageExt, conn: &PgConnection) -> Result<PostForm, Error> {
|
||||||
|
let ext = &page.extension;
|
||||||
|
let page = &page.base;
|
||||||
let oprops = &page.object_props;
|
let oprops = &page.object_props;
|
||||||
let creator_actor_id = &oprops.get_attributed_to_xsd_any_uri().unwrap().to_string();
|
let creator_actor_id = &oprops.get_attributed_to_xsd_any_uri().unwrap().to_string();
|
||||||
let creator = get_or_fetch_and_upsert_remote_user(&creator_actor_id, &conn)?;
|
let creator = get_or_fetch_and_upsert_remote_user(&creator_actor_id, &conn)?;
|
||||||
|
@ -85,18 +93,18 @@ impl FromApub for PostForm {
|
||||||
body: oprops.get_content_xsd_string().map(|c| c.to_string()),
|
body: oprops.get_content_xsd_string().map(|c| c.to_string()),
|
||||||
creator_id: creator.id,
|
creator_id: creator.id,
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
removed: None, // -> Delete activity / tombstone
|
removed: None,
|
||||||
locked: None, // -> commentsEnabled
|
locked: Some(!ext.comments_enabled),
|
||||||
published: oprops
|
published: oprops
|
||||||
.get_published()
|
.get_published()
|
||||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||||
updated: oprops
|
updated: oprops
|
||||||
.get_updated()
|
.get_updated()
|
||||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||||
deleted: None, // -> Delete activity / tombstone
|
deleted: None,
|
||||||
nsfw: false, // -> sensitive
|
nsfw: ext.sensitive,
|
||||||
stickied: None, // -> put it in "featured" collection of the community
|
stickied: None, // -> put it in "featured" collection of the community
|
||||||
embed_title: None, // -> attachment?
|
embed_title: None, // -> attachment? or fetch the embed locally
|
||||||
embed_description: None,
|
embed_description: None,
|
||||||
embed_html: None,
|
embed_html: None,
|
||||||
thumbnail_url: None,
|
thumbnail_url: None,
|
||||||
|
|
|
@ -110,7 +110,7 @@ fn receive_create_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Page>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = create
|
let user_uri = create
|
||||||
.create_props
|
.create_props
|
||||||
|
@ -213,7 +213,7 @@ fn receive_update_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Page>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = update
|
let user_uri = update
|
||||||
.update_props
|
.update_props
|
||||||
|
@ -263,7 +263,7 @@ fn receive_like_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Page>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ fn receive_dislike_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Page>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = dislike
|
let user_uri = dislike
|
||||||
.dislike_props
|
.dislike_props
|
||||||
|
@ -692,7 +692,7 @@ fn receive_delete_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Page>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user.public_key.unwrap())?;
|
||||||
|
@ -763,7 +763,7 @@ fn receive_remove_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Page>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||||
verify(request, &mod_.public_key.unwrap())?;
|
verify(request, &mod_.public_key.unwrap())?;
|
||||||
|
@ -1166,7 +1166,7 @@ fn receive_undo_delete_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Page>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
|
||||||
verify(request, &user.public_key.unwrap())?;
|
verify(request, &user.public_key.unwrap())?;
|
||||||
|
@ -1237,7 +1237,7 @@ fn receive_undo_remove_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Page>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
let mod_ = get_or_fetch_and_upsert_remote_user(&mod_uri, &conn)?;
|
||||||
verify(request, &mod_.public_key.unwrap())?;
|
verify(request, &mod_.public_key.unwrap())?;
|
||||||
|
@ -1526,7 +1526,7 @@ fn receive_undo_like_post(
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_concrete::<Page>()?;
|
.into_concrete::<PageExt>()?;
|
||||||
|
|
||||||
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
let user_uri = like.like_props.get_actor_xsd_any_uri().unwrap().to_string();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue