Move @context out of object/activity definitions

This commit is contained in:
Felix Ableitner 2021-10-28 17:25:26 +02:00
parent 2d04ff93f5
commit d89156810d
42 changed files with 179 additions and 473 deletions

View file

@ -1,23 +1,4 @@
{ {
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"comments_enabled": {
"id": "pt:commentsEnabled",
"type": "sc:Boolean"
},
"matrixUserId": {
"id": "as:alsoKnownAs",
"type": "sc:Text"
},
"moderators": "as:moderators",
"pt": "https://join-lemmy.org#",
"sc": "http://schema.org#",
"sensitive": "as:sensitive",
"stickied": "as:stickied"
},
"https://w3id.org/security/v1"
],
"id": "https://enterprise.lemmy.ml/comment/38741", "id": "https://enterprise.lemmy.ml/comment/38741",
"type": "Note", "type": "Note",
"attributedTo": "https://enterprise.lemmy.ml/u/picard", "attributedTo": "https://enterprise.lemmy.ml/u/picard",

View file

@ -1,23 +1,4 @@
{ {
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"comments_enabled": {
"id": "pt:commentsEnabled",
"type": "sc:Boolean"
},
"matrixUserId": {
"id": "as:alsoKnownAs",
"type": "sc:Text"
},
"moderators": "as:moderators",
"pt": "https://join-lemmy.org#",
"sc": "http://schema.org#",
"sensitive": "as:sensitive",
"stickied": "as:stickied"
},
"https://w3id.org/security/v1"
],
"id": "https://enterprise.lemmy.ml/c/tenforward", "id": "https://enterprise.lemmy.ml/c/tenforward",
"type": "Group", "type": "Group",
"preferredUsername": "main", "preferredUsername": "main",

View file

@ -1,23 +1,4 @@
{ {
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"comments_enabled": {
"id": "pt:commentsEnabled",
"type": "sc:Boolean"
},
"matrixUserId": {
"id": "as:alsoKnownAs",
"type": "sc:Text"
},
"moderators": "as:moderators",
"pt": "https://join-lemmy.org#",
"sc": "http://schema.org#",
"sensitive": "as:sensitive",
"stickied": "as:stickied"
},
"https://w3id.org/security/v1"
],
"id": "https://enterprise.lemmy.ml/u/picard", "id": "https://enterprise.lemmy.ml/u/picard",
"type": "Person", "type": "Person",
"preferredUsername": "picard", "preferredUsername": "picard",

View file

@ -1,23 +1,4 @@
{ {
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"comments_enabled": {
"id": "pt:commentsEnabled",
"type": "sc:Boolean"
},
"matrixUserId": {
"id": "as:alsoKnownAs",
"type": "sc:Text"
},
"moderators": "as:moderators",
"pt": "https://join-lemmy.org#",
"sc": "http://schema.org#",
"sensitive": "as:sensitive",
"stickied": "as:stickied"
},
"https://w3id.org/security/v1"
],
"id": "https://enterprise.lemmy.ml/post/55143", "id": "https://enterprise.lemmy.ml/post/55143",
"type": "Page", "type": "Page",
"attributedTo": "https://enterprise.lemmy.ml/u/picard", "attributedTo": "https://enterprise.lemmy.ml/u/picard",

View file

@ -1,23 +1,4 @@
{ {
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"comments_enabled": {
"id": "pt:commentsEnabled",
"type": "sc:Boolean"
},
"matrixUserId": {
"id": "as:alsoKnownAs",
"type": "sc:Text"
},
"moderators": "as:moderators",
"pt": "https://join-lemmy.org#",
"sc": "http://schema.org#",
"sensitive": "as:sensitive",
"stickied": "as:stickied"
},
"https://w3id.org/security/v1"
],
"id": "https://enterprise.lemmy.ml/private_message/1621", "id": "https://enterprise.lemmy.ml/private_message/1621",
"type": "ChatMessage", "type": "ChatMessage",
"attributedTo": "https://enterprise.lemmy.ml/u/picard", "attributedTo": "https://enterprise.lemmy.ml/u/picard",

View file

@ -12,7 +12,6 @@ use crate::{
verify_person_in_community, verify_person_in_community,
CreateOrUpdateType, CreateOrUpdateType,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{ objects::{
comment::{ApubComment, Note}, comment::{ApubComment, Note},
@ -20,13 +19,7 @@ use crate::{
person::ApubPerson, person::ApubPerson,
}, },
}; };
use activitystreams::{ use activitystreams::{link::Mention, public, unparsed::Unparsed};
base::AnyBase,
link::Mention,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use lemmy_api_common::{blocking, check_post_deleted_or_removed}; use lemmy_api_common::{blocking, check_post_deleted_or_removed};
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -54,8 +47,6 @@ pub struct CreateOrUpdateComment {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: CreateOrUpdateType, kind: CreateOrUpdateType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -91,7 +82,6 @@ impl CreateOrUpdateComment {
tag: maa.tags, tag: maa.tags,
kind, kind,
id: id.clone(), id: id.clone(),
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };

View file

@ -12,18 +12,11 @@ use crate::{
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
}; };
use activitystreams::{ use activitystreams::{activity::kind::AddType, public, unparsed::Unparsed};
activity::kind::AddType,
base::AnyBase,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -49,8 +42,6 @@ pub struct AddMod {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: AddType, kind: AddType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -74,7 +65,6 @@ impl AddMod {
cc: vec![community.actor_id()], cc: vec![community.actor_id()],
kind: AddType::Add, kind: AddType::Add,
id: id.clone(), id: id.clone(),
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };

View file

@ -12,24 +12,17 @@ use crate::{
deletion::{delete::Delete, undo_delete::UndoDelete}, deletion::{delete::Delete, undo_delete::UndoDelete},
generate_activity_id, generate_activity_id,
post::create_or_update::CreateOrUpdatePost, post::create_or_update::CreateOrUpdatePost,
send_lemmy_activity,
verify_activity, verify_activity,
verify_is_public, verify_is_public,
voting::{undo_vote::UndoVote, vote::Vote}, voting::{undo_vote::UndoVote, vote::Vote},
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
http::is_activity_already_known, http::is_activity_already_known,
insert_activity, insert_activity,
objects::community::ApubCommunity, objects::community::ApubCommunity,
send_lemmy_activity,
};
use activitystreams::{
activity::kind::AnnounceType,
base::AnyBase,
primitives::OneOrMany,
public,
unparsed::Unparsed,
}; };
use activitystreams::{activity::kind::AnnounceType, public, unparsed::Unparsed};
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
traits::{ActivityFields, ActivityHandler, ActorType}, traits::{ActivityFields, ActivityHandler, ActorType},
@ -102,8 +95,6 @@ pub struct AnnounceActivity {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: AnnounceType, kind: AnnounceType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -125,7 +116,6 @@ impl AnnounceActivity {
&AnnounceType::Announce, &AnnounceType::Announce,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?, )?,
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };
let inboxes = list_community_follower_inboxes(community, additional_inboxes, context).await?; let inboxes = list_community_follower_inboxes(community, additional_inboxes, context).await?;

View file

@ -10,17 +10,10 @@ use crate::{
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
}; };
use activitystreams::{ use activitystreams::{activity::kind::BlockType, public, unparsed::Unparsed};
activity::kind::BlockType,
base::AnyBase,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -51,8 +44,6 @@ pub struct BlockUserFromCommunity {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: BlockType, kind: BlockType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -75,7 +66,6 @@ impl BlockUserFromCommunity {
BlockType::Block, BlockType::Block,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?, )?,
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}) })
} }

