]> Untitled Git - lemmy.git/commitdiff
Move @context out of object/activity definitions
authorFelix Ableitner <me@nutomic.com>
Thu, 28 Oct 2021 15:25:26 +0000 (17:25 +0200)
committerFelix Ableitner <me@nutomic.com>
Fri, 29 Oct 2021 10:50:32 +0000 (12:50 +0200)
42 files changed:
crates/apub/assets/lemmy-comment.json
crates/apub/assets/lemmy-community.json
crates/apub/assets/lemmy-person.json
crates/apub/assets/lemmy-post.json
crates/apub/assets/lemmy-private-message.json
crates/apub/src/activities/comment/create_or_update.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/block_user.rs
crates/apub/src/activities/community/mod.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/undo_block_user.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/following/accept.rs
crates/apub/src/activities/following/follow.rs
crates/apub/src/activities/following/undo.rs
crates/apub/src/activities/mod.rs
crates/apub/src/activities/post/create_or_update.rs
crates/apub/src/activities/private_message/create_or_update.rs
crates/apub/src/activities/private_message/delete.rs
crates/apub/src/activities/private_message/undo_delete.rs
crates/apub/src/activities/report.rs
crates/apub/src/activities/voting/undo_vote.rs
crates/apub/src/activities/voting/vote.rs
crates/apub/src/collections/community_moderators.rs
crates/apub/src/collections/community_outbox.rs
crates/apub/src/context.rs
crates/apub/src/fetcher/object_id.rs
crates/apub/src/fetcher/post_or_comment.rs
crates/apub/src/fetcher/search.rs
crates/apub/src/http/community.rs
crates/apub/src/http/mod.rs
crates/apub/src/http/person.rs
crates/apub/src/lib.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/person.rs
crates/apub/src/objects/post.rs
crates/apub/src/objects/private_message.rs
crates/apub/src/objects/tombstone.rs

index c40e893c80b3951923e807c0a81a7096d16eee29..2a20be29da3bf2b8be780696906fd9b42830eb3f 100644 (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",
   "type": "Note",
   "attributedTo": "https://enterprise.lemmy.ml/u/picard",
index 3f56ed8ee5d4572e7d59e3e9b1215fcb2343d02b..7eddd86bdf9a9478f71ede189e74c99a1324f073 100644 (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",
   "type": "Group",
   "preferredUsername": "main",
index 25c9351774127be13787ea298b3bc46096c56198..769f2f3e110b2d7bdc219d4c981876cad913363b 100644 (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",
   "type": "Person",
   "preferredUsername": "picard",
index baf28ea06bef973b055a898d559a998562794fb4..2c39acce8424c2408e96ed7257c448c769054c0a 100644 (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",
   "type": "Page",
   "attributedTo": "https://enterprise.lemmy.ml/u/picard",
index 374754215890f215d566c13b076044ab425ea9a0..45790231d4b5e90ec2a6e1aef493b6a6486bd687 100644 (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",
   "type": "ChatMessage",
   "attributedTo": "https://enterprise.lemmy.ml/u/picard",
index f8469be925b8c54b21cd49fe623f7f37f0404d2d..18661cbfe1a78a4bc47affc7e313ea85808e40ee 100644 (file)
@@ -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(),
     };
 
index 11abb5ba58c74f7cf933cabeaa63725dd12ed89b..b65fa48e7b1eff72d5eccbe32b9a3341abe8695a 100644 (file)
@@ -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(),
     };
 
index 6165eb2f00d212b0a09d116ef5f0cec7d029b818..007fcbb3cc2549b1da6416a3d546f07fd6e0b33f 100644 (file)
@@ -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?;
index 21493214594a56cc43fda833fcf316150ae82a64..0a716228d360bc26ad77b50b321f401e022025bd 100644 (file)
@@ -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(),
     })
   }
index 9db9d8148530ec2da9e64e1d1d7ada3b58183077..1f51c0335ae6395ea25461827027ed7b60784789 100644 (file)
@@ -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;
index 786740d53c03183bd723608d26d188c56a112553..f0c0b90e1cc7602da644001d59cf9030a7358d18 100644 (file)
@@ -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(),
index b5e2a69cba20dba542164dbac73bf2b04b8016ae..ad220c9681afd37af18ed3899244439c660acb4d 100644 (file)
@@ -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(),
     };
 
index b5ad7f920c408b177ce22e410d49798e472d1cd4..78fce324877d696ffcc451efc87fdea19cead696 100644 (file)
@@ -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(),
     };
 
index 2677ea901c59b2547c1e44a28b2169a1f99ae4c6..0db590b9a19bea87502022f844d9742d2ec59539 100644 (file)
@@ -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(),
     })
   }
index d881ab424373f1e70723ee218b28f7cab786906d..5cc4dffc2a839c24f2e466733bcd10cf6e47d7d2 100644 (file)
@@ -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(),
     };
 
