};
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;
.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> {
/// 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;
// 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
.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,
--- /dev/null
+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 {}
--- /dev/null
+pub mod group_extensions;
+pub mod page_extension;
+pub mod signatures;
-use super::*;
+use activitystreams::ext::Extension;
+use activitystreams::Base;
+use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
-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();
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)?;
// Also add the community moderators too
let creator_and_moderator_uris = group
+ .base
.base
.base
.object_props
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;
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,
};
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;
};
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>;
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;