View file

@ -1,10 +1,12 @@
use crate::{ use crate::{
activities::community::announce::{AnnouncableActivities, AnnounceActivity}, activities::{
community::announce::{AnnouncableActivities, AnnounceActivity},
send_lemmy_activity,
},
check_is_apub_id_valid, check_is_apub_id_valid,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
insert_activity, insert_activity,
objects::community::ApubCommunity, objects::community::ApubCommunity,
send_lemmy_activity,
}; };
use itertools::Itertools; use itertools::Itertools;
use lemmy_apub_lib::traits::ActorType; use lemmy_apub_lib::traits::ActorType;

View file

@ -12,18 +12,11 @@ use crate::{
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
}; };
use activitystreams::{ use activitystreams::{activity::kind::RemoveType, public, unparsed::Unparsed};
activity::kind::RemoveType,
base::AnyBase,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -49,8 +42,6 @@ pub struct RemoveMod {
kind: RemoveType, kind: RemoveType,
pub(in crate::activities) target: Url, pub(in crate::activities) target: Url,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -72,7 +63,6 @@ impl RemoveMod {
object: ObjectId::new(removed_mod.actor_id()), object: ObjectId::new(removed_mod.actor_id()),
target: generate_moderators_url(&community.actor_id)?.into(), target: generate_moderators_url(&community.actor_id)?.into(),
id: id.clone(), id: id.clone(),
context: lemmy_context(),
cc: vec![community.actor_id()], cc: vec![community.actor_id()],
kind: RemoveType::Remove, kind: RemoveType::Remove,
unparsed: Default::default(), unparsed: Default::default(),

View file

@ -11,17 +11,10 @@ use crate::{
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
}; };
use activitystreams::{ use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
activity::kind::UndoType,
base::AnyBase,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -46,8 +39,6 @@ pub struct UndoBlockUserFromCommunity {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UndoType, kind: UndoType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -72,7 +63,6 @@ impl UndoBlockUserFromCommunity {
cc: vec![community.actor_id()], cc: vec![community.actor_id()],
kind: UndoType::Undo, kind: UndoType::Undo,
id: id.clone(), id: id.clone(),
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };

View file

@ -10,20 +10,13 @@ use crate::{
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{ objects::{
community::{ApubCommunity, Group}, community::{ApubCommunity, Group},
person::ApubPerson, person::ApubPerson,
}, },
}; };
use activitystreams::{ use activitystreams::{activity::kind::UpdateType, public, unparsed::Unparsed};
activity::kind::UpdateType,
base::AnyBase,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -51,8 +44,6 @@ pub struct UpdateCommunity {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UpdateType, kind: UpdateType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -74,7 +65,6 @@ impl UpdateCommunity {
cc: vec![community.actor_id()], cc: vec![community.actor_id()],
kind: UpdateType::Update, kind: UpdateType::Update,
id: id.clone(), id: id.clone(),
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };

View file

@ -14,17 +14,10 @@ use crate::{
verify_activity, verify_activity,
verify_is_public, verify_is_public,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
}; };
use activitystreams::{ use activitystreams::{activity::kind::DeleteType, public, unparsed::Unparsed};
activity::kind::DeleteType,
base::AnyBase,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use anyhow::anyhow; use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
@ -79,8 +72,6 @@ pub struct Delete {
/// deleting their own content. /// deleting their own content.
pub(in crate::activities::deletion) summary: Option<String>, pub(in crate::activities::deletion) summary: Option<String>,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -159,7 +150,6 @@ impl Delete {
DeleteType::Delete, DeleteType::Delete,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?, )?,
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}) })
} }

View file