index 92f5318429bdae93e3a16e1bfbb292f97d71bfe7..28f6c10894de75f54baa7a5fac20dbb0b2aa743e 100644 (file)
@@ -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()];
index 4710f70f0b69a77fe05432008bdbd1cfa9ed4136..57a112e0bcb69029cb08730c50207f647470e5aa 100644 (file)
@@ -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(),
     })
   }
index 7abb611780d1d5431521f8de6e3aacb26c34cf42..a9326a2689bd787799f1f83ab7a7043dee5f57f2 100644 (file)
@@ -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()];
index 63f79caa0d8e3c695062df8583f69d7d42288fff..9509babb0e2ab9a1047df340a0f9f5230cbfbd42 100644 (file)
@@ -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
+}
index 44498823e4a69ee7fd1164477fe6e534c330fb3d..b5d9a202edd2acff72eeca78b6d0a833fc233b51 100644 (file)
@@ -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(),
     })
   }
index 22f8edb8e15fca6142dfb3c713ae16fa87611859..72a38e5e6eabd5212189231a0657397923364b77 100644 (file)
@@ -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())],
index bcd9542c9c207cee54f829c08b3defb228162581..0928cba2e1ad73b72e28f5d832c9ce7adcf7bead 100644 (file)
@@ -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(),
     })
   }
index cdabaa9aa6766b8170107936f0ef3f316b796357..4275ea9cd1d69d1a4aa031caf818ce2734825cd4 100644 (file)
@@ -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()];
index 24041b0ff4ae7bcece9fce67b9433c90b64091bd..9256920a6a74ab43d272b01705405d7974703378 100644 (file)
@@ -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(
index 144cbfc1819c545f691bcc47ccce7264e3499ec3..cc6206616133c78b1cd5aec80363753a93542e74 100644 (file)
@@ -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);
index 5b08390fa45fbd332bf90f424b26c99734703d6a..3efef7cf89a00ab22070d687d14ae3026ba674b4 100644 (file)
@@ -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(),
     })
   }
index dc1d579850f113ad3618ce9e01381db100817e96..2d190f4e2506f649936afec56d57ede03aa53ef9 100644 (file)
@@ -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,
index 24465c95c2532482ea43b0c1cf53791152c24de3..9d870f0e836b40e1acf7067c7bc40ccf04edca6b 100644 (file)
@@ -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,
index bc58052f0496219c5308e8f95a64a65156a51933..cf4b704fce185da65d3a5aa60273e950430e79eb 100644 (file)
@@ -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
+  }
 }
index 66466362e79b9cee7b529d55ee983f69667cbe69..5c5c518f4b85afe6e5afa2272fc0093bd8c1d94b 100644 (file)
@@ -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()))
index ff0562a6b8d96e427b2521a1897b4c8296d598d1..ac391120385d13a7d6b57e67a1fc663f3be9e866 100644 (file)
@@ -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;
index 86cdcbe07bdce77309e60d00b02b2762e45a6c45..5c2a3e7bde777bad8dc22d031114905648642c6c 100644 (file)
@@ -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::{
index f39f7b6f0184c246c9d934ad30e0611a68893cac..6c9c632e1c1778ce0dee6fa03108ebae4510c969 100644 (file)
@@ -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))
 }
 
index fe44d5e3f04aab61b62f67395f4a9a32388f66bc..48956cdf28b57225dde041e21befcfddec206e0b 100644 (file)
@@ -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)]
index 88ffa12033f776885df048784c478da842613d7f..2cc187681f4f48151af7efb9687b1c2b1e647ecc 100644 (file)
@@ -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))
 }
index 3bf3ff2534a3ac21462350f98ca82e954531d545..f60e04af8de0b1aa01af186d0b5e63bd5f210225 100644 (file)
@@ -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
-}
index 335605a6c834eca1157f43585078d607faea0fce..5698640da7db4ea0fb3e182059eb29a85c4b5f14 100644 (file)
@@ -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),
index a38e759fa2e198dc8b4226b81f72c5f3a1848378..c7d1dd3ed4538d3640e155836e9c2dd35d4fd9e6 100644 (file)
@@ -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(),
index f4ba225b8ed260cca37beabae83e6f424c389156..49ba7eb1b685f1c92e582a3f07894cf5396f776d 100644 (file)
@@ -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!()
   }
 
index f15bb5baffb8c2da6ffeb369e7dd63b2c253e4c2..ee9aa7b884f18d9b4e1a45c0c4758438eb400669 100644 (file)
@@ -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),
index 56200d1be789256488a33c3d75b093e8af978c5a..e971ebe339ea61dd2d827584736d6fb8c6a3bacc 100644 (file)
@@ -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!()
   }
 
index fc78c9682f7a3cff2f29424170b47949f8bc2dab..2746c5ae600c3f0f89b2c0290440308d07c31e67 100644 (file)
@@ -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),