Set valid context for our extra fields (ref #1220)

This commit is contained in:
Felix Ableitner 2020-11-25 18:44:49 +01:00
parent b2288fcb9a
commit a7b72ed5c4
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. # It is not intended for manual editing.
[[package]] [[package]]
name = "activitystreams" name = "activitystreams"
version = "0.7.0-alpha.6" version = "0.7.0-alpha.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b1afe32371e466a791ced0d6ef6e6b97822bb1a279ee4cc41c4324e61cd0b2b" checksum = "5e9fedbe571e267d9b93d071bdc4493f944022c6cce717ebb27d352026fc81c4"
dependencies = [ dependencies = [
"chrono", "chrono",
"mime", "mime",

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
set -e 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 for Item in alpha beta gamma delta epsilon ; do
sudo mkdir -p volumes/pictrs_$Item sudo mkdir -p volumes/pictrs_$Item

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,5 @@
use crate::{ use crate::{
extensions::context::lemmy_context,
http::{create_apub_response, create_apub_tombstone_response}, http::{create_apub_response, create_apub_tombstone_response},
ActorType, ActorType,
ToApub, ToApub,
@ -56,7 +57,7 @@ pub async fn get_apub_community_followers(
let mut collection = UnorderedCollection::new(); let mut collection = UnorderedCollection::new();
collection collection
.set_context(activitystreams::context()) .set_many_contexts(lemmy_context()?)
.set_id(community.get_followers_url()?) .set_id(community.get_followers_url()?)
.set_total_items(community_followers.len() as u64); .set_total_items(community_followers.len() as u64);
Ok(create_apub_response(&collection)) Ok(create_apub_response(&collection))
@ -88,7 +89,7 @@ pub async fn get_apub_community_outbox(
let mut collection = OrderedCollection::new(); let mut collection = OrderedCollection::new();
collection collection
.set_many_items(pages) .set_many_items(pages)
.set_context(activitystreams::context()) .set_many_contexts(lemmy_context()?)
.set_id(community.get_outbox_url()?) .set_id(community.get_outbox_url()?)
.set_total_items(len as u64); .set_total_items(len as u64);
Ok(create_apub_response(&collection)) 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::{ use activitystreams::{
base::BaseExt, base::BaseExt,
collection::{CollectionExt, OrderedCollection}, collection::{CollectionExt, OrderedCollection},
@ -42,7 +42,7 @@ pub async fn get_apub_user_outbox(
let mut collection = OrderedCollection::new(); let mut collection = OrderedCollection::new();
collection collection
.set_many_items(Vec::<Url>::new()) .set_many_items(Vec::<Url>::new())
.set_context(activitystreams::context()) .set_many_contexts(lemmy_context()?)
.set_id(user.get_outbox_url()?) .set_id(user.get_outbox_url()?)
.set_total_items(0_u64); .set_total_items(0_u64);
Ok(create_apub_response(&collection)) Ok(create_apub_response(&collection))

View file

@ -1,4 +1,5 @@
use crate::{ use crate::{
extensions::context::lemmy_context,
fetcher::{ fetcher::{
get_or_fetch_and_insert_comment, get_or_fetch_and_insert_comment,
get_or_fetch_and_insert_post, get_or_fetch_and_insert_post,
@ -64,7 +65,7 @@ impl ToApub for Comment {
comment comment
// 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)
.set_context(activitystreams::context()) .set_many_contexts(lemmy_context()?)
.set_id(Url::parse(&self.ap_id)?) .set_id(Url::parse(&self.ap_id)?)
.set_published(convert_datetime(self.published)) .set_published(convert_datetime(self.published))
.set_to(community.actor_id) .set_to(community.actor_id)

View file

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

View file

@ -1,5 +1,5 @@
use crate::{ 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}, fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
objects::{ objects::{
check_object_domain, 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) // Not needed when the Post is embedded in a collection (like for community outbox)
// TODO: need to set proper context defining sensitive/commentsEnabled fields // TODO: need to set proper context defining sensitive/commentsEnabled fields
// https://git.asonix.dog/Aardwolf/activitystreams/issues/5 // https://git.asonix.dog/Aardwolf/activitystreams/issues/5
.set_context(activitystreams::context()) .set_many_contexts(lemmy_context()?)
.set_id(self.ap_id.parse::<Url>()?) .set_id(self.ap_id.parse::<Url>()?)
// Use summary field to be consistent with mastodon content warning. // Use summary field to be consistent with mastodon content warning.
// https://mastodon.xyz/@Louisa/103987265222901387.json // https://mastodon.xyz/@Louisa/103987265222901387.json

View file

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

View file

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