@ -15,17 +15,10 @@ use crate::{
verify_activity, verify_activity,
verify_is_public, verify_is_public,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
}; };
use activitystreams::{ use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
activity::kind::UndoType,
base::AnyBase,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use anyhow::anyhow; use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
@ -52,8 +45,6 @@ pub struct UndoDelete {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UndoType, kind: UndoType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -128,7 +119,6 @@ impl UndoDelete {
cc: vec![community.actor_id()], cc: vec![community.actor_id()],
kind: UndoType::Undo, kind: UndoType::Undo,
id: id.clone(), id: id.clone(),
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };

View file

@ -1,16 +1,14 @@
use crate::{ use crate::{
activities::{following::follow::FollowCommunity, generate_activity_id, verify_activity}, activities::{
context::lemmy_context, following::follow::FollowCommunity,
generate_activity_id,
send_lemmy_activity,
verify_activity,
},
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
send_lemmy_activity,
};
use activitystreams::{
activity::kind::AcceptType,
base::AnyBase,
primitives::OneOrMany,
unparsed::Unparsed,
}; };
use activitystreams::{activity::kind::AcceptType, unparsed::Unparsed};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -32,8 +30,6 @@ pub struct AcceptFollowCommunity {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: AcceptType, kind: AcceptType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -59,7 +55,6 @@ impl AcceptFollowCommunity {
AcceptType::Accept, AcceptType::Accept,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?, )?,
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };
let inbox = vec![person.inbox_url()]; let inbox = vec![person.inbox_url()];

View file

@ -2,21 +2,15 @@ use crate::{
activities::{ activities::{
following::accept::AcceptFollowCommunity, following::accept::AcceptFollowCommunity,
generate_activity_id, generate_activity_id,
send_lemmy_activity,
verify_activity, verify_activity,
verify_person, verify_person,
verify_person_in_community, verify_person_in_community,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
send_lemmy_activity,
};
use activitystreams::{
activity::kind::FollowType,
base::AnyBase,
primitives::OneOrMany,
unparsed::Unparsed,
}; };
use activitystreams::{activity::kind::FollowType, unparsed::Unparsed};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -41,8 +35,6 @@ pub struct FollowCommunity {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: FollowType, kind: FollowType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -62,7 +54,6 @@ impl FollowCommunity {
FollowType::Follow, FollowType::Follow,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?, )?,
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}) })
} }

View file

@ -2,20 +2,14 @@ use crate::{
activities::{ activities::{
following::follow::FollowCommunity, following::follow::FollowCommunity,
generate_activity_id, generate_activity_id,
send_lemmy_activity,
verify_activity, verify_activity,
verify_person, verify_person,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
send_lemmy_activity,
};
use activitystreams::{
activity::kind::UndoType,
base::AnyBase,
primitives::OneOrMany,
unparsed::Unparsed,
}; };
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -40,8 +34,6 @@ pub struct UndoFollowCommunity {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UndoType, kind: UndoType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -62,7 +54,6 @@ impl UndoFollowCommunity {
UndoType::Undo, UndoType::Undo,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?, )?,
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };
let inbox = vec![community.shared_inbox_or_inbox_url()]; let inbox = vec![community.shared_inbox_or_inbox_url()];

View file

@ -1,13 +1,19 @@
use crate::{ use crate::{
check_is_apub_id_valid, check_is_apub_id_valid,
context::WithContext,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
insert_activity,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
}; };
use activitystreams::public; use activitystreams::public;
use anyhow::anyhow; use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{traits::ActivityFields, verify::verify_domains_match}; use lemmy_apub_lib::{
activity_queue::send_activity,
traits::{ActivityFields, ActorType},
verify::verify_domains_match,
};
use lemmy_db_schema::source::community::Community; use lemmy_db_schema::source::community::Community;
use lemmy_db_views_actor::{ use lemmy_db_views_actor::{
community_person_ban_view::CommunityPersonBanView, community_person_ban_view::CommunityPersonBanView,
@ -15,6 +21,7 @@ use lemmy_db_views_actor::{
}; };
use lemmy_utils::{settings::structs::Settings, LemmyError}; use lemmy_utils::{settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use log::info;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use strum_macros::ToString; use strum_macros::ToString;
use url::{ParseError, Url}; use url::{ParseError, Url};
@ -146,3 +153,47 @@ where
); );
Url::parse(&id) Url::parse(&id)
} }
async fn send_lemmy_activity<T: Serialize>(
context: &LemmyContext,
activity: &T,
activity_id: &Url,
actor: &dyn ActorType,
inboxes: Vec<Url>,
sensitive: bool,
) -> Result<(), LemmyError> {
if !context.settings().federation.enabled || inboxes.is_empty() {
return Ok(());
}
let activity = WithContext::new(activity);
info!("Sending activity {}", activity_id.to_string());
// Don't send anything to ourselves
// TODO: this should be a debug assert
let hostname = context.settings().get_hostname_without_port()?;
let inboxes: Vec<&Url> = inboxes
.iter()
.filter(|i| i.domain().expect("valid inbox url") != hostname)
.collect();
let serialised_activity = serde_json::to_string(&activity)?;
insert_activity(
activity_id,
serialised_activity.clone(),
true,
sensitive,
context.pool(),
)
.await?;
send_activity(
serialised_activity,
actor,
inboxes,
context.client(),
context.activity_queue(),
)
.await
}

View file

@ -12,7 +12,6 @@ use crate::{
verify_person_in_community, verify_person_in_community,
CreateOrUpdateType, CreateOrUpdateType,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{ objects::{
community::ApubCommunity, community::ApubCommunity,
@ -20,7 +19,7 @@ use crate::{
post::{ApubPost, Page}, post::{ApubPost, Page},
}, },
}; };
use activitystreams::{base::AnyBase, primitives::OneOrMany, public, unparsed::Unparsed}; use activitystreams::{public, unparsed::Unparsed};
use anyhow::anyhow; use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
@ -44,8 +43,6 @@ pub struct CreateOrUpdatePost {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: CreateOrUpdateType, kind: CreateOrUpdateType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -69,7 +66,6 @@ impl CreateOrUpdatePost {
cc: vec![community.actor_id()], cc: vec![community.actor_id()],
kind, kind,
id: id.clone(), id: id.clone(),
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}) })
} }

View file

