Merge remote-tracking branch 'yerba/main' into main

pull/1285/head
Dessalines 2020-11-27 15:58:22 -05:00
commit 5e10cf69b7
17 changed files with 83 additions and 55 deletions

4
Cargo.lock generated
View File

@ -2,9 +2,9 @@
# It is not intended for manual editing.
[[package]]
name = "activitystreams"
version = "0.7.0-alpha.6"
version = "0.7.0-alpha.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b1afe32371e466a791ced0d6ef6e6b97822bb1a279ee4cc41c4324e61cd0b2b"
checksum = "5e9fedbe571e267d9b93d071bdc4493f944022c6cce717ebb27d352026fc81c4"
dependencies = [
"chrono",
"mime",

View File

@ -1,7 +1,7 @@
#!/bin/bash
set -e
sudo docker build ../../ --file ../dev/Dockerfile -t lemmy-federation:latest
sudo docker build ../../ --file ../dev/volume_mount.dockerfile -t lemmy-federation:latest
for Item in alpha beta gamma delta epsilon ; do
sudo mkdir -p volumes/pictrs_$Item

View File

@ -14,7 +14,7 @@ lemmy_db = { path = "../lemmy_db" }
lemmy_structs = { path = "../lemmy_structs" }
lemmy_websocket = { path = "../lemmy_websocket" }
diesel = "1.4"
activitystreams = "0.7.0-alpha.6"
activitystreams = "0.7.0-alpha.7"
activitystreams-ext = "0.1.0-alpha.2"
bcrypt = "0.8"
chrono = { version = "0.4", features = ["serde"] }

View File

@ -1,6 +1,7 @@
use crate::{
activities::send::generate_activity_id,
activity_queue::{send_comment_mentions, send_to_community},
extensions::context::lemmy_context,
fetcher::get_or_fetch_and_upsert_user,
ActorType,
ApubLikeableType,
@ -62,7 +63,7 @@ impl ApubObjectType for Comment {
let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
create
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(CreateType::Create)?)
.set_to(public())
.set_many_ccs(ccs)
@ -95,7 +96,7 @@ impl ApubObjectType for Comment {
let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
update
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
.set_many_ccs(ccs)
@ -119,7 +120,7 @@ impl ApubObjectType for Comment {
let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
delete
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -145,7 +146,7 @@ impl ApubObjectType for Comment {
// Generate a fake delete activity, with the correct object
let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
delete
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -153,7 +154,7 @@ impl ApubObjectType for Comment {
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -174,7 +175,7 @@ impl ApubObjectType for Comment {
let mut remove = Remove::new(mod_.actor_id.to_owned(), Url::parse(&self.ap_id)?);
remove
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -196,7 +197,7 @@ impl ApubObjectType for Comment {
// Generate a fake delete activity, with the correct object
let mut remove = Remove::new(mod_.actor_id.to_owned(), Url::parse(&self.ap_id)?);
remove
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -204,7 +205,7 @@ impl ApubObjectType for Comment {
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -230,7 +231,7 @@ impl ApubLikeableType for Comment {
let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?);
like
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -253,7 +254,7 @@ impl ApubLikeableType for Comment {
let mut dislike = Dislike::new(creator.actor_id.to_owned(), note.into_any_base()?);
dislike
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -280,7 +281,7 @@ impl ApubLikeableType for Comment {
let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?);
like
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -288,7 +289,7 @@ impl ApubLikeableType for Comment {
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);

View File

@ -2,6 +2,7 @@ use crate::{
activities::send::generate_activity_id,
activity_queue::{send_activity_single_dest, send_to_community_followers},
check_is_apub_id_valid,
extensions::context::lemmy_context,
fetcher::get_or_fetch_and_upsert_user,
ActorType,
};
@ -71,7 +72,7 @@ impl ActorType for Community {
let mut accept = Accept::new(self.actor_id.to_owned(), follow.into_any_base()?);
accept
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(AcceptType::Accept)?)
.set_to(user.actor_id()?);
@ -83,7 +84,7 @@ impl ActorType for Community {
async fn send_delete(&self, context: &LemmyContext) -> Result<(), LemmyError> {
let mut delete = Delete::new(self.actor_id()?, self.actor_id()?);
delete
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]);
@ -96,14 +97,14 @@ impl ActorType for Community {
async fn send_undo_delete(&self, context: &LemmyContext) -> Result<(), LemmyError> {
let mut delete = Delete::new(self.actor_id()?, self.actor_id()?);
delete
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]);
let mut undo = Undo::new(self.actor_id()?, delete.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]);
@ -116,7 +117,7 @@ impl ActorType for Community {
async fn send_remove(&self, context: &LemmyContext) -> Result<(), LemmyError> {
let mut remove = Remove::new(self.actor_id()?, self.actor_id()?);
remove
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]);
@ -129,7 +130,7 @@ impl ActorType for Community {
async fn send_undo_remove(&self, context: &LemmyContext) -> Result<(), LemmyError> {
let mut remove = Remove::new(self.actor_id()?, self.actor_id()?);
remove
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]);
@ -137,7 +138,7 @@ impl ActorType for Community {
// Undo that fake activity
let mut undo = Undo::new(self.actor_id()?, remove.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]);
@ -155,7 +156,7 @@ impl ActorType for Community {
) -> Result<(), LemmyError> {
let mut announce = Announce::new(self.actor_id.to_owned(), activity);
announce
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(AnnounceType::Announce)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]);

View File

@ -1,6 +1,7 @@
use crate::{
activities::send::generate_activity_id,
activity_queue::send_to_community,
extensions::context::lemmy_context,
ActorType,
ApubLikeableType,
ApubObjectType,
@ -40,7 +41,7 @@ impl ApubObjectType for Post {
let mut create = Create::new(creator.actor_id.to_owned(), page.into_any_base()?);
create
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(CreateType::Create)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -61,7 +62,7 @@ impl ApubObjectType for Post {
let mut update = Update::new(creator.actor_id.to_owned(), page.into_any_base()?);
update
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -79,7 +80,7 @@ impl ApubObjectType for Post {
let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
delete
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -101,7 +102,7 @@ impl ApubObjectType for Post {
let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
delete
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -109,7 +110,7 @@ impl ApubObjectType for Post {
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -127,7 +128,7 @@ impl ApubObjectType for Post {
let mut remove = Remove::new(mod_.actor_id.to_owned(), Url::parse(&self.ap_id)?);
remove
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -145,7 +146,7 @@ impl ApubObjectType for Post {
let mut remove = Remove::new(mod_.actor_id.to_owned(), Url::parse(&self.ap_id)?);
remove
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -153,7 +154,7 @@ impl ApubObjectType for Post {
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -176,7 +177,7 @@ impl ApubLikeableType for Post {
let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?);
like
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -196,7 +197,7 @@ impl ApubLikeableType for Post {
let mut dislike = Dislike::new(creator.actor_id.to_owned(), page.into_any_base()?);
dislike
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -220,7 +221,7 @@ impl ApubLikeableType for Post {
let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?);
like
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);
@ -228,7 +229,7 @@ impl ApubLikeableType for Post {
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()?]);

View File

@ -1,6 +1,7 @@
use crate::{
activities::send::generate_activity_id,
activity_queue::send_activity_single_dest,
extensions::context::lemmy_context,
ActorType,
ApubObjectType,
ToApub,
@ -33,7 +34,7 @@ impl ApubObjectType for PrivateMessage {
let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
create
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(CreateType::Create)?)
.set_to(recipient.actor_id()?);
@ -50,7 +51,7 @@ impl ApubObjectType for PrivateMessage {
let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
update
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(recipient.actor_id()?);
@ -64,7 +65,7 @@ impl ApubObjectType for PrivateMessage {
let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
delete
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(recipient.actor_id()?);
@ -82,14 +83,14 @@ impl ApubObjectType for PrivateMessage {
let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
delete
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(recipient.actor_id()?);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(recipient.actor_id()?);

View File

@ -1,6 +1,7 @@
use crate::{
activities::send::generate_activity_id,
activity_queue::send_activity_single_dest,
extensions::context::lemmy_context,
ActorType,
};
use activitystreams::{
@ -61,7 +62,7 @@ impl ActorType for User_ {
let mut follow = Follow::new(self.actor_id.to_owned(), community.actor_id()?);
follow
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(FollowType::Follow)?)
.set_to(community.actor_id()?);
@ -82,14 +83,14 @@ impl ActorType for User_ {
let mut follow = Follow::new(self.actor_id.to_owned(), community.actor_id()?);
follow
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(FollowType::Follow)?)
.set_to(community.actor_id()?);
// Undo that fake activity
let mut undo = Undo::new(Url::parse(&self.actor_id)?, follow.into_any_base()?);
undo
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(community.actor_id()?);

View File

@ -0,0 +1,18 @@
use activitystreams::{base::AnyBase, context};
use lemmy_utils::LemmyError;
use serde_json::json;
pub(crate) fn lemmy_context() -> Result<Vec<AnyBase>, LemmyError> {
let context_ext = AnyBase::from_arbitrary_json(json!(
{
"sc": "http://schema.org#",
"category": "sc:category",
"sensitive": "as:sensitive",
"stickied": "as:stickied",
"comments_enabled": {
"kind": "sc:Boolean",
"id": "pt:commentsEnabled"
}
}))?;
Ok(vec![AnyBase::from(context()), context_ext])
}

View File

@ -1,3 +1,4 @@
pub(crate) mod context;
pub(crate) mod group_extensions;
pub(crate) mod page_extension;
pub(crate) mod signatures;

View File

@ -1,4 +1,5 @@
use crate::{
extensions::context::lemmy_context,
http::{create_apub_response, create_apub_tombstone_response},
ActorType,
ToApub,
@ -56,7 +57,7 @@ pub async fn get_apub_community_followers(
let mut collection = UnorderedCollection::new();
collection
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(community.get_followers_url()?)
.set_total_items(community_followers.len() as u64);
Ok(create_apub_response(&collection))
@ -88,7 +89,7 @@ pub async fn get_apub_community_outbox(
let mut collection = OrderedCollection::new();
collection
.set_many_items(pages)
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(community.get_outbox_url()?)
.set_total_items(len as u64);
Ok(create_apub_response(&collection))

View File

@ -1,4 +1,4 @@
use crate::{http::create_apub_response, ActorType, ToApub};
use crate::{extensions::context::lemmy_context, http::create_apub_response, ActorType, ToApub};
use activitystreams::{
base::BaseExt,
collection::{CollectionExt, OrderedCollection},
@ -42,7 +42,7 @@ pub async fn get_apub_user_outbox(
let mut collection = OrderedCollection::new();
collection
.set_many_items(Vec::<Url>::new())
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(user.get_outbox_url()?)
.set_total_items(0_u64);
Ok(create_apub_response(&collection))

View File

@ -1,4 +1,5 @@
use crate::{
extensions::context::lemmy_context,
fetcher::{
get_or_fetch_and_insert_comment,
get_or_fetch_and_insert_post,
@ -64,7 +65,7 @@ impl ToApub for Comment {
comment
// Not needed when the Post is embedded in a collection (like for community outbox)
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(Url::parse(&self.ap_id)?)
.set_published(convert_datetime(self.published))
.set_to(community.actor_id)

View File

@ -1,5 +1,5 @@
use crate::{
extensions::group_extensions::GroupExtension,
extensions::{context::lemmy_context, group_extensions::GroupExtension},
fetcher::get_or_fetch_and_upsert_user,
objects::{
check_object_domain,
@ -53,7 +53,7 @@ impl ToApub for Community {
let mut group = ApObject::new(Group::new());
group
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(Url::parse(&self.actor_id)?)
.set_name(self.title.to_owned())
.set_published(convert_datetime(self.published))

View File

@ -1,5 +1,5 @@
use crate::{
extensions::page_extension::PageExtension,
extensions::{context::lemmy_context, page_extension::PageExtension},
fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
objects::{
check_object_domain,
@ -52,7 +52,7 @@ impl ToApub for Post {
// 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(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(self.ap_id.parse::<Url>()?)
// Use summary field to be consistent with mastodon content warning.
// https://mastodon.xyz/@Louisa/103987265222901387.json

View File

@ -1,5 +1,6 @@
use crate::{
check_is_apub_id_valid,
extensions::context::lemmy_context,
fetcher::get_or_fetch_and_upsert_user,
objects::{
check_object_domain,
@ -41,7 +42,7 @@ impl ToApub for PrivateMessage {
let recipient = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??;
private_message
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(Url::parse(&self.ap_id.to_owned())?)
.set_published(convert_datetime(self.published))
.set_to(recipient.actor_id)

View File

@ -1,4 +1,5 @@
use crate::{
extensions::context::lemmy_context,
objects::{check_object_domain, get_source_markdown_value, set_content_and_source},
ActorType,
FromApub,
@ -32,7 +33,7 @@ impl ToApub for User_ {
async fn to_apub(&self, _pool: &DbPool) -> Result<PersonExt, LemmyError> {
let mut person = ApObject::new(Person::new());
person
.set_context(activitystreams::context())
.set_many_contexts(lemmy_context()?)
.set_id(Url::parse(&self.actor_id)?)
.set_published(convert_datetime(self.published));