mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-22 20:43:05 +00:00
Move @context out of object/activity definitions
This commit is contained in:
parent
2d04ff93f5
commit
d89156810d
42 changed files with 179 additions and 473 deletions
|
@ -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",
|
||||
"type": "Note",
|
||||
"attributedTo": "https://enterprise.lemmy.ml/u/picard",
|
||||
|
|
|
@ -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",
|
||||
"type": "Group",
|
||||
"preferredUsername": "main",
|
||||
|
|
|
@ -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",
|
||||
"type": "Person",
|
||||
"preferredUsername": "picard",
|
||||
|
|
|
@ -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",
|
||||
"type": "Page",
|
||||
"attributedTo": "https://enterprise.lemmy.ml/u/picard",
|
||||
|
|
|
@ -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",
|
||||
"type": "ChatMessage",
|
||||
"attributedTo": "https://enterprise.lemmy.ml/u/picard",
|
||||
|
|
|
@ -12,7 +12,6 @@ use crate::{
|
|||
verify_person_in_community,
|
||||
CreateOrUpdateType,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{
|
||||
comment::{ApubComment, Note},
|
||||
|
@ -20,13 +19,7 @@ use crate::{
|
|||
person::ApubPerson,
|
||||
},
|
||||
};
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
link::Mention,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{link::Mention, public, unparsed::Unparsed};
|
||||
use lemmy_api_common::{blocking, check_post_deleted_or_removed};
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -54,8 +47,6 @@ pub struct CreateOrUpdateComment {
|
|||
#[serde(rename = "type")]
|
||||
kind: CreateOrUpdateType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -91,7 +82,6 @@ impl CreateOrUpdateComment {
|
|||
tag: maa.tags,
|
||||
kind,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
|
||||
|
|
|
@ -12,18 +12,11 @@ use crate::{
|
|||
verify_mod_action,
|
||||
verify_person_in_community,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
generate_moderators_url,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::kind::AddType,
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{activity::kind::AddType, public, unparsed::Unparsed};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -49,8 +42,6 @@ pub struct AddMod {
|
|||
#[serde(rename = "type")]
|
||||
kind: AddType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -74,7 +65,6 @@ impl AddMod {
|
|||
cc: vec![community.actor_id()],
|
||||
kind: AddType::Add,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
|
||||
|
|
|
@ -12,24 +12,17 @@ use crate::{
|
|||
deletion::{delete::Delete, undo_delete::UndoDelete},
|
||||
generate_activity_id,
|
||||
post::create_or_update::CreateOrUpdatePost,
|
||||
send_lemmy_activity,
|
||||
verify_activity,
|
||||
verify_is_public,
|
||||
voting::{undo_vote::UndoVote, vote::Vote},
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
http::is_activity_already_known,
|
||||
insert_activity,
|
||||
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::{
|
||||
data::Data,
|
||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
|
@ -102,8 +95,6 @@ pub struct AnnounceActivity {
|
|||
#[serde(rename = "type")]
|
||||
kind: AnnounceType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -125,7 +116,6 @@ impl AnnounceActivity {
|
|||
&AnnounceType::Announce,
|
||||
&context.settings().get_protocol_and_hostname(),
|
||||
)?,
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
let inboxes = list_community_follower_inboxes(community, additional_inboxes, context).await?;
|
||||
|
|
|
@ -10,17 +10,10 @@ use crate::{
|
|||
verify_mod_action,
|
||||
verify_person_in_community,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::kind::BlockType,
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{activity::kind::BlockType, public, unparsed::Unparsed};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -51,8 +44,6 @@ pub struct BlockUserFromCommunity {
|
|||
#[serde(rename = "type")]
|
||||
kind: BlockType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -75,7 +66,6 @@ impl BlockUserFromCommunity {
|
|||
BlockType::Block,
|
||||
&context.settings().get_protocol_and_hostname(),
|
||||
)?,
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
use crate::{
|
||||
activities::community::announce::{AnnouncableActivities, AnnounceActivity},
|
||||
activities::{
|
||||
community::announce::{AnnouncableActivities, AnnounceActivity},
|
||||
send_lemmy_activity,
|
||||
},
|
||||
check_is_apub_id_valid,
|
||||
fetcher::object_id::ObjectId,
|
||||
insert_activity,
|
||||
objects::community::ApubCommunity,
|
||||
send_lemmy_activity,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use lemmy_apub_lib::traits::ActorType;
|
||||
|
|
|
@ -12,18 +12,11 @@ use crate::{
|
|||
verify_mod_action,
|
||||
verify_person_in_community,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
generate_moderators_url,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::kind::RemoveType,
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{activity::kind::RemoveType, public, unparsed::Unparsed};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -49,8 +42,6 @@ pub struct RemoveMod {
|
|||
kind: RemoveType,
|
||||
pub(in crate::activities) target: Url,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -72,7 +63,6 @@ impl RemoveMod {
|
|||
object: ObjectId::new(removed_mod.actor_id()),
|
||||
target: generate_moderators_url(&community.actor_id)?.into(),
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
cc: vec![community.actor_id()],
|
||||
kind: RemoveType::Remove,
|
||||
unparsed: Default::default(),
|
||||
|
|
|
@ -11,17 +11,10 @@ use crate::{
|
|||
verify_mod_action,
|
||||
verify_person_in_community,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::kind::UndoType,
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -46,8 +39,6 @@ pub struct UndoBlockUserFromCommunity {
|
|||
#[serde(rename = "type")]
|
||||
kind: UndoType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -72,7 +63,6 @@ impl UndoBlockUserFromCommunity {
|
|||
cc: vec![community.actor_id()],
|
||||
kind: UndoType::Undo,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
|
||||
|
|
|
@ -10,20 +10,13 @@ use crate::{
|
|||
verify_mod_action,
|
||||
verify_person_in_community,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{
|
||||
community::{ApubCommunity, Group},
|
||||
person::ApubPerson,
|
||||
},
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::kind::UpdateType,
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{activity::kind::UpdateType, public, unparsed::Unparsed};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -51,8 +44,6 @@ pub struct UpdateCommunity {
|
|||
#[serde(rename = "type")]
|
||||
kind: UpdateType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -74,7 +65,6 @@ impl UpdateCommunity {
|
|||
cc: vec![community.actor_id()],
|
||||
kind: UpdateType::Update,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
|
||||
|
|
|
@ -14,17 +14,10 @@ use crate::{
|
|||
verify_activity,
|
||||
verify_is_public,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::kind::DeleteType,
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{activity::kind::DeleteType, public, unparsed::Unparsed};
|
||||
use anyhow::anyhow;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
|
@ -79,8 +72,6 @@ pub struct Delete {
|
|||
/// deleting their own content.
|
||||
pub(in crate::activities::deletion) summary: Option<String>,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -159,7 +150,6 @@ impl Delete {
|
|||
DeleteType::Delete,
|
||||
&context.settings().get_protocol_and_hostname(),
|
||||
)?,
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -15,17 +15,10 @@ use crate::{
|
|||
verify_activity,
|
||||
verify_is_public,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::kind::UndoType,
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
|
||||
use anyhow::anyhow;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
|
@ -52,8 +45,6 @@ pub struct UndoDelete {
|
|||
#[serde(rename = "type")]
|
||||
kind: UndoType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -128,7 +119,6 @@ impl UndoDelete {
|
|||
cc: vec![community.actor_id()],
|
||||
kind: UndoType::Undo,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
use crate::{
|
||||
activities::{following::follow::FollowCommunity, generate_activity_id, verify_activity},
|
||||
context::lemmy_context,
|
||||
activities::{
|
||||
following::follow::FollowCommunity,
|
||||
generate_activity_id,
|
||||
send_lemmy_activity,
|
||||
verify_activity,
|
||||
},
|
||||
fetcher::object_id::ObjectId,
|
||||
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_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -32,8 +30,6 @@ pub struct AcceptFollowCommunity {
|
|||
#[serde(rename = "type")]
|
||||
kind: AcceptType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -59,7 +55,6 @@ impl AcceptFollowCommunity {
|
|||
AcceptType::Accept,
|
||||
&context.settings().get_protocol_and_hostname(),
|
||||
)?,
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
let inbox = vec![person.inbox_url()];
|
||||
|
|
|
@ -2,21 +2,15 @@ use crate::{
|
|||
activities::{
|
||||
following::accept::AcceptFollowCommunity,
|
||||
generate_activity_id,
|
||||
send_lemmy_activity,
|
||||
verify_activity,
|
||||
verify_person,
|
||||
verify_person_in_community,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
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_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -41,8 +35,6 @@ pub struct FollowCommunity {
|
|||
#[serde(rename = "type")]
|
||||
kind: FollowType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -62,7 +54,6 @@ impl FollowCommunity {
|
|||
FollowType::Follow,
|
||||
&context.settings().get_protocol_and_hostname(),
|
||||
)?,
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,20 +2,14 @@ use crate::{
|
|||
activities::{
|
||||
following::follow::FollowCommunity,
|
||||
generate_activity_id,
|
||||
send_lemmy_activity,
|
||||
verify_activity,
|
||||
verify_person,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
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_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -40,8 +34,6 @@ pub struct UndoFollowCommunity {
|
|||
#[serde(rename = "type")]
|
||||
kind: UndoType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -62,7 +54,6 @@ impl UndoFollowCommunity {
|
|||
UndoType::Undo,
|
||||
&context.settings().get_protocol_and_hostname(),
|
||||
)?,
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
let inbox = vec![community.shared_inbox_or_inbox_url()];
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
use crate::{
|
||||
check_is_apub_id_valid,
|
||||
context::WithContext,
|
||||
fetcher::object_id::ObjectId,
|
||||
generate_moderators_url,
|
||||
insert_activity,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
};
|
||||
use activitystreams::public;
|
||||
use anyhow::anyhow;
|
||||
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_views_actor::{
|
||||
community_person_ban_view::CommunityPersonBanView,
|
||||
|
@ -15,6 +21,7 @@ use lemmy_db_views_actor::{
|
|||
};
|
||||
use lemmy_utils::{settings::structs::Settings, LemmyError};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::ToString;
|
||||
use url::{ParseError, Url};
|
||||
|
@ -146,3 +153,47 @@ where
|
|||
);
|
||||
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
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ use crate::{
|
|||
verify_person_in_community,
|
||||
CreateOrUpdateType,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{
|
||||
community::ApubCommunity,
|
||||
|
@ -20,7 +19,7 @@ use crate::{
|
|||
post::{ApubPost, Page},
|
||||
},
|
||||
};
|
||||
use activitystreams::{base::AnyBase, primitives::OneOrMany, public, unparsed::Unparsed};
|
||||
use activitystreams::{public, unparsed::Unparsed};
|
||||
use anyhow::anyhow;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
|
@ -44,8 +43,6 @@ pub struct CreateOrUpdatePost {
|
|||
#[serde(rename = "type")]
|
||||
kind: CreateOrUpdateType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -69,7 +66,6 @@ impl CreateOrUpdatePost {
|
|||
cc: vec![community.actor_id()],
|
||||
kind,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
use crate::{
|
||||
activities::{generate_activity_id, verify_activity, verify_person, CreateOrUpdateType},
|
||||
context::lemmy_context,
|
||||
activities::{
|
||||
generate_activity_id,
|
||||
send_lemmy_activity,
|
||||
verify_activity,
|
||||
verify_person,
|
||||
CreateOrUpdateType,
|
||||
},
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{
|
||||
person::ApubPerson,
|
||||
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_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -24,8 +28,6 @@ use url::Url;
|
|||
#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CreateOrUpdatePrivateMessage {
|
||||
#[serde(rename = "@context")]
|
||||
pub context: OneOrMany<AnyBase>,
|
||||
id: Url,
|
||||
actor: ObjectId<ApubPerson>,
|
||||
to: [ObjectId<ApubPerson>; 1],
|
||||
|
@ -54,7 +56,6 @@ impl CreateOrUpdatePrivateMessage {
|
|||
&context.settings().get_protocol_and_hostname(),
|
||||
)?;
|
||||
let create_or_update = CreateOrUpdatePrivateMessage {
|
||||
context: lemmy_context(),
|
||||
id: id.clone(),
|
||||
actor: ObjectId::new(actor.actor_id()),
|
||||
to: [ObjectId::new(recipient.actor_id())],
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
use crate::{
|
||||
activities::{generate_activity_id, verify_activity, verify_person},
|
||||
context::lemmy_context,
|
||||
activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_person},
|
||||
fetcher::object_id::ObjectId,
|
||||
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_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -35,8 +28,6 @@ pub struct DeletePrivateMessage {
|
|||
#[serde(rename = "type")]
|
||||
kind: DeleteType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -56,7 +47,6 @@ impl DeletePrivateMessage {
|
|||
DeleteType::Delete,
|
||||
&context.settings().get_protocol_and_hostname(),
|
||||
)?,
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,20 +2,14 @@ use crate::{
|
|||
activities::{
|
||||
generate_activity_id,
|
||||
private_message::delete::DeletePrivateMessage,
|
||||
send_lemmy_activity,
|
||||
verify_activity,
|
||||
verify_person,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
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_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -40,8 +34,6 @@ pub struct UndoDeletePrivateMessage {
|
|||
#[serde(rename = "type")]
|
||||
kind: UndoType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -69,7 +61,6 @@ impl UndoDeletePrivateMessage {
|
|||
object,
|
||||
kind: UndoType::Undo,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
let inbox = vec![recipient.shared_inbox_or_inbox_url()];
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
use crate::{
|
||||
activities::{generate_activity_id, verify_activity, verify_person_in_community},
|
||||
context::lemmy_context,
|
||||
activities::{
|
||||
generate_activity_id,
|
||||
send_lemmy_activity,
|
||||
verify_activity,
|
||||
verify_person_in_community,
|
||||
},
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
send_lemmy_activity,
|
||||
PostOrComment,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::kind::FlagType,
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{activity::kind::FlagType, unparsed::Unparsed};
|
||||
use lemmy_api_common::{blocking, comment::CommentReportResponse, post::PostReportResponse};
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -40,8 +38,6 @@ pub struct Report {
|
|||
#[serde(rename = "type")]
|
||||
kind: FlagType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -67,7 +63,6 @@ impl Report {
|
|||
summary: reason,
|
||||
kind,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
send_lemmy_activity(
|
||||
|
|
|
@ -14,18 +14,11 @@ use crate::{
|
|||
vote::{Vote, VoteType},
|
||||
},
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
PostOrComment,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::kind::UndoType,
|
||||
base::AnyBase,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -49,8 +42,6 @@ pub struct UndoVote {
|
|||
#[serde(rename = "type")]
|
||||
kind: UndoType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -81,7 +72,6 @@ impl UndoVote {
|
|||
cc: vec![community.actor_id()],
|
||||
kind: UndoType::Undo,
|
||||
id: id.clone(),
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
};
|
||||
let activity = AnnouncableActivities::UndoVote(undo_vote);
|
||||
|
|
|
@ -10,12 +10,11 @@ use crate::{
|
|||
verify_person_in_community,
|
||||
voting::{vote_comment, vote_post},
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{community::ApubCommunity, person::ApubPerson},
|
||||
PostOrComment,
|
||||
};
|
||||
use activitystreams::{base::AnyBase, primitives::OneOrMany, public, unparsed::Unparsed};
|
||||
use activitystreams::{public, unparsed::Unparsed};
|
||||
use anyhow::anyhow;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
|
@ -71,8 +70,6 @@ pub struct Vote {
|
|||
#[serde(rename = "type")]
|
||||
pub(in crate::activities::voting) kind: VoteType,
|
||||
id: Url,
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(flatten)]
|
||||
unparsed: Unparsed,
|
||||
}
|
||||
|
@ -92,7 +89,6 @@ impl Vote {
|
|||
cc: vec![community.actor_id()],
|
||||
kind: kind.clone(),
|
||||
id: generate_activity_id(kind, &context.settings().get_protocol_and_hostname())?,
|
||||
context: lemmy_context(),
|
||||
unparsed: Default::default(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
use crate::{
|
||||
collections::CommunityContext,
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
generate_moderators_url,
|
||||
objects::person::ApubPerson,
|
||||
};
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
chrono::NaiveDateTime,
|
||||
collection::kind::OrderedCollectionType,
|
||||
primitives::OneOrMany,
|
||||
url::Url,
|
||||
};
|
||||
use activitystreams::{chrono::NaiveDateTime, collection::kind::OrderedCollectionType};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{traits::ApubObject, verify::verify_domains_match};
|
||||
use lemmy_db_schema::{
|
||||
|
@ -22,13 +15,12 @@ use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
|
|||
use lemmy_utils::LemmyError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
use url::Url;
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GroupModerators {
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
r#type: OrderedCollectionType,
|
||||
id: Url,
|
||||
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()))
|
||||
.collect();
|
||||
Ok(GroupModerators {
|
||||
context: lemmy_context(),
|
||||
r#type: OrderedCollectionType::OrderedCollection,
|
||||
id: generate_moderators_url(&data.0.actor_id)?.into(),
|
||||
ordered_items,
|
||||
|
|
|
@ -1,17 +1,11 @@
|
|||
use crate::{
|
||||
activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType},
|
||||
collections::CommunityContext,
|
||||
context::lemmy_context,
|
||||
generate_outbox_url,
|
||||
objects::{person::ApubPerson, post::ApubPost},
|
||||
};
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
chrono::NaiveDateTime,
|
||||
collection::kind::OrderedCollectionType,
|
||||
primitives::OneOrMany,
|
||||
url::Url,
|
||||
};
|
||||
use activitystreams::collection::kind::OrderedCollectionType;
|
||||
use chrono::NaiveDateTime;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
data::Data,
|
||||
|
@ -25,13 +19,12 @@ use lemmy_db_schema::{
|
|||
use lemmy_utils::LemmyError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
use url::Url;
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GroupOutbox {
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
r#type: OrderedCollectionType,
|
||||
id: Url,
|
||||
ordered_items: Vec<CreateOrUpdatePost>,
|
||||
|
@ -88,7 +81,6 @@ impl ApubObject for ApubCommunityOutbox {
|
|||
}
|
||||
|
||||
Ok(GroupOutbox {
|
||||
context: lemmy_context(),
|
||||
r#type: OrderedCollectionType::OrderedCollection,
|
||||
id: generate_outbox_url(&data.0.actor_id)?.into(),
|
||||
ordered_items,
|
||||
|
|
|
@ -1,28 +1,51 @@
|
|||
use activitystreams::{base::AnyBase, context, primitives::OneOrMany};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use url::Url;
|
||||
|
||||
pub(crate) fn lemmy_context() -> OneOrMany<AnyBase> {
|
||||
let context_ext = AnyBase::from_arbitrary_json(json!(
|
||||
{
|
||||
"sc": "http://schema.org#",
|
||||
"sensitive": "as:sensitive",
|
||||
"stickied": "as:stickied",
|
||||
"pt": "https://join-lemmy.org#",
|
||||
"comments_enabled": {
|
||||
"type": "sc:Boolean",
|
||||
"id": "pt:commentsEnabled"
|
||||
},
|
||||
"moderators": "as:moderators",
|
||||
"matrixUserId": {
|
||||
"type": "sc:Text",
|
||||
"id": "as:alsoKnownAs"
|
||||
},
|
||||
}))
|
||||
.expect("parse context");
|
||||
OneOrMany::from(vec![
|
||||
AnyBase::from(context()),
|
||||
context_ext,
|
||||
AnyBase::from(Url::parse("https://w3id.org/security/v1").expect("parse context")),
|
||||
])
|
||||
lazy_static! {
|
||||
static ref CONTEXT: OneOrMany<AnyBase> = {
|
||||
let context_ext = AnyBase::from_arbitrary_json(json!(
|
||||
{
|
||||
"sc": "http://schema.org#",
|
||||
"sensitive": "as:sensitive",
|
||||
"stickied": "as:stickied",
|
||||
"pt": "https://join-lemmy.org#",
|
||||
"comments_enabled": {
|
||||
"type": "sc:Boolean",
|
||||
"id": "pt:commentsEnabled"
|
||||
},
|
||||
"moderators": "as:moderators",
|
||||
"matrixUserId": {
|
||||
"type": "sc:Text",
|
||||
"id": "as:alsoKnownAs"
|
||||
},
|
||||
}))
|
||||
.expect("parse context");
|
||||
OneOrMany::from(vec![
|
||||
AnyBase::from(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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ use url::Url;
|
|||
/// fetch through the search). This should be configurable.
|
||||
static REQUEST_LIMIT: i32 = 25;
|
||||
|
||||
// TODO: after moving this file to library, remove lazy_static dependency from apub crate
|
||||
lazy_static! {
|
||||
static ref CLIENT: Client = Client::builder()
|
||||
.user_agent(build_user_agent(&Settings::get()))
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::objects::{
|
|||
comment::{ApubComment, Note},
|
||||
post::{ApubPost, Page},
|
||||
};
|
||||
use activitystreams::chrono::NaiveDateTime;
|
||||
use chrono::NaiveDateTime;
|
||||
use lemmy_apub_lib::traits::ApubObject;
|
||||
use lemmy_db_schema::source::{comment::CommentForm, post::PostForm};
|
||||
use lemmy_utils::LemmyError;
|
||||
|
|
|
@ -7,8 +7,8 @@ use crate::{
|
|||
post::{ApubPost, Page},
|
||||
},
|
||||
};
|
||||
use activitystreams::chrono::NaiveDateTime;
|
||||
use anyhow::anyhow;
|
||||
use chrono::NaiveDateTime;
|
||||
use itertools::Itertools;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
community_outbox::ApubCommunityOutbox,
|
||||
CommunityContext,
|
||||
},
|
||||
context::lemmy_context,
|
||||
context::WithContext,
|
||||
fetcher::object_id::ObjectId,
|
||||
generate_outbox_url,
|
||||
http::{
|
||||
|
@ -82,9 +82,9 @@ pub async fn community_inbox(
|
|||
) -> Result<HttpResponse, LemmyError> {
|
||||
let unparsed = payload_to_string(payload).await?;
|
||||
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())
|
||||
}
|
||||
|
@ -127,9 +127,9 @@ pub(crate) async fn get_apub_community_followers(
|
|||
|
||||
let mut collection = UnorderedCollection::new();
|
||||
collection
|
||||
.set_many_contexts(lemmy_context())
|
||||
.set_id(community.followers_url.into())
|
||||
.set_total_items(community_followers.len() as u64);
|
||||
let collection = WithContext::new(collection);
|
||||
Ok(create_apub_response(&collection))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::{
|
||||
check_is_apub_id_valid,
|
||||
context::WithContext,
|
||||
fetcher::get_or_fetch_and_upsert_actor,
|
||||
http::{
|
||||
community::{receive_group_inbox, GroupInboxActivities},
|
||||
|
@ -55,8 +56,8 @@ pub async fn shared_inbox(
|
|||
) -> Result<HttpResponse, LemmyError> {
|
||||
let unparsed = payload_to_string(payload).await?;
|
||||
info!("Received shared inbox activity {}", unparsed);
|
||||
let activity = serde_json::from_str::<SharedInboxActivities>(&unparsed)?;
|
||||
match activity {
|
||||
let activity = serde_json::from_str::<WithContext<SharedInboxActivities>>(&unparsed)?;
|
||||
match activity.inner() {
|
||||
SharedInboxActivities::GroupInboxActivities(g) => {
|
||||
receive_group_inbox(g, request, &context).await
|
||||
}
|
||||
|
@ -134,7 +135,7 @@ where
|
|||
{
|
||||
HttpResponse::Ok()
|
||||
.content_type(APUB_JSON_CONTENT_TYPE)
|
||||
.json(data)
|
||||
.json(WithContext::new(data))
|
||||
}
|
||||
|
||||
fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body>
|
||||
|
@ -144,7 +145,7 @@ where
|
|||
HttpResponse::Gone()
|
||||
.content_type(APUB_JSON_CONTENT_TYPE)
|
||||
.status(StatusCode::GONE)
|
||||
.json(data)
|
||||
.json(WithContext::new(data))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
undo_delete::UndoDeletePrivateMessage,
|
||||
},
|
||||
},
|
||||
context::lemmy_context,
|
||||
context::WithContext,
|
||||
generate_outbox_url,
|
||||
http::{
|
||||
create_apub_response,
|
||||
|
@ -80,8 +80,8 @@ pub async fn person_inbox(
|
|||
) -> Result<HttpResponse, LemmyError> {
|
||||
let unparsed = payload_to_string(payload).await?;
|
||||
info!("Received person inbox activity {}", unparsed);
|
||||
let activity = serde_json::from_str::<PersonInboxActivities>(&unparsed)?;
|
||||
receive_person_inbox(activity, request, &context).await
|
||||
let activity = serde_json::from_str::<WithContext<PersonInboxActivities>>(&unparsed)?;
|
||||
receive_person_inbox(activity.inner(), request, &context).await
|
||||
}
|
||||
|
||||
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();
|
||||
collection
|
||||
.set_many_items(Vec::<Url>::new())
|
||||
.set_many_contexts(lemmy_context())
|
||||
.set_id(generate_outbox_url(&person.actor_id)?.into())
|
||||
.set_total_items(0_u64);
|
||||
let collection = WithContext::new(collection);
|
||||
Ok(create_apub_response(&collection))
|
||||
}
|
||||
|
|
|
@ -12,15 +12,10 @@ extern crate lazy_static;
|
|||
use crate::fetcher::post_or_comment::PostOrComment;
|
||||
use anyhow::{anyhow, Context};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
activity_queue::send_activity,
|
||||
traits::ActorType,
|
||||
webfinger::{webfinger_resolve_actor, WebfingerType},
|
||||
};
|
||||
use lemmy_apub_lib::webfinger::{webfinger_resolve_actor, WebfingerType};
|
||||
use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, DbPool};
|
||||
use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use log::info;
|
||||
use serde::Serialize;
|
||||
use std::net::IpAddr;
|
||||
use url::{ParseError, Url};
|
||||
|
@ -195,46 +190,3 @@ where
|
|||
.await??;
|
||||
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
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::{
|
||||
activities::{verify_is_public, verify_person_in_community},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{
|
||||
community::ApubCommunity,
|
||||
|
@ -11,16 +10,9 @@ use crate::{
|
|||
},
|
||||
PostOrComment,
|
||||
};
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
chrono::NaiveDateTime,
|
||||
object::kind::NoteType,
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::{object::kind::NoteType, public, unparsed::Unparsed};
|
||||
use anyhow::anyhow;
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use chrono::{DateTime, FixedOffset, NaiveDateTime};
|
||||
use html2md::parse_html;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
|
@ -52,11 +44,6 @@ use url::Url;
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
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,
|
||||
id: Url,
|
||||
pub(crate) attributed_to: ObjectId<ApubPerson>,
|
||||
|
@ -206,7 +193,6 @@ impl ApubObject for ApubComment {
|
|||
};
|
||||
|
||||
let note = Note {
|
||||
context: Some(lemmy_context()),
|
||||
r#type: NoteType::Note,
|
||||
id: self.ap_id.to_owned().into_inner(),
|
||||
attributed_to: ObjectId::new(creator.actor_id),
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::{
|
|||
community_outbox::ApubCommunityOutbox,
|
||||
CommunityContext,
|
||||
},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
generate_moderators_url,
|
||||
generate_outbox_url,
|
||||
|
@ -13,13 +12,10 @@ use crate::{
|
|||
};
|
||||
use activitystreams::{
|
||||
actor::{kind::GroupType, Endpoints},
|
||||
base::AnyBase,
|
||||
chrono::NaiveDateTime,
|
||||
object::kind::ImageType,
|
||||
primitives::OneOrMany,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use chrono::{DateTime, FixedOffset, NaiveDateTime};
|
||||
use itertools::Itertools;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
|
@ -50,8 +46,6 @@ use url::Url;
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Group {
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(rename = "type")]
|
||||
kind: GroupType,
|
||||
pub(crate) id: Url,
|
||||
|
@ -181,7 +175,6 @@ impl ApubObject for ApubCommunity {
|
|||
});
|
||||
|
||||
let group = Group {
|
||||
context: lemmy_context(),
|
||||
kind: GroupType::Group,
|
||||
id: self.actor_id(),
|
||||
preferred_username: self.name.clone(),
|
||||
|
|
|
@ -1,18 +1,10 @@
|
|||
use crate::{
|
||||
check_is_apub_id_valid,
|
||||
context::lemmy_context,
|
||||
generate_outbox_url,
|
||||
objects::{get_summary_from_string_or_source, ImageObject, Source},
|
||||
};
|
||||
use activitystreams::{
|
||||
actor::Endpoints,
|
||||
base::AnyBase,
|
||||
chrono::NaiveDateTime,
|
||||
object::{kind::ImageType, Tombstone},
|
||||
primitives::OneOrMany,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use activitystreams::{actor::Endpoints, object::kind::ImageType, unparsed::Unparsed};
|
||||
use chrono::{DateTime, FixedOffset, NaiveDateTime};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
signatures::PublicKey,
|
||||
|
@ -44,8 +36,6 @@ pub enum UserTypes {
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Person {
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(rename = "type")]
|
||||
kind: UserTypes,
|
||||
id: Url,
|
||||
|
@ -99,7 +89,7 @@ impl From<DbPerson> for ApubPerson {
|
|||
impl ApubObject for ApubPerson {
|
||||
type DataType = LemmyContext;
|
||||
type ApubType = Person;
|
||||
type TombstoneType = Tombstone;
|
||||
type TombstoneType = ();
|
||||
|
||||
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||
Some(self.last_refreshed_at)
|
||||
|
@ -146,7 +136,6 @@ impl ApubObject for ApubPerson {
|
|||
});
|
||||
|
||||
let person = Person {
|
||||
context: lemmy_context(),
|
||||
kind,
|
||||
id: self.actor_id.to_owned().into_inner(),
|
||||
preferred_username: self.name.clone(),
|
||||
|
@ -170,7 +159,7 @@ impl ApubObject for ApubPerson {
|
|||
Ok(person)
|
||||
}
|
||||
|
||||
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
|
||||
fn to_tombstone(&self) -> Result<(), LemmyError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::{
|
||||
activities::{verify_is_public, verify_person_in_community},
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{
|
||||
community::ApubCommunity,
|
||||
|
@ -11,9 +10,7 @@ use crate::{
|
|||
},
|
||||
};
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
object::kind::{ImageType, PageType},
|
||||
primitives::OneOrMany,
|
||||
public,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
|
@ -49,8 +46,6 @@ use url::Url;
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Page {
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
r#type: PageType,
|
||||
id: Url,
|
||||
pub(crate) attributed_to: ObjectId<ApubPerson>,
|
||||
|
@ -196,7 +191,6 @@ impl ApubObject for ApubPost {
|
|||
});
|
||||
|
||||
let page = Page {
|
||||
context: lemmy_context(),
|
||||
r#type: PageType::Page,
|
||||
id: self.ap_id.clone().into(),
|
||||
attributed_to: ObjectId::new(creator.actor_id),
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
use crate::{
|
||||
context::lemmy_context,
|
||||
fetcher::object_id::ObjectId,
|
||||
objects::{person::ApubPerson, Source},
|
||||
};
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
chrono::NaiveDateTime,
|
||||
object::Tombstone,
|
||||
primitives::OneOrMany,
|
||||
unparsed::Unparsed,
|
||||
};
|
||||
use activitystreams::unparsed::Unparsed;
|
||||
use anyhow::anyhow;
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use chrono::{DateTime, FixedOffset, NaiveDateTime};
|
||||
use html2md::parse_html;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{
|
||||
|
@ -37,8 +30,6 @@ use url::Url;
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ChatMessage {
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
r#type: ChatMessageType,
|
||||
id: Url,
|
||||
pub(crate) attributed_to: ObjectId<ApubPerson>,
|
||||
|
@ -104,7 +95,7 @@ impl From<PrivateMessage> for ApubPrivateMessage {
|
|||
impl ApubObject for ApubPrivateMessage {
|
||||
type DataType = LemmyContext;
|
||||
type ApubType = ChatMessage;
|
||||
type TombstoneType = Tombstone;
|
||||
type TombstoneType = ();
|
||||
|
||||
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||
None
|
||||
|
@ -137,7 +128,6 @@ impl ApubObject for ApubPrivateMessage {
|
|||
blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
|
||||
|
||||
let note = ChatMessage {
|
||||
context: lemmy_context(),
|
||||
r#type: ChatMessageType::ChatMessage,
|
||||
id: self.ap_id.clone().into(),
|
||||
attributed_to: ObjectId::new(creator.actor_id),
|
||||
|
@ -155,7 +145,7 @@ impl ApubObject for ApubPrivateMessage {
|
|||
Ok(note)
|
||||
}
|
||||
|
||||
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
|
||||
fn to_tombstone(&self) -> Result<(), LemmyError> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
use crate::context::lemmy_context;
|
||||
use activitystreams::{
|
||||
base::AnyBase,
|
||||
chrono::{DateTime, FixedOffset, NaiveDateTime},
|
||||
object::kind::TombstoneType,
|
||||
primitives::OneOrMany,
|
||||
};
|
||||
use activitystreams::object::kind::TombstoneType;
|
||||
use chrono::{DateTime, FixedOffset, NaiveDateTime};
|
||||
use lemmy_utils::utils::convert_datetime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
|
@ -13,8 +8,6 @@ use serde_with::skip_serializing_none;
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Tombstone {
|
||||
#[serde(rename = "@context")]
|
||||
context: OneOrMany<AnyBase>,
|
||||
#[serde(rename = "type")]
|
||||
kind: TombstoneType,
|
||||
former_type: String,
|
||||
|
@ -24,7 +17,6 @@ pub struct Tombstone {
|
|||
impl Tombstone {
|
||||
pub fn new<T: ToString>(former_type: T, updated_time: NaiveDateTime) -> Tombstone {
|
||||
Tombstone {
|
||||
context: lemmy_context(),
|
||||
kind: TombstoneType::Tombstone,
|
||||
former_type: former_type.to_string(),
|
||||
deleted: convert_datetime(updated_time),
|
||||
|
|
Loading…
Reference in a new issue