@ -1,14 +1,18 @@
use crate::{ use crate::{
activities::{generate_activity_id, verify_activity, verify_person, CreateOrUpdateType}, activities::{
context::lemmy_context, generate_activity_id,
send_lemmy_activity,
verify_activity,
verify_person,
CreateOrUpdateType,
},
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{ objects::{
person::ApubPerson, person::ApubPerson,
private_message::{ApubPrivateMessage, ChatMessage}, private_message::{ApubPrivateMessage, ChatMessage},
}, },
send_lemmy_activity,
}; };
use activitystreams::{base::AnyBase, primitives::OneOrMany, unparsed::Unparsed}; use activitystreams::unparsed::Unparsed;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -24,8 +28,6 @@ use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)] #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct CreateOrUpdatePrivateMessage { pub struct CreateOrUpdatePrivateMessage {
#[serde(rename = "@context")]
pub context: OneOrMany<AnyBase>,
id: Url, id: Url,
actor: ObjectId<ApubPerson>, actor: ObjectId<ApubPerson>,
to: [ObjectId<ApubPerson>; 1], to: [ObjectId<ApubPerson>; 1],
@ -54,7 +56,6 @@ impl CreateOrUpdatePrivateMessage {
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?; )?;
let create_or_update = CreateOrUpdatePrivateMessage { let create_or_update = CreateOrUpdatePrivateMessage {
context: lemmy_context(),
id: id.clone(), id: id.clone(),
actor: ObjectId::new(actor.actor_id()), actor: ObjectId::new(actor.actor_id()),
to: [ObjectId::new(recipient.actor_id())], to: [ObjectId::new(recipient.actor_id())],

View file

@ -1,16 +1,9 @@
use crate::{ use crate::{
activities::{generate_activity_id, verify_activity, verify_person}, activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage}, objects::{person::ApubPerson, private_message::ApubPrivateMessage},
send_lemmy_activity,
};
use activitystreams::{
activity::kind::DeleteType,
base::AnyBase,
primitives::OneOrMany,
unparsed::Unparsed,
}; };
use activitystreams::{activity::kind::DeleteType, unparsed::Unparsed};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -35,8 +28,6 @@ pub struct DeletePrivateMessage {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: DeleteType, kind: DeleteType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -56,7 +47,6 @@ impl DeletePrivateMessage {
DeleteType::Delete, DeleteType::Delete,
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?, )?,
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}) })
} }

View file

@ -2,20 +2,14 @@ use crate::{
activities::{ activities::{
generate_activity_id, generate_activity_id,
private_message::delete::DeletePrivateMessage, private_message::delete::DeletePrivateMessage,
send_lemmy_activity,
verify_activity, verify_activity,
verify_person, verify_person,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{person::ApubPerson, private_message::ApubPrivateMessage}, objects::{person::ApubPerson, private_message::ApubPrivateMessage},
send_lemmy_activity,
};
use activitystreams::{
activity::kind::UndoType,
base::AnyBase,
primitives::OneOrMany,
unparsed::Unparsed,
}; };
use activitystreams::{activity::kind::UndoType, unparsed::Unparsed};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -40,8 +34,6 @@ pub struct UndoDeletePrivateMessage {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UndoType, kind: UndoType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -69,7 +61,6 @@ impl UndoDeletePrivateMessage {
object, object,
kind: UndoType::Undo, kind: UndoType::Undo,
id: id.clone(), id: id.clone(),
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };
let inbox = vec![recipient.shared_inbox_or_inbox_url()]; let inbox = vec![recipient.shared_inbox_or_inbox_url()];

View file

@ -1,17 +1,15 @@
use crate::{ use crate::{
activities::{generate_activity_id, verify_activity, verify_person_in_community}, activities::{
context::lemmy_context, generate_activity_id,
send_lemmy_activity,
verify_activity,
verify_person_in_community,
},
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
send_lemmy_activity,
PostOrComment, PostOrComment,
}; };
use activitystreams::{ use activitystreams::{activity::kind::FlagType, unparsed::Unparsed};
activity::kind::FlagType,
base::AnyBase,
primitives::OneOrMany,
unparsed::Unparsed,
};
use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse}; use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse};
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -40,8 +38,6 @@ pub struct Report {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: FlagType, kind: FlagType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -67,7 +63,6 @@ impl Report {
summary: reason, summary: reason,
kind, kind,
id: id.clone(), id: id.clone(),
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };
send_lemmy_activity( send_lemmy_activity(

View file

@ -14,18 +14,11 @@ use crate::{
vote::{Vote, VoteType}, vote::{Vote, VoteType},
}, },
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
PostOrComment, PostOrComment,
}; };
use activitystreams::{ use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
activity::kind::UndoType,
base::AnyBase,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -49,8 +42,6 @@ pub struct UndoVote {
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UndoType, kind: UndoType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -81,7 +72,6 @@ impl UndoVote {
cc: vec![community.actor_id()], cc: vec![community.actor_id()],
kind: UndoType::Undo, kind: UndoType::Undo,
id: id.clone(), id: id.clone(),
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}; };
let activity = AnnouncableActivities::UndoVote(undo_vote); let activity = AnnouncableActivities::UndoVote(undo_vote);

View file

@ -10,12 +10,11 @@ use crate::{
verify_person_in_community, verify_person_in_community,
voting::{vote_comment, vote_post}, voting::{vote_comment, vote_post},
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{community::ApubCommunity, person::ApubPerson}, objects::{community::ApubCommunity, person::ApubPerson},
PostOrComment, PostOrComment,
}; };
use activitystreams::{base::AnyBase, primitives::OneOrMany, public, unparsed::Unparsed}; use activitystreams::{public, unparsed::Unparsed};
use anyhow::anyhow; use anyhow::anyhow;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
@ -71,8 +70,6 @@ pub struct Vote {
#[serde(rename = "type")] #[serde(rename = "type")]
pub(in crate::activities::voting) kind: VoteType, pub(in crate::activities::voting) kind: VoteType,
id: Url, id: Url,
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)] #[serde(flatten)]
unparsed: Unparsed, unparsed: Unparsed,
} }
@ -92,7 +89,6 @@ impl Vote {
cc: vec![community.actor_id()], cc: vec![community.actor_id()],
kind: kind.clone(), kind: kind.clone(),
id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?, id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?,
context: lemmy_context(),
unparsed: Default::default(), unparsed: Default::default(),
}) })
} }

