]> Untitled Git - lemmy.git/commitdiff
Simplify lemmy_context() function (dont return errors)
authorFelix Ableitner <me@nutomic.com>
Thu, 29 Jul 2021 08:58:29 +0000 (10:58 +0200)
committerFelix Ableitner <me@nutomic.com>
Fri, 30 Jul 2021 21:16:33 +0000 (23:16 +0200)
17 files changed:
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/post/create.rs
crates/apub/src/activities/post/update.rs
crates/apub/src/activities/send/comment.rs
crates/apub/src/activities/send/community.rs
crates/apub/src/activities/send/person.rs
crates/apub/src/activities/send/post.rs
crates/apub/src/activities/send/private_message.rs
crates/apub/src/extensions/context.rs
crates/apub/src/http/community.rs
crates/apub/src/http/person.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/mod.rs
crates/apub/src/objects/person.rs
crates/apub/src/objects/post.rs
crates/apub/src/objects/private_message.rs

index 0bdb8bc06dd883abb029cee780601ca8b3c1db18..04721edac3df7ed015472d548dbc7833f9bfd0b5 100644 (file)
@@ -86,7 +86,7 @@ impl AnnounceActivity {
       cc: vec![community.followers_url()],
       kind: AnnounceType::Announce,
       common: ActivityCommonFields {
-        context: lemmy_context()?.into(),
+        context: lemmy_context(),
         id: generate_activity_id(AnnounceType::Announce)?,
         actor: community.actor_id(),
         unparsed: Default::default(),
index 909a6148dad584f287b08907dbc15557ecb472c4..270b712b3e9600a72c1fcf2579ebbf5e643432ae 100644 (file)
@@ -55,7 +55,7 @@ impl CreatePost {
       cc: [community.actor_id()],
       r#type: Default::default(),
       common: ActivityCommonFields {
-        context: lemmy_context()?.into(),
+        context: lemmy_context(),
         id: id.clone(),
         actor: actor.actor_id(),
         unparsed: Default::default(),
index a8cec9e73705300310c9e6026fabc22c4be5c035..c9fbb548f6a8ff081f6453b759cac9f597741b67 100644 (file)
@@ -48,7 +48,7 @@ impl UpdatePost {
       cc: [community.actor_id()],
       r#type: Default::default(),
       common: ActivityCommonFields {
-        context: lemmy_context()?.into(),
+        context: lemmy_context(),
         id: id.clone(),
         actor: actor.actor_id(),
         unparsed: Default::default(),
index be24dd07a42db348e2883ccd2bb6953b7d6cb4c6..47fc2a3e048322e1dac7ce442441dc33ad2703ef 100644 (file)
@@ -64,7 +64,7 @@ impl ApubObjectType for Comment {
       note.into_any_base()?,
     );
     create
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(CreateType::Create)?)
       .set_to(public())
       .set_many_ccs(maa.ccs.to_owned())
@@ -97,7 +97,7 @@ impl ApubObjectType for Comment {
       note.into_any_base()?,
     );
     update
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UpdateType::Update)?)
       .set_to(public())
       .set_many_ccs(maa.ccs.to_owned())
@@ -124,7 +124,7 @@ impl ApubObjectType for Comment {
       self.ap_id.to_owned().into_inner(),
     );
     delete
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -153,7 +153,7 @@ impl ApubObjectType for Comment {
       self.ap_id.to_owned().into_inner(),
     );
     delete
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -164,7 +164,7 @@ impl ApubObjectType for Comment {
       delete.into_any_base()?,
     );
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -188,7 +188,7 @@ impl ApubObjectType for Comment {
       self.ap_id.to_owned().into_inner(),
     );
     remove
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -217,7 +217,7 @@ impl ApubObjectType for Comment {
       self.ap_id.to_owned().into_inner(),
     );
     remove
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -228,7 +228,7 @@ impl ApubObjectType for Comment {
       remove.into_any_base()?,
     );
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -255,7 +255,7 @@ impl ApubLikeableType for Comment {
       self.ap_id.to_owned().into_inner(),
     );
     like
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(LikeType::Like)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -279,7 +279,7 @@ impl ApubLikeableType for Comment {
       self.ap_id.to_owned().into_inner(),
     );
     dislike
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(DislikeType::Dislike)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -307,7 +307,7 @@ impl ApubLikeableType for Comment {
       self.ap_id.to_owned().into_inner(),
     );
     like
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(DislikeType::Dislike)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -318,7 +318,7 @@ impl ApubLikeableType for Comment {
       like.into_any_base()?,
     );
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
index 96cb058a484a49cf4adaf207ea09397559ec27b6..fbc61fc05b232c209901cd3443b1a5befe70f272 100644 (file)
@@ -98,7 +98,7 @@ impl CommunityType for Community {
       follow.into_any_base()?,
     );
     accept
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(AcceptType::Accept)?)
       .set_to(person.actor_id());
 
@@ -117,7 +117,7 @@ impl CommunityType for Community {
         self.to_apub(context.pool()).await?.into_any_base()?,
       );
       update
-        .set_many_contexts(lemmy_context()?)
+        .set_many_contexts(lemmy_context())
         .set_id(generate_activity_id(UpdateType::Update)?)
         .set_to(public())
         .set_many_ccs(vec![self.actor_id()]);
@@ -134,7 +134,7 @@ impl CommunityType for Community {
     if self.local {
       let mut delete = Delete::new(self.actor_id(), self.actor_id());
       delete
-        .set_many_contexts(lemmy_context()?)
+        .set_many_contexts(lemmy_context())
         .set_id(generate_activity_id(DeleteType::Delete)?)
         .set_to(public())
         .set_many_ccs(vec![self.followers_url()]);
@@ -145,7 +145,7 @@ impl CommunityType for Community {
     else {
       let mut delete = Delete::new(mod_.actor_id(), self.actor_id());
       delete
-        .set_many_contexts(lemmy_context()?)
+        .set_many_contexts(lemmy_context())
         .set_id(generate_activity_id(DeleteType::Delete)?)
         .set_to(public())
         .set_many_ccs(vec![self.actor_id()]);
@@ -163,14 +163,14 @@ impl CommunityType for Community {
     if self.local {
       let mut delete = Delete::new(self.actor_id(), self.actor_id());
       delete
-        .set_many_contexts(lemmy_context()?)
+        .set_many_contexts(lemmy_context())
         .set_id(generate_activity_id(DeleteType::Delete)?)
         .set_to(public())
         .set_many_ccs(vec![self.followers_url()]);
 
       let mut undo = Undo::new(self.actor_id(), delete.into_any_base()?);
       undo
-        .set_many_contexts(lemmy_context()?)
+        .set_many_contexts(lemmy_context())
         .set_id(generate_activity_id(UndoType::Undo)?)
         .set_to(public())
         .set_many_ccs(vec![self.followers_url()]);
@@ -181,14 +181,14 @@ impl CommunityType for Community {
     else {
       let mut delete = Delete::new(mod_.actor_id(), self.actor_id());
       delete
-        .set_many_contexts(lemmy_context()?)
+        .set_many_contexts(lemmy_context())
         .set_id(generate_activity_id(DeleteType::Delete)?)
         .set_to(public())
         .set_many_ccs(vec![self.actor_id()]);
 
       let mut undo = Undo::new(mod_.actor_id(), delete.into_any_base()?);
       undo
-        .set_many_contexts(lemmy_context()?)
+        .set_many_contexts(lemmy_context())
         .set_id(generate_activity_id(UndoType::Undo)?)
         .set_to(public())
         .set_many_ccs(vec![self.actor_id()]);
@@ -202,7 +202,7 @@ impl CommunityType for Community {
   async fn send_remove(&self, context: &LemmyContext) -> Result<(), LemmyError> {
     let mut remove = Remove::new(self.actor_id(), self.actor_id());
     remove
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
       .set_many_ccs(vec![self.followers_url()]);
@@ -215,7 +215,7 @@ impl CommunityType for Community {
   async fn send_undo_remove(&self, context: &LemmyContext) -> Result<(), LemmyError> {
     let mut remove = Remove::new(self.actor_id(), self.actor_id());
     remove
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
       .set_many_ccs(vec![self.followers_url()]);
@@ -223,7 +223,7 @@ impl CommunityType for Community {
     // Undo that fake activity
     let mut undo = Undo::new(self.actor_id(), remove.into_any_base()?);
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(LikeType::Like)?)
       .set_to(public())
       .set_many_ccs(vec![self.followers_url()]);
@@ -267,7 +267,7 @@ impl CommunityType for Community {
     }
     let mut announce = Announce::new(self.actor_id(), activity);
     announce
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(AnnounceType::Announce)?)
       .set_to(public())
       .set_many_ccs(ccs);
@@ -306,7 +306,7 @@ impl CommunityType for Community {
   ) -> Result<(), LemmyError> {
     let mut add = Add::new(actor.actor_id(), added_mod.actor_id());
     add
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(AddType::Add)?)
       .set_to(public())
       .set_many_ccs(vec![self.actor_id()])
@@ -324,7 +324,7 @@ impl CommunityType for Community {
   ) -> Result<(), LemmyError> {
     let mut remove = Remove::new(actor.actor_id(), removed_mod.actor_id());
     remove
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
       .set_many_ccs(vec![self.actor_id()])
@@ -342,7 +342,7 @@ impl CommunityType for Community {
   ) -> Result<(), LemmyError> {
     let mut block = Block::new(actor.actor_id(), blocked_user.actor_id());
     block
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(BlockType::Block)?)
       .set_to(public())
       .set_many_ccs(vec![self.actor_id()]);
@@ -359,7 +359,7 @@ impl CommunityType for Community {
   ) -> Result<(), LemmyError> {
     let mut block = Block::new(actor.actor_id(), unblocked_user.actor_id());
     block
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(BlockType::Block)?)
       .set_to(public())
       .set_many_ccs(vec![self.actor_id()]);
@@ -367,7 +367,7 @@ impl CommunityType for Community {
     // Undo that fake activity
     let mut undo = Undo::new(actor.actor_id(), block.into_any_base()?);
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
       .set_many_ccs(vec![self.actor_id()]);
index a5e792512f7e90b7e39bdd80430734bf4a4b3636..b7b43c433d9d9eb2e2ccaa4c4d04c0cfdb117e4c 100644 (file)
@@ -78,7 +78,7 @@ impl UserType for Person {
 
     let mut follow = Follow::new(self.actor_id(), community.actor_id());
     follow
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(FollowType::Follow)?)
       .set_to(community.actor_id());
 
@@ -99,7 +99,7 @@ impl UserType for Person {
 
     let mut follow = Follow::new(self.actor_id(), community.actor_id());
     follow
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(FollowType::Follow)?)
       .set_to(community.actor_id());
 
@@ -109,7 +109,7 @@ impl UserType for Person {
       follow.into_any_base()?,
     );
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(community.actor_id());
 
index db96621b0176c9a01648728ab167798e25aa36e7..677e7845b99d44ef756778893c7d785fa2d75585 100644 (file)
@@ -54,7 +54,7 @@ impl ApubObjectType for Post {
       self.ap_id.to_owned().into_inner(),
     );
     delete
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -79,7 +79,7 @@ impl ApubObjectType for Post {
       self.ap_id.to_owned().into_inner(),
     );
     delete
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -90,7 +90,7 @@ impl ApubObjectType for Post {
       delete.into_any_base()?,
     );
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -111,7 +111,7 @@ impl ApubObjectType for Post {
       self.ap_id.to_owned().into_inner(),
     );
     remove
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -136,7 +136,7 @@ impl ApubObjectType for Post {
       self.ap_id.to_owned().into_inner(),
     );
     remove
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -147,7 +147,7 @@ impl ApubObjectType for Post {
       remove.into_any_base()?,
     );
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -171,7 +171,7 @@ impl ApubLikeableType for Post {
       self.ap_id.to_owned().into_inner(),
     );
     like
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(LikeType::Like)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -192,7 +192,7 @@ impl ApubLikeableType for Post {
       self.ap_id.to_owned().into_inner(),
     );
     dislike
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(DislikeType::Dislike)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -217,7 +217,7 @@ impl ApubLikeableType for Post {
       self.ap_id.to_owned().into_inner(),
     );
     like
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(LikeType::Like)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
@@ -228,7 +228,7 @@ impl ApubLikeableType for Post {
       like.into_any_base()?,
     );
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
       .set_many_ccs(vec![community.actor_id()]);
index d208b25d43ad5f0a1e5df14c3d6877a6f95f1239..67d0afcd31051066964cce2344c2b27c6443e784 100644 (file)
@@ -38,7 +38,7 @@ impl ApubObjectType for PrivateMessage {
     );
 
     create
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(CreateType::Create)?)
       .set_to(recipient.actor_id());
 
@@ -59,7 +59,7 @@ impl ApubObjectType for PrivateMessage {
       note.into_any_base()?,
     );
     update
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UpdateType::Update)?)
       .set_to(recipient.actor_id());
 
@@ -77,7 +77,7 @@ impl ApubObjectType for PrivateMessage {
       self.ap_id.to_owned().into_inner(),
     );
     delete
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(recipient.actor_id());
 
@@ -99,7 +99,7 @@ impl ApubObjectType for PrivateMessage {
       self.ap_id.to_owned().into_inner(),
     );
     delete
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(recipient.actor_id());
 
@@ -109,7 +109,7 @@ impl ApubObjectType for PrivateMessage {
       delete.into_any_base()?,
     );
     undo
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(recipient.actor_id());
 
index 08491dcbfd0491277d0e5383b23b8627761758c4..1d6f83bd74df9519d3454355cf506aeb18abc897 100644 (file)
@@ -1,9 +1,8 @@
-use activitystreams::{base::AnyBase, context};
-use lemmy_utils::LemmyError;
+use activitystreams::{base::AnyBase, context, primitives::OneOrMany};
 use serde_json::json;
 use url::Url;
 
-pub fn lemmy_context() -> Result<Vec<AnyBase>, LemmyError> {
+pub fn lemmy_context() -> OneOrMany<AnyBase> {
   let context_ext = AnyBase::from_arbitrary_json(json!(
   {
     "sc": "http://schema.org#",
@@ -19,10 +18,11 @@ pub fn lemmy_context() -> Result<Vec<AnyBase>, LemmyError> {
       "type": "sc:Text",
       "id": "as:alsoKnownAs"
     },
-  }))?;
-  Ok(vec![
+  }))
+  .expect("parse context");
+  OneOrMany::from(vec![
     AnyBase::from(context()),
     context_ext,
-    AnyBase::from(Url::parse("https://w3id.org/security/v1")?),
+    AnyBase::from(Url::parse("https://w3id.org/security/v1").expect("parse context")),
   ])
 }
index 3173bca12c75432b0bb4201b738590a112b2b966..6b264fad6aadca549a6abf9e0228e69d175639f0 100644 (file)
@@ -81,7 +81,7 @@ pub(crate) async fn get_apub_community_followers(
 
   let mut collection = UnorderedCollection::new();
   collection
-    .set_many_contexts(lemmy_context()?)
+    .set_many_contexts(lemmy_context())
     .set_id(community.followers_url.into())
     .set_total_items(community_followers.len() as u64);
   Ok(create_apub_response(&collection))
@@ -112,7 +112,7 @@ pub(crate) async fn get_apub_community_outbox(
   let mut collection = OrderedCollection::new();
   collection
     .set_many_items(activities)
-    .set_many_contexts(lemmy_context()?)
+    .set_many_contexts(lemmy_context())
     .set_id(community.get_outbox_url()?)
     .set_total_items(len as u64);
   Ok(create_apub_response(&collection))
@@ -130,7 +130,7 @@ pub(crate) async fn get_apub_community_inbox(
   let mut collection = OrderedCollection::new();
   collection
     .set_id(community.inbox_url.into())
-    .set_many_contexts(lemmy_context()?);
+    .set_many_contexts(lemmy_context());
   Ok(create_apub_response(&collection))
 }
 
@@ -162,6 +162,6 @@ pub(crate) async fn get_apub_community_moderators(
     .set_id(generate_moderators_url(&community.actor_id)?.into())
     .set_total_items(moderators.len() as u64)
     .set_many_items(moderators)
-    .set_many_contexts(lemmy_context()?);
+    .set_many_contexts(lemmy_context());
   Ok(create_apub_response(&collection))
 }
index 2c96aafd8fca32a71648178dc69f4110ed28c7bb..42f25bb629788c6f5e0fc0c8e039bbf6cbd6f54f 100644 (file)
@@ -71,7 +71,7 @@ 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_many_contexts(lemmy_context())
     .set_id(person.get_outbox_url()?)
     .set_total_items(0_u64);
   Ok(create_apub_response(&collection))
@@ -89,6 +89,6 @@ pub(crate) async fn get_apub_person_inbox(
   let mut collection = OrderedCollection::new();
   collection
     .set_id(person.inbox_url.into())
-    .set_many_contexts(lemmy_context()?);
+    .set_many_contexts(lemmy_context());
   Ok(create_apub_response(&collection))
 }
index 7b181eff4e9a326ffdf83a322b5ff7346d286308..8501ea2a73d9ac59888413cf98f74e25840a432d 100644 (file)
@@ -69,7 +69,7 @@ impl ToApub for Comment {
 
     comment
       // Not needed when the Post is embedded in a collection (like for community outbox)
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(self.ap_id.to_owned().into_inner())
       .set_published(convert_datetime(self.published))
       // NOTE: included community id for compatibility with lemmy v0.9.9
index 34a15793b9195aaa5d11101f4244af0f5ed20987..f9948588d5e9b6b322680ee1d3f8ee35fcf2f31d 100644 (file)
@@ -55,7 +55,7 @@ impl ToApub for Community {
 
     let mut group = ApObject::new(Group::new());
     group
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(self.actor_id.to_owned().into())
       .set_name(self.title.to_owned())
       .set_published(convert_datetime(self.published))
index c87fc043c97ed16311ef23193a5ff2d926e6b0e7..6a52673e6c0a883c2f591e19b2771f07c747a894 100644 (file)
@@ -70,6 +70,25 @@ pub trait FromApubToForm<ApubType> {
     Self: Sized;
 }
 
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+pub enum MediaTypeMarkdown {
+  #[serde(rename = "text/markdown")]
+  Markdown,
+}
+
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+pub enum MediaTypeHtml {
+  #[serde(rename = "text/html")]
+  Markdown,
+}
+
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct Source {
+  content: String,
+  media_type: MediaTypeMarkdown,
+}
+
 /// Updated is actually the deletion time
 fn create_tombstone<T>(
   deleted: bool,
index a508f4e088e872bb785dce1a3f659514a9527500..29935ec074adda9d3c16c3a3d9301b75f3234363 100644 (file)
@@ -50,7 +50,7 @@ impl ToApub for DbPerson {
     let mut person = ApObject::new(actor);
 
     person
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(self.actor_id.to_owned().into_inner())
       .set_published(convert_datetime(self.published));
 
index ace6b913121fd73329f340b1c6a0d2040f51f769..7c79ff88b8e77f5229db26151d954c375c8c7266 100644 (file)
@@ -2,7 +2,7 @@ use crate::{
   activities::extract_community,
   extensions::context::lemmy_context,
   fetcher::person::get_or_fetch_and_upsert_person,
-  objects::{create_tombstone, FromApub, ToApub},
+  objects::{create_tombstone, FromApub, MediaTypeHtml, MediaTypeMarkdown, Source, ToApub},
 };
 use activitystreams::{
   base::AnyBase,
@@ -34,84 +34,6 @@ use lemmy_utils::{
 use lemmy_websocket::LemmyContext;
 use url::Url;
 
-#[async_trait::async_trait(?Send)]
-impl ToApub for Post {
-  type ApubType = Page;
-
-  // Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
-  async fn to_apub(&self, pool: &DbPool) -> Result<Page, LemmyError> {
-    let creator_id = self.creator_id;
-    let creator = blocking(pool, move |conn| Person::read(conn, creator_id)).await??;
-    let community_id = self.community_id;
-    let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
-
-    let source = self.body.clone().map(|body| Source {
-      content: body,
-      media_type: MediaTypeMarkdown::Markdown,
-    });
-    let image = self.thumbnail_url.clone().map(|thumb| ImageObject {
-      content: ImageType::Image,
-      url: thumb.into(),
-    });
-
-    let page = Page {
-      context: lemmy_context()?.into(),
-      r#type: PageType::Page,
-      id: self.ap_id.clone().into(),
-      attributed_to: creator.actor_id.into(),
-      to: [community.actor_id.into(), public()],
-      name: self.name.clone(),
-      content: self.body.as_ref().map(|b| markdown_to_html(b)),
-      media_type: MediaTypeHtml::Markdown,
-      source,
-      url: self.url.clone().map(|u| u.into()),
-      image,
-      comments_enabled: Some(!self.locked),
-      sensitive: Some(self.nsfw),
-      stickied: Some(self.stickied),
-      published: convert_datetime(self.published),
-      updated: self.updated.map(convert_datetime),
-      unparsed: Default::default(),
-    };
-    Ok(page)
-  }
-
-  fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
-    create_tombstone(
-      self.deleted,
-      self.ap_id.to_owned().into(),
-      self.updated,
-      PageType::Page,
-    )
-  }
-}
-
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-pub enum MediaTypeMarkdown {
-  #[serde(rename = "text/markdown")]
-  Markdown,
-}
-
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-pub enum MediaTypeHtml {
-  #[serde(rename = "text/html")]
-  Markdown,
-}
-
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct Source {
-  content: String,
-  media_type: MediaTypeMarkdown,
-}
-
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ImageObject {
-  content: ImageType,
-  url: Url,
-}
-
 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
 #[serde(rename_all = "camelCase")]
 pub struct Page {
@@ -138,6 +60,13 @@ pub struct Page {
   unparsed: Unparsed,
 }
 
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ImageObject {
+  content: ImageType,
+  url: Url,
+}
+
 impl Page {
   /// Only mods can change the post's stickied/locked status. So if either of these is changed from
   /// the current value, it is a mod action and needs to be verified as such.
@@ -169,6 +98,58 @@ impl Page {
   }
 }
 
+#[async_trait::async_trait(?Send)]
+impl ToApub for Post {
+  type ApubType = Page;
+
+  // Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
+  async fn to_apub(&self, pool: &DbPool) -> Result<Page, LemmyError> {
+    let creator_id = self.creator_id;
+    let creator = blocking(pool, move |conn| Person::read(conn, creator_id)).await??;
+    let community_id = self.community_id;
+    let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
+
+    let source = self.body.clone().map(|body| Source {
+      content: body,
+      media_type: MediaTypeMarkdown::Markdown,
+    });
+    let image = self.thumbnail_url.clone().map(|thumb| ImageObject {
+      content: ImageType::Image,
+      url: thumb.into(),
+    });
+
+    let page = Page {
+      context: lemmy_context(),
+      r#type: PageType::Page,
+      id: self.ap_id.clone().into(),
+      attributed_to: creator.actor_id.into(),
+      to: [community.actor_id.into(), public()],
+      name: self.name.clone(),
+      content: self.body.as_ref().map(|b| markdown_to_html(b)),
+      media_type: MediaTypeHtml::Markdown,
+      source,
+      url: self.url.clone().map(|u| u.into()),
+      image,
+      comments_enabled: Some(!self.locked),
+      sensitive: Some(self.nsfw),
+      stickied: Some(self.stickied),
+      published: convert_datetime(self.published),
+      updated: self.updated.map(convert_datetime),
+      unparsed: Default::default(),
+    };
+    Ok(page)
+  }
+
+  fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
+    create_tombstone(
+      self.deleted,
+      self.ap_id.to_owned().into(),
+      self.updated,
+      PageType::Page,
+    )
+  }
+}
+
 #[async_trait::async_trait(?Send)]
 impl FromApub for Post {
   type ApubType = Page;
index 6bb4820f4cabcde25d4dce59ecd85e5ec6c81d25..624123ecf0cdd54c7fec76d820632c972dc9945f 100644 (file)
@@ -42,7 +42,7 @@ impl ToApub for PrivateMessage {
     let recipient = blocking(pool, move |conn| Person::read(conn, recipient_id)).await??;
 
     private_message
-      .set_many_contexts(lemmy_context()?)
+      .set_many_contexts(lemmy_context())
       .set_id(self.ap_id.to_owned().into_inner())
       .set_published(convert_datetime(self.published))
       .set_to(recipient.actor_id.into_inner())