mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-27 11:51:08 +00:00
Federate community category and nsfw
This commit is contained in:
parent
21407260a4
commit
dfd6629a6f
9 changed files with 84 additions and 24 deletions
|
@ -23,8 +23,8 @@ use crate::{
|
|||
};
|
||||
|
||||
use crate::apub::{
|
||||
extensions::signatures::generate_actor_keypair,
|
||||
fetcher::search_by_apub_id,
|
||||
signatures::generate_actor_keypair,
|
||||
{make_apub_endpoint, ActorType, ApubLikeableType, ApubObjectType, EndpointType},
|
||||
};
|
||||
use crate::settings::Settings;
|
||||
|
|
|
@ -51,7 +51,14 @@ impl ToApub for Community {
|
|||
.set_endpoints(endpoint_props)?
|
||||
.set_followers(self.get_followers_url())?;
|
||||
|
||||
Ok(group.extend(actor_props).extend(self.get_public_key_ext()))
|
||||
let group_extension = GroupExtension::new(conn, self.category_id, self.nsfw)?;
|
||||
|
||||
Ok(
|
||||
group
|
||||
.extend(group_extension)
|
||||
.extend(actor_props)
|
||||
.extend(self.get_public_key_ext()),
|
||||
)
|
||||
}
|
||||
|
||||
fn to_tombstone(&self) -> Result<Tombstone, Error> {
|
||||
|
@ -304,7 +311,8 @@ impl FromApub for CommunityForm {
|
|||
|
||||
/// Parse an ActivityPub group received from another instance into a Lemmy community.
|
||||
fn from_apub(group: &GroupExt, conn: &PgConnection) -> Result<Self, Error> {
|
||||
let oprops = &group.base.base.object_props;
|
||||
let group_extensions: &GroupExtension = &group.base.base.extension;
|
||||
let oprops = &group.base.base.base.object_props;
|
||||
let aprops = &group.base.extension;
|
||||
let public_key: &PublicKey = &group.extension.public_key;
|
||||
|
||||
|
@ -325,7 +333,7 @@ impl FromApub for CommunityForm {
|
|||
// TODO: should be parsed as html and tags like <script> removed (or use markdown source)
|
||||
// -> same for post.content etc
|
||||
description: oprops.get_content_xsd_string().map(|s| s.to_string()),
|
||||
category_id: 1, // -> peertube uses `"category": {"identifier": "9","name": "Comedy"},`
|
||||
category_id: group_extensions.category.identifier.parse::<i32>()?,
|
||||
creator_id: creator.id,
|
||||
removed: None,
|
||||
published: oprops
|
||||
|
@ -335,7 +343,7 @@ impl FromApub for CommunityForm {
|
|||
.get_updated()
|
||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||
deleted: None,
|
||||
nsfw: false,
|
||||
nsfw: group_extensions.sensitive,
|
||||
actor_id: oprops.get_id().unwrap().to_string(),
|
||||
local: false,
|
||||
private_key: None,
|
||||
|
|
42
server/src/apub/extensions/group_extensions.rs
Normal file
42
server/src/apub/extensions/group_extensions.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use crate::db::category::Category;
|
||||
use crate::db::Crud;
|
||||
use activitystreams::ext::Extension;
|
||||
use activitystreams::Actor;
|
||||
use diesel::PgConnection;
|
||||
use failure::Error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GroupExtension {
|
||||
pub category: GroupCategory,
|
||||
pub sensitive: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GroupCategory {
|
||||
// Using a string because that's how Peertube does it.
|
||||
pub identifier: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl GroupExtension {
|
||||
pub fn new(
|
||||
conn: &PgConnection,
|
||||
category_id: i32,
|
||||
sensitive: bool,
|
||||
) -> Result<GroupExtension, Error> {
|
||||
let category = Category::read(conn, category_id)?;
|
||||
let group_category = GroupCategory {
|
||||
identifier: category_id.to_string(),
|
||||
name: category.name,
|
||||
};
|
||||
Ok(GroupExtension {
|
||||
category: group_category,
|
||||
sensitive,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Extension<T> for GroupExtension where T: Actor {}
|
3
server/src/apub/extensions/mod.rs
Normal file
3
server/src/apub/extensions/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub mod group_extensions;
|
||||
pub mod page_extension;
|
||||
pub mod signatures;
|
|
@ -1,4 +1,6 @@
|
|||
use super::*;
|
||||
use activitystreams::ext::Extension;
|
||||
use activitystreams::Base;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
|
@ -1,4 +1,15 @@
|
|||
use super::*;
|
||||
use activitystreams::ext::Extension;
|
||||
use activitystreams::Actor;
|
||||
use actix_web::HttpRequest;
|
||||
use failure::Error;
|
||||
use http::request::Builder;
|
||||
use http_signature_normalization::Config;
|
||||
use log::debug;
|
||||
use openssl::hash::MessageDigest;
|
||||
use openssl::sign::{Signer, Verifier};
|
||||
use openssl::{pkey::PKey, rsa::Rsa};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
lazy_static! {
|
||||
static ref HTTP_SIG_CONFIG: Config = Config::new();
|
|
@ -89,7 +89,7 @@ pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result<SearchRespo
|
|||
response.users = vec![UserView::read(conn, user.id)?];
|
||||
}
|
||||
SearchAcceptedObjects::Group(g) => {
|
||||
let community_uri = g.base.base.object_props.get_id().unwrap().to_string();
|
||||
let community_uri = g.base.base.base.object_props.get_id().unwrap().to_string();
|
||||
let community = get_or_fetch_and_upsert_remote_community(&community_uri, &conn)?;
|
||||
// TODO Maybe at some point in the future, fetch all the history of a community
|
||||
// fetch_community_outbox(&c, conn)?;
|
||||
|
@ -165,6 +165,7 @@ pub fn get_or_fetch_and_upsert_remote_community(
|
|||
|
||||
// Also add the community moderators too
|
||||
let creator_and_moderator_uris = group
|
||||
.base
|
||||
.base
|
||||
.base
|
||||
.object_props
|
||||
|
|
|
@ -2,11 +2,10 @@ pub mod activities;
|
|||
pub mod comment;
|
||||
pub mod community;
|
||||
pub mod community_inbox;
|
||||
pub mod extensions;
|
||||
pub mod fetcher;
|
||||
pub mod page_extension;
|
||||
pub mod post;
|
||||
pub mod shared_inbox;
|
||||
pub mod signatures;
|
||||
pub mod user;
|
||||
pub mod user_inbox;
|
||||
|
||||
|
@ -15,11 +14,11 @@ use crate::websocket::server::SendCommunityRoomMessage;
|
|||
use activitystreams::object::kind::{NoteType, PageType};
|
||||
use activitystreams::{
|
||||
activity::{Accept, Create, Delete, Dislike, Follow, Like, Remove, Undo, Update},
|
||||
actor::{kind::GroupType, properties::ApActorProperties, Actor, Group, Person},
|
||||
actor::{kind::GroupType, properties::ApActorProperties, Group, Person},
|
||||
collection::UnorderedCollection,
|
||||
context,
|
||||
endpoint::EndpointProperties,
|
||||
ext::{Ext, Extensible, Extension},
|
||||
ext::{Ext, Extensible},
|
||||
object::{properties::ObjectProperties, Note, Page, Tombstone},
|
||||
public, BaseBox,
|
||||
};
|
||||
|
@ -30,16 +29,10 @@ use diesel::result::Error::NotFound;
|
|||
use diesel::PgConnection;
|
||||
use failure::Error;
|
||||
use failure::_core::fmt::Debug;
|
||||
use http::request::Builder;
|
||||
use http_signature_normalization::Config;
|
||||
use isahc::prelude::*;
|
||||
use itertools::Itertools;
|
||||
use log::debug;
|
||||
use openssl::hash::MessageDigest;
|
||||
use openssl::sign::{Signer, Verifier};
|
||||
use openssl::{pkey::PKey, rsa::Rsa};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use std::time::Duration;
|
||||
use url::Url;
|
||||
|
||||
|
@ -66,15 +59,15 @@ use crate::websocket::{
|
|||
};
|
||||
use crate::{convert_datetime, naive_now, Settings};
|
||||
|
||||
use crate::apub::page_extension::PageExtension;
|
||||
use crate::apub::extensions::group_extensions::GroupExtension;
|
||||
use crate::apub::extensions::page_extension::PageExtension;
|
||||
use activities::{populate_object_props, send_activity};
|
||||
use activitystreams::Base;
|
||||
use chrono::NaiveDateTime;
|
||||
use extensions::signatures::verify;
|
||||
use extensions::signatures::{sign, PublicKey, PublicKeyExtension};
|
||||
use fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user};
|
||||
use signatures::verify;
|
||||
use signatures::{sign, PublicKey, PublicKeyExtension};
|
||||
|
||||
type GroupExt = Ext<Ext<Group, ApActorProperties>, PublicKeyExtension>;
|
||||
type GroupExt = Ext<Ext<Ext<Group, GroupExtension>, ApActorProperties>, PublicKeyExtension>;
|
||||
type PersonExt = Ext<Ext<Person, ApActorProperties>, PublicKeyExtension>;
|
||||
type PageExt = Ext<Page, PageExtension>;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use super::community::{Community, CommunityForm};
|
|||
use super::post::Post;
|
||||
use super::user::{UserForm, User_};
|
||||
use super::*;
|
||||
use crate::apub::signatures::generate_actor_keypair;
|
||||
use crate::apub::extensions::signatures::generate_actor_keypair;
|
||||
use crate::apub::{make_apub_endpoint, EndpointType};
|
||||
use crate::naive_now;
|
||||
use failure::Error;
|
||||
|
|
Loading…
Reference in a new issue