View file

@ -1,17 +1,10 @@
use crate::{ use crate::{
collections::CommunityContext, collections::CommunityContext,
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
objects::person::ApubPerson, objects::person::ApubPerson,
}; };
use activitystreams::{ use activitystreams::{chrono::NaiveDateTime, collection::kind::OrderedCollectionType};
base::AnyBase,
chrono::NaiveDateTime,
collection::kind::OrderedCollectionType,
primitives::OneOrMany,
url::Url,
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{traits::ApubObject, verify::verify_domains_match}; use lemmy_apub_lib::{traits::ApubObject, verify::verify_domains_match};
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -22,13 +15,12 @@ use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use url::Url;
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct GroupModerators { pub struct GroupModerators {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
r#type: OrderedCollectionType, r#type: OrderedCollectionType,
id: Url, id: Url,
ordered_items: Vec<ObjectId<ApubPerson>>, ordered_items: Vec<ObjectId<ApubPerson>>,
@ -75,7 +67,6 @@ impl ApubObject for ApubCommunityModerators {
.map(|m| ObjectId::<ApubPerson>::new(m.moderator.actor_id.clone().into_inner())) .map(|m| ObjectId::<ApubPerson>::new(m.moderator.actor_id.clone().into_inner()))
.collect(); .collect();
Ok(GroupModerators { Ok(GroupModerators {
context: lemmy_context(),
r#type: OrderedCollectionType::OrderedCollection, r#type: OrderedCollectionType::OrderedCollection,
id: generate_moderators_url(&data.0.actor_id)?.into(), id: generate_moderators_url(&data.0.actor_id)?.into(),
ordered_items, ordered_items,

View file

@ -1,17 +1,11 @@
use crate::{ use crate::{
activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType}, activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType},
collections::CommunityContext, collections::CommunityContext,
context::lemmy_context,
generate_outbox_url, generate_outbox_url,
objects::{person::ApubPerson, post::ApubPost}, objects::{person::ApubPerson, post::ApubPost},
}; };
use activitystreams::{ use activitystreams::collection::kind::OrderedCollectionType;
base::AnyBase, use chrono::NaiveDateTime;
chrono::NaiveDateTime,
collection::kind::OrderedCollectionType,
primitives::OneOrMany,
url::Url,
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
data::Data, data::Data,
@ -25,13 +19,12 @@ use lemmy_db_schema::{
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use url::Url;
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct GroupOutbox { pub struct GroupOutbox {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
r#type: OrderedCollectionType, r#type: OrderedCollectionType,
id: Url, id: Url,
ordered_items: Vec<CreateOrUpdatePost>, ordered_items: Vec<CreateOrUpdatePost>,
@ -88,7 +81,6 @@ impl ApubObject for ApubCommunityOutbox {
} }
Ok(GroupOutbox { Ok(GroupOutbox {
context: lemmy_context(),
r#type: OrderedCollectionType::OrderedCollection, r#type: OrderedCollectionType::OrderedCollection,
id: generate_outbox_url(&data.0.actor_id)?.into(), id: generate_outbox_url(&data.0.actor_id)?.into(),
ordered_items, ordered_items,

View file

@ -1,28 +1,51 @@
use activitystreams::{base::AnyBase, context, primitives::OneOrMany}; use activitystreams::{base::AnyBase, context, primitives::OneOrMany};
use serde::{Deserialize, Serialize};
use serde_json::json; use serde_json::json;
use url::Url; use url::Url;
pub(crate) fn lemmy_context() -> OneOrMany<AnyBase> { lazy_static! {
let context_ext = AnyBase::from_arbitrary_json(json!( static ref CONTEXT: OneOrMany<AnyBase> = {
{ let context_ext = AnyBase::from_arbitrary_json(json!(
"sc": "http://schema.org#", {
"sensitive": "as:sensitive", "sc": "http://schema.org#",
"stickied": "as:stickied", "sensitive": "as:sensitive",
"pt": "https://join-lemmy.org#", "stickied": "as:stickied",
"comments_enabled": { "pt": "https://join-lemmy.org#",
"type": "sc:Boolean", "comments_enabled": {
"id": "pt:commentsEnabled" "type": "sc:Boolean",
}, "id": "pt:commentsEnabled"
"moderators": "as:moderators", },
"matrixUserId": { "moderators": "as:moderators",
"type": "sc:Text", "matrixUserId": {
"id": "as:alsoKnownAs" "type": "sc:Text",
}, "id": "as:alsoKnownAs"
})) },
.expect("parse context"); }))
OneOrMany::from(vec![ .expect("parse context");
AnyBase::from(context()), OneOrMany::from(vec![
context_ext, AnyBase::from(context()),
AnyBase::from(Url::parse("https://w3id.org/security/v1").expect("parse context")), context_ext,
]) AnyBase::from(Url::parse("https://w3id.org/security/v1").expect("parse context")),
])
};
}
#[derive(Serialize, Deserialize)]
pub(crate) struct WithContext<T> {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(flatten)]
inner: T,
}
impl<T> WithContext<T> {
pub(crate) fn new(inner: T) -> WithContext<T> {
WithContext {
context: CONTEXT.clone(),
inner,
}
}
pub(crate) fn inner(self) -> T {
self.inner
}
} }

View file

@ -22,7 +22,6 @@ use url::Url;
/// fetch through the search). This should be configurable. /// fetch through the search). This should be configurable.
static REQUEST_LIMIT: i32 = 25; static REQUEST_LIMIT: i32 = 25;
// TODO: after moving this file to library, remove lazy_static dependency from apub crate
lazy_static! { lazy_static! {
static ref CLIENT: Client = Client::builder() static ref CLIENT: Client = Client::builder()
.user_agent(build_user_agent(&Settings::get())) .user_agent(build_user_agent(&Settings::get()))

View file

@ -2,7 +2,7 @@ use crate::objects::{
comment::{ApubComment, Note}, comment::{ApubComment, Note},
post::{ApubPost, Page}, post::{ApubPost, Page},
}; };
use activitystreams::chrono::NaiveDateTime; use chrono::NaiveDateTime;
use lemmy_apub_lib::traits::ApubObject; use lemmy_apub_lib::traits::ApubObject;
use lemmy_db_schema::source::{comment::CommentForm, post::PostForm}; use lemmy_db_schema::source::{comment::CommentForm, post::PostForm};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;

View file

@ -7,8 +7,8 @@ use crate::{
post::{ApubPost, Page}, post::{ApubPost, Page},
}, },
}; };
use activitystreams::chrono::NaiveDateTime;
use anyhow::anyhow; use anyhow::anyhow;
use chrono::NaiveDateTime;
use itertools::Itertools; use itertools::Itertools;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{

View file

@ -10,7 +10,7 @@ use crate::{
community_outbox::ApubCommunityOutbox, community_outbox::ApubCommunityOutbox,
CommunityContext, CommunityContext,
}, },
context::lemmy_context, context::WithContext,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
generate_outbox_url, generate_outbox_url,
http::{ http::{
@ -82,9 +82,9 @@ pub async fn community_inbox(
) -> Result<HttpResponse, LemmyError> { ) -> Result<HttpResponse, LemmyError> {
let unparsed = payload_to_string(payload).await?; let unparsed = payload_to_string(payload).await?;
info!("Received community inbox activity {}", unparsed); info!("Received community inbox activity {}", unparsed);
let activity = serde_json::from_str::<GroupInboxActivities>(&unparsed)?; let activity = serde_json::from_str::<WithContext<GroupInboxActivities>>(&unparsed)?;
receive_group_inbox(activity.clone(), request, &context).await?; receive_group_inbox(activity.inner(), request, &context).await?;
Ok(HttpResponse::Ok().finish()) Ok(HttpResponse::Ok().finish())
} }
@ -127,9 +127,9 @@ pub(crate) async fn get_apub_community_followers(
let mut collection = UnorderedCollection::new(); let mut collection = UnorderedCollection::new();
collection collection
.set_many_contexts(lemmy_context())
.set_id(community.followers_url.into()) .set_id(community.followers_url.into())
.set_total_items(community_followers.len() as u64); .set_total_items(community_followers.len() as u64);
let collection = WithContext::new(collection);
Ok(create_apub_response(&collection)) Ok(create_apub_response(&collection))
} }

View file

@ -1,5 +1,6 @@
use crate::{ use crate::{
check_is_apub_id_valid, check_is_apub_id_valid,
context::WithContext,
fetcher::get_or_fetch_and_upsert_actor, fetcher::get_or_fetch_and_upsert_actor,
http::{ http::{
community::{receive_group_inbox, GroupInboxActivities}, community::{receive_group_inbox, GroupInboxActivities},
@ -55,8 +56,8 @@ pub async fn shared_inbox(
) -> Result<HttpResponse, LemmyError> { ) -> Result<HttpResponse, LemmyError> {
let unparsed = payload_to_string(payload).await?; let unparsed = payload_to_string(payload).await?;
info!("Received shared inbox activity {}", unparsed); info!("Received shared inbox activity {}", unparsed);
let activity = serde_json::from_str::<SharedInboxActivities>(&unparsed)?; let activity = serde_json::from_str::<WithContext<SharedInboxActivities>>(&unparsed)?;
match activity { match activity.inner() {
SharedInboxActivities::GroupInboxActivities(g) => { SharedInboxActivities::GroupInboxActivities(g) => {
receive_group_inbox(g, request, &context).await receive_group_inbox(g, request, &context).await
} }
@ -134,7 +135,7 @@ where
{ {
HttpResponse::Ok() HttpResponse::Ok()
.content_type(APUB_JSON_CONTENT_TYPE) .content_type(APUB_JSON_CONTENT_TYPE)
.json(data) .json(WithContext::new(data))
} }
fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body> fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body>
@ -144,7 +145,7 @@ where
HttpResponse::Gone() HttpResponse::Gone()
.content_type(APUB_JSON_CONTENT_TYPE) .content_type(APUB_JSON_CONTENT_TYPE)
.status(StatusCode::GONE) .status(StatusCode::GONE)
.json(data) .json(WithContext::new(data))
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -8,7 +8,7 @@ use crate::{
undo_delete::UndoDeletePrivateMessage, undo_delete::UndoDeletePrivateMessage,
}, },
}, },
context::lemmy_context, context::WithContext,
generate_outbox_url, generate_outbox_url,
http::{ http::{
create_apub_response, create_apub_response,
@ -80,8 +80,8 @@ pub async fn person_inbox(
) -> Result<HttpResponse, LemmyError> { ) -> Result<HttpResponse, LemmyError> {
let unparsed = payload_to_string(payload).await?; let unparsed = payload_to_string(payload).await?;
info!("Received person inbox activity {}", unparsed); info!("Received person inbox activity {}", unparsed);
let activity = serde_json::from_str::<PersonInboxActivities>(&unparsed)?; let activity = serde_json::from_str::<WithContext<PersonInboxActivities>>(&unparsed)?;
receive_person_inbox(activity, request, &context).await receive_person_inbox(activity.inner(), request, &context).await
} }
pub(in crate::http) async fn receive_person_inbox( pub(in crate::http) async fn receive_person_inbox(
@ -104,8 +104,8 @@ pub(crate) async fn get_apub_person_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_many_contexts(lemmy_context())
.set_id(generate_outbox_url(&person.actor_id)?.into()) .set_id(generate_outbox_url(&person.actor_id)?.into())
.set_total_items(0_u64); .set_total_items(0_u64);
let collection = WithContext::new(collection);
Ok(create_apub_response(&collection)) Ok(create_apub_response(&collection))
} }

View file

@ -12,15 +12,10 @@ extern crate lazy_static;
use crate::fetcher::post_or_comment::PostOrComment; use crate::fetcher::post_or_comment::PostOrComment;
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::webfinger::{webfinger_resolve_actor, WebfingerType};
activity_queue::send_activity,
traits::ActorType,
webfinger::{webfinger_resolve_actor, WebfingerType},
};
use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, DbPool}; use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, DbPool};
use lemmy_utils::{location_info, settings::structs::Settings, LemmyError}; use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use log::info;
use serde::Serialize; use serde::Serialize;
use std::net::IpAddr; use std::net::IpAddr;
use url::{ParseError, Url}; use url::{ParseError, Url};
@ -195,46 +190,3 @@ where
.await??; .await??;
Ok(()) Ok(())
} }
pub(crate) async fn send_lemmy_activity<T: Serialize>(
context: &LemmyContext,
activity: &T,
activity_id: &Url,
actor: &dyn ActorType,
inboxes: Vec<Url>,
sensitive: bool,
) -> Result<(), LemmyError> {
if !context.settings().federation.enabled || inboxes.is_empty() {
return Ok(());
}
info!("Sending activity {}", activity_id.to_string());
// Don't send anything to ourselves
// TODO: this should be a debug assert
let hostname = context.settings().get_hostname_without_port()?;
let inboxes: Vec<&Url> = inboxes
.iter()
.filter(|i| i.domain().expect("valid inbox url") != hostname)
.collect();
let serialised_activity = serde_json::to_string(&activity)?;
insert_activity(
activity_id,
serialised_activity.clone(),
true,
sensitive,
context.pool(),
)
.await?;
send_activity(
serialised_activity,
actor,
inboxes,
context.client(),
context.activity_queue(),
)
.await
}

View file

@ -1,6 +1,5 @@
use crate::{ use crate::{
activities::{verify_is_public, verify_person_in_community}, activities::{verify_is_public, verify_person_in_community},
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{ objects::{
community::ApubCommunity, community::ApubCommunity,
@ -11,16 +10,9 @@ use crate::{
}, },
PostOrComment, PostOrComment,
}; };
use activitystreams::{ use activitystreams::{object::kind::NoteType, public, unparsed::Unparsed};
base::AnyBase,
chrono::NaiveDateTime,
object::kind::NoteType,
primitives::OneOrMany,
public,
unparsed::Unparsed,
};
use anyhow::anyhow; use anyhow::anyhow;
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset, NaiveDateTime};
use html2md::parse_html; use html2md::parse_html;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
@ -52,11 +44,6 @@ use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Note { pub struct Note {
/// Necessary to make this optional to make Pleroma Create/Note work.
/// TODO: change this so that context is not defined in the struct itself, but added in activity
/// queue and http handlers
#[serde(rename = "@context")]
context: Option<OneOrMany<AnyBase>>,
r#type: NoteType, r#type: NoteType,
id: Url, id: Url,
pub(crate) attributed_to: ObjectId<ApubPerson>, pub(crate) attributed_to: ObjectId<ApubPerson>,
@ -206,7 +193,6 @@ impl ApubObject for ApubComment {
}; };
let note = Note { let note = Note {
context: Some(lemmy_context()),
r#type: NoteType::Note, r#type: NoteType::Note,
id: self.ap_id.to_owned().into_inner(), id: self.ap_id.to_owned().into_inner(),
attributed_to: ObjectId::new(creator.actor_id), attributed_to: ObjectId::new(creator.actor_id),

View file

@ -5,7 +5,6 @@ use crate::{
community_outbox::ApubCommunityOutbox, community_outbox::ApubCommunityOutbox,
CommunityContext, CommunityContext,
}, },
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
generate_moderators_url, generate_moderators_url,
generate_outbox_url, generate_outbox_url,
@ -13,13 +12,10 @@ use crate::{
}; };
use activitystreams::{ use activitystreams::{
actor::{kind::GroupType, Endpoints}, actor::{kind::GroupType, Endpoints},
base::AnyBase,
chrono::NaiveDateTime,
object::kind::ImageType, object::kind::ImageType,
primitives::OneOrMany,
unparsed::Unparsed, unparsed::Unparsed,
}; };
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset, NaiveDateTime};
use itertools::Itertools; use itertools::Itertools;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
@ -50,8 +46,6 @@ use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Group { pub struct Group {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: GroupType, kind: GroupType,
pub(crate) id: Url, pub(crate) id: Url,
@ -181,7 +175,6 @@ impl ApubObject for ApubCommunity {
}); });
let group = Group { let group = Group {
context: lemmy_context(),
kind: GroupType::Group, kind: GroupType::Group,
id: self.actor_id(), id: self.actor_id(),
preferred_username: self.name.clone(), preferred_username: self.name.clone(),

View file

@ -1,18 +1,10 @@
use crate::{ use crate::{
check_is_apub_id_valid, check_is_apub_id_valid,
context::lemmy_context,
generate_outbox_url, generate_outbox_url,
objects::{get_summary_from_string_or_source, ImageObject, Source}, objects::{get_summary_from_string_or_source, ImageObject, Source},
}; };
use activitystreams::{ use activitystreams::{actor::Endpoints, object::kind::ImageType, unparsed::Unparsed};
actor::Endpoints, use chrono::{DateTime, FixedOffset, NaiveDateTime};
base::AnyBase,
chrono::NaiveDateTime,
object::{kind::ImageType, Tombstone},
primitives::OneOrMany,
unparsed::Unparsed,
};
use chrono::{DateTime, FixedOffset};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
signatures::PublicKey, signatures::PublicKey,
@ -44,8 +36,6 @@ pub enum UserTypes {
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Person { pub struct Person {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: UserTypes, kind: UserTypes,
id: Url, id: Url,
@ -99,7 +89,7 @@ impl From<DbPerson> for ApubPerson {
impl ApubObject for ApubPerson { impl ApubObject for ApubPerson {
type DataType = LemmyContext; type DataType = LemmyContext;
type ApubType = Person; type ApubType = Person;
type TombstoneType = Tombstone; type TombstoneType = ();
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
Some(self.last_refreshed_at) Some(self.last_refreshed_at)
@ -146,7 +136,6 @@ impl ApubObject for ApubPerson {
}); });
let person = Person { let person = Person {
context: lemmy_context(),
kind, kind,
id: self.actor_id.to_owned().into_inner(), id: self.actor_id.to_owned().into_inner(),
preferred_username: self.name.clone(), preferred_username: self.name.clone(),
@ -170,7 +159,7 @@ impl ApubObject for ApubPerson {
Ok(person) Ok(person)
} }
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> { fn to_tombstone(&self) -> Result<(), LemmyError> {
unimplemented!() unimplemented!()
} }

View file

@ -1,6 +1,5 @@
use crate::{ use crate::{
activities::{verify_is_public, verify_person_in_community}, activities::{verify_is_public, verify_person_in_community},
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{ objects::{
community::ApubCommunity, community::ApubCommunity,
@ -11,9 +10,7 @@ use crate::{
}, },
}; };
use activitystreams::{ use activitystreams::{
base::AnyBase,
object::kind::{ImageType, PageType}, object::kind::{ImageType, PageType},
primitives::OneOrMany,
public, public,
unparsed::Unparsed, unparsed::Unparsed,
}; };
@ -49,8 +46,6 @@ use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Page { pub struct Page {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
r#type: PageType, r#type: PageType,
id: Url, id: Url,
pub(crate) attributed_to: ObjectId<ApubPerson>, pub(crate) attributed_to: ObjectId<ApubPerson>,
@ -196,7 +191,6 @@ impl ApubObject for ApubPost {
}); });
let page = Page { let page = Page {
context: lemmy_context(),
r#type: PageType::Page, r#type: PageType::Page,
id: self.ap_id.clone().into(), id: self.ap_id.clone().into(),
attributed_to: ObjectId::new(creator.actor_id), attributed_to: ObjectId::new(creator.actor_id),

View file

@ -1,17 +1,10 @@
use crate::{ use crate::{
context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
objects::{person::ApubPerson, Source}, objects::{person::ApubPerson, Source},
}; };
use activitystreams::{ use activitystreams::unparsed::Unparsed;
base::AnyBase,
chrono::NaiveDateTime,
object::Tombstone,
primitives::OneOrMany,
unparsed::Unparsed,
};
use anyhow::anyhow; use anyhow::anyhow;
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset, NaiveDateTime};
use html2md::parse_html; use html2md::parse_html;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
@ -37,8 +30,6 @@ use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ChatMessage { pub struct ChatMessage {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
r#type: ChatMessageType, r#type: ChatMessageType,
id: Url, id: Url,
pub(crate) attributed_to: ObjectId<ApubPerson>, pub(crate) attributed_to: ObjectId<ApubPerson>,
@ -104,7 +95,7 @@ impl From<PrivateMessage> for ApubPrivateMessage {
impl ApubObject for ApubPrivateMessage { impl ApubObject for ApubPrivateMessage {
type DataType = LemmyContext; type DataType = LemmyContext;
type ApubType = ChatMessage; type ApubType = ChatMessage;
type TombstoneType = Tombstone; type TombstoneType = ();
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
None None
@ -137,7 +128,6 @@ impl ApubObject for ApubPrivateMessage {
blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??; blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
let note = ChatMessage { let note = ChatMessage {
context: lemmy_context(),
r#type: ChatMessageType::ChatMessage, r#type: ChatMessageType::ChatMessage,
id: self.ap_id.clone().into(), id: self.ap_id.clone().into(),
attributed_to: ObjectId::new(creator.actor_id), attributed_to: ObjectId::new(creator.actor_id),
@ -155,7 +145,7 @@ impl ApubObject for ApubPrivateMessage {
Ok(note) Ok(note)
} }
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> { fn to_tombstone(&self) -> Result<(), LemmyError> {
unimplemented!() unimplemented!()
} }

View file

@ -1,10 +1,5 @@
use crate::context::lemmy_context; use activitystreams::object::kind::TombstoneType;
use activitystreams::{ use chrono::{DateTime, FixedOffset, NaiveDateTime};
base::AnyBase,
chrono::{DateTime, FixedOffset, NaiveDateTime},
object::kind::TombstoneType,
primitives::OneOrMany,
};
use lemmy_utils::utils::convert_datetime; use lemmy_utils::utils::convert_datetime;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
@ -13,8 +8,6 @@ use serde_with::skip_serializing_none;
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Tombstone { pub struct Tombstone {
#[serde(rename = "@context")]
context: OneOrMany<AnyBase>,
#[serde(rename = "type")] #[serde(rename = "type")]
kind: TombstoneType, kind: TombstoneType,
former_type: String, former_type: String,
@ -24,7 +17,6 @@ pub struct Tombstone {
impl Tombstone { impl Tombstone {
pub fn new<T: ToString>(former_type: T, updated_time: NaiveDateTime) -> Tombstone { pub fn new<T: ToString>(former_type: T, updated_time: NaiveDateTime) -> Tombstone {
Tombstone { Tombstone {
context: lemmy_context(),
kind: TombstoneType::Tombstone, kind: TombstoneType::Tombstone,
former_type: former_type.to_string(), former_type: former_type.to_string(),
deleted: convert_datetime(updated_time), deleted: convert_datetime(updated_time),