]> Untitled Git - lemmy.git/commitdiff
Change the way that `to` is set in apub
authorFelix Ableitner <me@nutomic.com>
Mon, 12 Oct 2020 16:02:28 +0000 (18:02 +0200)
committerFelix Ableitner <me@nutomic.com>
Mon, 12 Oct 2020 16:02:28 +0000 (18:02 +0200)
16 files changed:
lemmy_apub/src/activities/receive/announce.rs
lemmy_apub/src/activities/receive/create.rs
lemmy_apub/src/activities/receive/delete.rs
lemmy_apub/src/activities/receive/dislike.rs
lemmy_apub/src/activities/receive/like.rs
lemmy_apub/src/activities/receive/mod.rs
lemmy_apub/src/activities/receive/remove.rs
lemmy_apub/src/activities/receive/undo.rs
lemmy_apub/src/activities/receive/undo_comment.rs
lemmy_apub/src/activities/receive/undo_post.rs
lemmy_apub/src/activities/receive/update.rs
lemmy_apub/src/activities/send/comment.rs
lemmy_apub/src/activities/send/post.rs
lemmy_apub/src/activities/send/private_message.rs
lemmy_apub/src/activity_queue.rs
lemmy_apub/src/inbox/shared_inbox.rs

index a553c190dbc7176f09d78c9993dd6d29541e6a07..50c2ed9d697521ad13c14d0ba9576f759e5641d1 100644 (file)
@@ -1,15 +1,12 @@
-use crate::{
-  activities::receive::{
-    create::receive_create,
-    delete::receive_delete,
-    dislike::receive_dislike,
-    like::receive_like,
-    receive_unhandled_activity,
-    remove::receive_remove,
-    undo::receive_undo,
-    update::receive_update,
-  },
-  inbox::shared_inbox::get_community_id_from_activity,
+use crate::activities::receive::{
+  create::receive_create,
+  delete::receive_delete,
+  dislike::receive_dislike,
+  like::receive_like,
+  receive_unhandled_activity,
+  remove::receive_remove,
+  undo::receive_undo,
+  update::receive_update,
 };
 use activitystreams::{
   activity::*,
@@ -28,8 +25,12 @@ pub async fn receive_announce(
   let announce = Announce::from_any_base(activity)?.context(location_info!())?;
 
   // ensure that announce and community come from the same instance
-  let community = get_community_id_from_activity(&announce)?;
-  announce.id(community.domain().context(location_info!())?)?;
+  let community_id = announce
+    .actor()?
+    .to_owned()
+    .single_xsd_any_uri()
+    .context(location_info!())?;
+  announce.id(community_id.domain().context(location_info!())?)?;
 
   let kind = announce.object().as_single_kind_str();
   let object = announce.object();
index 4911088d041b2b5868caf116c84c566ef612efc7..201d620ba1c205c57efd99059752c8fbd9c7ecfe 100644 (file)
@@ -1,6 +1,9 @@
 use crate::{
-  activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
-  inbox::shared_inbox::get_user_from_activity,
+  activities::receive::{
+    announce_if_community_is_local,
+    get_actor_as_user,
+    receive_unhandled_activity,
+  },
   ActorType,
   FromApub,
   PageExt,
@@ -29,7 +32,7 @@ pub async fn receive_create(
   let create = Create::from_any_base(activity)?.context(location_info!())?;
 
   // ensure that create and actor come from the same instance
-  let user = get_user_from_activity(&create, context).await?;
+  let user = get_actor_as_user(&create, context).await?;
   create.id(user.actor_id()?.domain().context(location_info!())?)?;
 
   match create.object().as_single_kind_str() {
@@ -43,7 +46,7 @@ async fn receive_create_post(
   create: Create,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(&create, context).await?;
+  let user = get_actor_as_user(&create, context).await?;
   let page = PageExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -76,7 +79,7 @@ async fn receive_create_comment(
   create: Create,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(&create, context).await?;
+  let user = get_actor_as_user(&create, context).await?;
   let note = Note::from_any_base(create.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
index 1490ce9182b2896abe24b5d2da4eb1723ab4bf6c..a1985881e9f79645f089b3630b6107bd6d64a146 100644 (file)
@@ -1,7 +1,10 @@
 use crate::{
-  activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
+  activities::receive::{
+    announce_if_community_is_local,
+    get_actor_as_user,
+    receive_unhandled_activity,
+  },
   fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
-  inbox::shared_inbox::get_user_from_activity,
   ActorType,
   FromApub,
   GroupExt,
@@ -50,7 +53,7 @@ async fn receive_delete_post(
   delete: Delete,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(&delete, context).await?;
+  let user = get_actor_as_user(&delete, context).await?;
   let page = PageExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -109,7 +112,7 @@ async fn receive_delete_comment(
   delete: Delete,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(&delete, context).await?;
+  let user = get_actor_as_user(&delete, context).await?;
   let note = Note::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -169,7 +172,7 @@ async fn receive_delete_community(
 ) -> Result<HttpResponse, LemmyError> {
   let group = GroupExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
-  let user = get_user_from_activity(&delete, context).await?;
+  let user = get_actor_as_user(&delete, context).await?;
 
   let community_actor_id = CommunityForm::from_apub(&group, context, Some(user.actor_id()?))
     .await?
index e794148041be12e1c6ab5e71bf968a64ac8e748b..1007e615415383cb726a05c7538481a20d0e7f65 100644 (file)
@@ -1,7 +1,10 @@
 use crate::{
-  activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
+  activities::receive::{
+    announce_if_community_is_local,
+    get_actor_as_user,
+    receive_unhandled_activity,
+  },
   fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
-  inbox::shared_inbox::get_user_from_activity,
   FromApub,
   PageExt,
 };
@@ -49,7 +52,7 @@ async fn receive_dislike_post(
   dislike: Dislike,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(&dislike, context).await?;
+  let user = get_actor_as_user(&dislike, context).await?;
   let page = PageExt::from_any_base(
     dislike
       .object()
@@ -107,7 +110,7 @@ async fn receive_dislike_comment(
       .context(location_info!())?,
   )?
   .context(location_info!())?;
-  let user = get_user_from_activity(&dislike, context).await?;
+  let user = get_actor_as_user(&dislike, context).await?;
 
   let comment = CommentForm::from_apub(&note, context, None).await?;
 
index 3000e512d18fd72b35e7f9972fe8d28d27511967..ef53e7918ed57a362fb767ffcac14b6cf0b8ca68 100644 (file)
@@ -1,7 +1,10 @@
 use crate::{
-  activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
+  activities::receive::{
+    announce_if_community_is_local,
+    get_actor_as_user,
+    receive_unhandled_activity,
+  },
   fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
-  inbox::shared_inbox::get_user_from_activity,
   FromApub,
   PageExt,
 };
@@ -36,7 +39,7 @@ pub async fn receive_like(
 }
 
 async fn receive_like_post(like: Like, context: &LemmyContext) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(&like, context).await?;
+  let user = get_actor_as_user(&like, context).await?;
   let page = PageExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -82,7 +85,7 @@ async fn receive_like_comment(
 ) -> Result<HttpResponse, LemmyError> {
   let note = Note::from_any_base(like.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
-  let user = get_user_from_activity(&like, context).await?;
+  let user = get_actor_as_user(&like, context).await?;
 
   let comment = CommentForm::from_apub(&note, context, None).await?;
 
index b765b03e975e7c0f4fbc5d8085ca4c331717d832..06c5f291abc4d3e977229539d8794939bac80c1a 100644 (file)
@@ -1,6 +1,10 @@
-use crate::{fetcher::get_or_fetch_and_upsert_community, ActorType};
+use crate::{
+  fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
+  ActorType,
+};
 use activitystreams::{
-  base::{Extends, ExtendsExt},
+  activity::{ActorAndObjectRef, ActorAndObjectRefExt},
+  base::{AsBase, Extends, ExtendsExt},
   object::{AsObject, ObjectExt},
 };
 use actix_web::HttpResponse;
@@ -63,3 +67,15 @@ where
   }
   Ok(())
 }
+
+pub(in crate) async fn get_actor_as_user<T, A>(
+  activity: &T,
+  context: &LemmyContext,
+) -> Result<User_, LemmyError>
+where
+  T: AsBase<A> + ActorAndObjectRef,
+{
+  let actor = activity.actor()?;
+  let user_uri = actor.as_single_xsd_any_uri().context(location_info!())?;
+  get_or_fetch_and_upsert_user(&user_uri, context).await
+}
index 09cfd081385981dad4dca5a23f52efc0b3724642..dfd166e6cdc9110446a0ef1f9371d8addbe1ce4f 100644 (file)
@@ -1,7 +1,10 @@
 use crate::{
-  activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
+  activities::receive::{
+    announce_if_community_is_local,
+    get_actor_as_user,
+    receive_unhandled_activity,
+  },
   fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
-  inbox::shared_inbox::{get_community_id_from_activity, get_user_from_activity},
   ActorType,
   FromApub,
   GroupExt,
@@ -38,9 +41,18 @@ pub async fn receive_remove(
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
   let remove = Remove::from_any_base(activity)?.context(location_info!())?;
-  let actor = get_user_from_activity(&remove, context).await?;
-  let community = get_community_id_from_activity(&remove)?;
-  if actor.actor_id()?.domain() != community.domain() {
+  let actor = get_actor_as_user(&remove, context).await?;
+  let cc = remove
+    .cc()
+    .map(|c| c.as_many())
+    .flatten()
+    .context(location_info!())?;
+  let community_id = cc
+    .first()
+    .map(|c| c.as_xsd_any_uri())
+    .flatten()
+    .context(location_info!())?;
+  if actor.actor_id()?.domain() != community_id.domain() {
     return Err(anyhow!("Remove receive are only allowed on local objects").into());
   }
 
@@ -56,7 +68,7 @@ async fn receive_remove_post(
   remove: Remove,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let mod_ = get_user_from_activity(&remove, context).await?;
+  let mod_ = get_actor_as_user(&remove, context).await?;
   let page = PageExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -115,7 +127,7 @@ async fn receive_remove_comment(
   remove: Remove,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let mod_ = get_user_from_activity(&remove, context).await?;
+  let mod_ = get_actor_as_user(&remove, context).await?;
   let note = Note::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -173,7 +185,7 @@ async fn receive_remove_community(
   remove: Remove,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let mod_ = get_user_from_activity(&remove, context).await?;
+  let mod_ = get_actor_as_user(&remove, context).await?;
   let group = GroupExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
index 0880c3f682bfd6e9244046e7f750c9c02e5f85f0..95a73950512148e405488f33194f4aff36dd9a84 100644 (file)
@@ -1,11 +1,11 @@
 use crate::{
   activities::receive::{
     announce_if_community_is_local,
+    get_actor_as_user,
     receive_unhandled_activity,
     undo_comment::*,
     undo_post::*,
   },
-  inbox::shared_inbox::get_user_from_activity,
   ActorType,
   FromApub,
   GroupExt,
@@ -141,7 +141,7 @@ async fn receive_undo_delete_community(
   delete: &Delete,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(delete, context).await?;
+  let user = get_actor_as_user(delete, context).await?;
   let group = GroupExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -207,7 +207,7 @@ async fn receive_undo_remove_community(
   remove: &Remove,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let mod_ = get_user_from_activity(remove, context).await?;
+  let mod_ = get_actor_as_user(remove, context).await?;
   let group = GroupExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
index 8ff805e93fb7fe6cff57fd86b28feb41904c0649..d7566827d9b2869fdc670051465190c0afd45b1f 100644 (file)
@@ -1,7 +1,6 @@
 use crate::{
-  activities::receive::announce_if_community_is_local,
+  activities::receive::{announce_if_community_is_local, get_actor_as_user},
   fetcher::get_or_fetch_and_insert_comment,
-  inbox::shared_inbox::get_user_from_activity,
   ActorType,
   FromApub,
 };
@@ -24,7 +23,7 @@ pub(crate) async fn receive_undo_like_comment(
   like: &Like,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(like, context).await?;
+  let user = get_actor_as_user(like, context).await?;
   let note = Note::from_any_base(like.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -69,7 +68,7 @@ pub(crate) async fn receive_undo_dislike_comment(
   dislike: &Dislike,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(dislike, context).await?;
+  let user = get_actor_as_user(dislike, context).await?;
   let note = Note::from_any_base(
     dislike
       .object()
@@ -120,7 +119,7 @@ pub(crate) async fn receive_undo_delete_comment(
   delete: &Delete,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(delete, context).await?;
+  let user = get_actor_as_user(delete, context).await?;
   let note = Note::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -179,7 +178,7 @@ pub(crate) async fn receive_undo_remove_comment(
   remove: &Remove,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let mod_ = get_user_from_activity(remove, context).await?;
+  let mod_ = get_actor_as_user(remove, context).await?;
   let note = Note::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
index 00527a102d5322dfd75270e76e2080b71ced7f7a..3eebb08ec9391c01ade5c78debd0fb2db111e49c 100644 (file)
@@ -1,7 +1,6 @@
 use crate::{
-  activities::receive::announce_if_community_is_local,
+  activities::receive::{announce_if_community_is_local, get_actor_as_user},
   fetcher::get_or_fetch_and_insert_post,
-  inbox::shared_inbox::get_user_from_activity,
   ActorType,
   FromApub,
   PageExt,
@@ -25,7 +24,7 @@ pub(crate) async fn receive_undo_like_post(
   like: &Like,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(like, context).await?;
+  let user = get_actor_as_user(like, context).await?;
   let page = PageExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -64,7 +63,7 @@ pub(crate) async fn receive_undo_dislike_post(
   dislike: &Dislike,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(dislike, context).await?;
+  let user = get_actor_as_user(dislike, context).await?;
   let page = PageExt::from_any_base(
     dislike
       .object()
@@ -109,7 +108,7 @@ pub(crate) async fn receive_undo_delete_post(
   delete: &Delete,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(delete, context).await?;
+  let user = get_actor_as_user(delete, context).await?;
   let page = PageExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -169,7 +168,7 @@ pub(crate) async fn receive_undo_remove_post(
   remove: &Remove,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let mod_ = get_user_from_activity(remove, context).await?;
+  let mod_ = get_actor_as_user(remove, context).await?;
   let page = PageExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
index a18c6fe9220f5612c547e0a2c9fd46ee3ff5eb99..0dd21ef5acbe1717f9ad5895d04c0f08c87dfacc 100644 (file)
@@ -1,7 +1,10 @@
 use crate::{
-  activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
+  activities::receive::{
+    announce_if_community_is_local,
+    get_actor_as_user,
+    receive_unhandled_activity,
+  },
   fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
-  inbox::shared_inbox::get_user_from_activity,
   ActorType,
   FromApub,
   PageExt,
@@ -31,7 +34,7 @@ pub async fn receive_update(
   let update = Update::from_any_base(activity)?.context(location_info!())?;
 
   // ensure that update and actor come from the same instance
-  let user = get_user_from_activity(&update, context).await?;
+  let user = get_actor_as_user(&update, context).await?;
   update.id(user.actor_id()?.domain().context(location_info!())?)?;
 
   match update.object().as_single_kind_str() {
@@ -45,7 +48,7 @@ async fn receive_update_post(
   update: Update,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  let user = get_user_from_activity(&update, context).await?;
+  let user = get_actor_as_user(&update, context).await?;
   let page = PageExt::from_any_base(update.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
 
@@ -84,7 +87,7 @@ async fn receive_update_comment(
 ) -> Result<HttpResponse, LemmyError> {
   let note = Note::from_any_base(update.object().to_owned().one().context(location_info!())?)?
     .context(location_info!())?;
-  let user = get_user_from_activity(&update, context).await?;
+  let user = get_actor_as_user(&update, context).await?;
 
   let comment = CommentForm::from_apub(&note, context, Some(user.actor_id()?)).await?;
 
index af31dc433a6b562cfd9e622750fd68a9b6a7c347..092d7ef3d9c35fb668ba2b8a2520c01e56009de7 100644 (file)
@@ -54,14 +54,17 @@ impl ApubObjectType for Comment {
     })
     .await??;
 
-    let maa = collect_non_local_mentions_and_addresses(&self.content, &community, context).await?;
+    let mut maa =
+      collect_non_local_mentions_and_addresses(&self.content, &community, context).await?;
+    let mut ccs = vec![community.actor_id()?];
+    ccs.append(&mut maa.addressed_ccs);
 
     let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
     create
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(CreateType::Create)?)
       .set_to(public())
-      .set_many_ccs(maa.addressed_ccs.to_owned())
+      .set_many_ccs(ccs)
       // Set the mention tags
       .set_many_tags(maa.get_tags()?);
 
@@ -83,14 +86,17 @@ impl ApubObjectType for Comment {
     })
     .await??;
 
-    let maa = collect_non_local_mentions_and_addresses(&self.content, &community, context).await?;
+    let mut maa =
+      collect_non_local_mentions_and_addresses(&self.content, &community, context).await?;
+    let mut ccs = vec![community.actor_id()?];
+    ccs.append(&mut maa.addressed_ccs);
 
     let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
     update
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UpdateType::Update)?)
       .set_to(public())
-      .set_many_ccs(maa.addressed_ccs.to_owned())
+      .set_many_ccs(ccs)
       // Set the mention tags
       .set_many_tags(maa.get_tags()?);
 
@@ -116,7 +122,7 @@ impl ApubObjectType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&creator, &community, delete, context).await?;
     Ok(())
@@ -144,7 +150,7 @@ impl ApubObjectType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     // Undo that fake activity
     let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
@@ -152,7 +158,7 @@ impl ApubObjectType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&creator, &community, undo, context).await?;
     Ok(())
@@ -175,7 +181,7 @@ impl ApubObjectType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&mod_, &community, remove, context).await?;
     Ok(())
@@ -199,7 +205,7 @@ impl ApubObjectType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     // Undo that fake activity
     let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
@@ -207,7 +213,7 @@ impl ApubObjectType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&mod_, &community, undo, context).await?;
     Ok(())
@@ -233,7 +239,7 @@ impl ApubLikeableType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(LikeType::Like)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&creator, &community, like, context).await?;
     Ok(())
@@ -256,7 +262,7 @@ impl ApubLikeableType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(DislikeType::Dislike)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&creator, &community, dislike, context).await?;
     Ok(())
@@ -283,7 +289,7 @@ impl ApubLikeableType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(DislikeType::Dislike)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     // Undo that fake activity
     let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
@@ -291,7 +297,7 @@ impl ApubLikeableType for Comment {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&creator, &community, undo, context).await?;
     Ok(())
index f7c27964cb6b8fef533fac652002f0b0f72e6863..81d1a954cac7f2411c569bc318bb16fa33e2e744 100644 (file)
@@ -42,7 +42,7 @@ impl ApubObjectType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(CreateType::Create)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(creator, &community, create, context).await?;
     Ok(())
@@ -63,7 +63,7 @@ impl ApubObjectType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UpdateType::Update)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(creator, &community, update, context).await?;
     Ok(())
@@ -83,7 +83,7 @@ impl ApubObjectType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(creator, &community, delete, context).await?;
     Ok(())
@@ -107,7 +107,7 @@ impl ApubObjectType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     // Undo that fake activity
     let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
@@ -115,7 +115,7 @@ impl ApubObjectType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(creator, &community, undo, context).await?;
     Ok(())
@@ -135,7 +135,7 @@ impl ApubObjectType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(mod_, &community, remove, context).await?;
     Ok(())
@@ -155,7 +155,7 @@ impl ApubObjectType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(RemoveType::Remove)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     // Undo that fake activity
     let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
@@ -163,7 +163,7 @@ impl ApubObjectType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(mod_, &community, undo, context).await?;
     Ok(())
@@ -186,7 +186,7 @@ impl ApubLikeableType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(LikeType::Like)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&creator, &community, like, context).await?;
     Ok(())
@@ -206,7 +206,7 @@ impl ApubLikeableType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(DislikeType::Dislike)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&creator, &community, dislike, context).await?;
     Ok(())
@@ -230,7 +230,7 @@ impl ApubLikeableType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(LikeType::Like)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     // Undo that fake activity
     let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
@@ -238,7 +238,7 @@ impl ApubLikeableType for Post {
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UndoType::Undo)?)
       .set_to(public())
-      .set_many_ccs(vec![community.get_followers_url()?]);
+      .set_many_ccs(vec![community.actor_id()?]);
 
     send_to_community(&creator, &community, undo, context).await?;
     Ok(())
index 8c3f5aa9ce91be982b1b166d3112a73fa9279f35..fc3e52252922c778610d57712ec5356060a43e1e 100644 (file)
@@ -30,13 +30,13 @@ impl ApubObjectType for PrivateMessage {
     let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
 
     let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
-    let to = recipient.get_inbox_url()?;
+
     create
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(CreateType::Create)?)
-      .set_to(to.clone());
+      .set_to(recipient.actor_id()?);
 
-    send_activity_single_dest(create, creator, to, context).await?;
+    send_activity_single_dest(create, creator, recipient.get_inbox_url()?, context).await?;
     Ok(())
   }
 
@@ -48,13 +48,12 @@ impl ApubObjectType for PrivateMessage {
     let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
 
     let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
-    let to = recipient.get_inbox_url()?;
     update
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UpdateType::Update)?)
-      .set_to(to.clone());
+      .set_to(recipient.actor_id()?);
 
-    send_activity_single_dest(update, creator, to, context).await?;
+    send_activity_single_dest(update, creator, recipient.get_inbox_url()?, context).await?;
     Ok(())
   }
 
@@ -65,13 +64,12 @@ impl ApubObjectType for PrivateMessage {
     let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
 
     let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
-    let to = recipient.get_inbox_url()?;
     delete
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
-      .set_to(to.clone());
+      .set_to(recipient.actor_id()?);
 
-    send_activity_single_dest(delete, creator, to, context).await?;
+    send_activity_single_dest(delete, creator, recipient.get_inbox_url()?, context).await?;
     Ok(())
   }
 
@@ -86,20 +84,19 @@ impl ApubObjectType for PrivateMessage {
     let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
 
     let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
-    let to = recipient.get_inbox_url()?;
     delete
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(DeleteType::Delete)?)
-      .set_to(to.clone());
+      .set_to(recipient.actor_id()?);
 
     // Undo that fake activity
     let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
     undo
       .set_context(activitystreams::context())
       .set_id(generate_activity_id(UndoType::Undo)?)
-      .set_to(to.clone());
+      .set_to(recipient.actor_id()?);
 
-    send_activity_single_dest(undo, creator, to, context).await?;
+    send_activity_single_dest(undo, creator, recipient.get_inbox_url()?, context).await?;
     Ok(())
   }
 
index 379618f298c2bb35543cd75ffde6f708868f4ec1..715c530449f7f7045a0bd5c0eae3b35634aaee58 100644 (file)
@@ -31,7 +31,7 @@ use url::Url;
 pub async fn send_activity_single_dest<T, Kind>(
   activity: T,
   creator: &dyn ActorType,
-  to: Url,
+  inbox: Url,
   context: &LemmyContext,
 ) -> Result<(), LemmyError>
 where
@@ -39,13 +39,17 @@ where
   Kind: Serialize,
   <T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
 {
-  if check_is_apub_id_valid(&to).is_ok() {
-    debug!("Sending activity {:?} to {}", &activity.id_unchecked(), &to);
+  if check_is_apub_id_valid(&inbox).is_ok() {
+    debug!(
+      "Sending activity {:?} to {}",
+      &activity.id_unchecked(),
+      &inbox
+    );
     send_activity_internal(
       context.activity_queue(),
       activity,
       creator,
-      vec![to],
+      vec![inbox],
       context.pool(),
       true,
     )
@@ -69,7 +73,7 @@ where
   // dont send to the local instance, nor to the instance where the activity originally came from,
   // because that would result in a database error (same data inserted twice)
   let community_shared_inbox = community.get_shared_inbox_url()?;
-  let to: Vec<Url> = community
+  let follower_inboxes: Vec<Url> = community
     .get_follower_inboxes(context.pool())
     .await?
     .iter()
@@ -89,7 +93,7 @@ where
     context.activity_queue(),
     activity,
     community,
-    to,
+    follower_inboxes,
     context.pool(),
     true,
   )
@@ -177,7 +181,7 @@ async fn send_activity_internal<T, Kind>(
   activity_sender: &QueueHandle,
   activity: T,
   actor: &dyn ActorType,
-  to: Vec<Url>,
+  inboxes: Vec<Url>,
   pool: &DbPool,
   insert_into_db: bool,
 ) -> Result<(), LemmyError>
@@ -186,7 +190,7 @@ where
   Kind: Serialize,
   <T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
 {
-  if !Settings::get().federation.enabled || to.is_empty() {
+  if !Settings::get().federation.enabled || inboxes.is_empty() {
     return Ok(());
   }
 
@@ -199,10 +203,10 @@ where
     insert_activity(actor.user_id(), activity.clone(), true, pool).await?;
   }
 
-  for t in to {
+  for i in inboxes {
     let message = SendActivityTask {
       activity: serialised_activity.to_owned(),
-      to: t,
+      inbox: i,
       actor_id: actor.actor_id()?,
       private_key: actor.private_key().context(location_info!())?,
     };
@@ -215,7 +219,7 @@ where
 #[derive(Clone, Debug, Deserialize, Serialize)]
 struct SendActivityTask {
   activity: String,
-  to: Url,
+  inbox: Url,
   actor_id: Url,
   private_key: String,
 }
@@ -235,7 +239,7 @@ impl ActixJob for SendActivityTask {
       let result = sign_and_send(
         &state.client,
         headers,
-        &self.to,
+        &self.inbox,
         self.activity.clone(),
         &self.actor_id,
         self.private_key.to_owned(),
@@ -247,7 +251,7 @@ impl ActixJob for SendActivityTask {
         return Err(anyhow!(
           "Failed to send activity {} to {}",
           &self.activity,
-          self.to
+          self.inbox
         ));
       }
       Ok(())
index c8ce9cdfec88fffca789d001d98679aff9ac066b..5b87e0f89bf3ade91e53c463f467cb056b4905ba 100644 (file)
@@ -11,24 +11,17 @@ use crate::{
   },
   check_is_apub_id_valid,
   extensions::signatures::verify,
-  fetcher::{get_or_fetch_and_upsert_actor, get_or_fetch_and_upsert_user},
+  fetcher::get_or_fetch_and_upsert_actor,
   insert_activity,
 };
-use activitystreams::{
-  activity::{ActorAndObject, ActorAndObjectRef},
-  base::AsBase,
-  object::AsObject,
-  prelude::*,
-};
+use activitystreams::{activity::ActorAndObject, prelude::*};
 use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::Context;
-use lemmy_db::user::User_;
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
 use log::debug;
 use serde::{Deserialize, Serialize};
 use std::fmt::Debug;
-use url::Url;
 
 #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
 #[serde(rename_all = "PascalCase")]
@@ -55,22 +48,20 @@ pub async fn shared_inbox(
 ) -> Result<HttpResponse, LemmyError> {
   let activity = input.into_inner();
 
-  let sender = &activity
+  let actor = activity
     .actor()?
     .to_owned()
     .single_xsd_any_uri()
     .context(location_info!())?;
-  let community = get_community_id_from_activity(&activity)?;
   debug!(
     "Shared inbox received activity {:?} from {}",
     &activity.id_unchecked(),
-    &sender
+    &actor
   );
 
-  check_is_apub_id_valid(sender)?;
-  check_is_apub_id_valid(&community)?;
+  check_is_apub_id_valid(&actor)?;
 
-  let actor = get_or_fetch_and_upsert_actor(sender, &context).await?;
+  let actor = get_or_fetch_and_upsert_actor(&actor, &context).await?;
   verify(&request, actor.as_ref())?;
 
   let any_base = activity.clone().into_any_base()?;
@@ -89,30 +80,3 @@ pub async fn shared_inbox(
   insert_activity(actor.user_id(), activity.clone(), false, context.pool()).await?;
   res
 }
-
-pub(in crate) async fn get_user_from_activity<T, A>(
-  activity: &T,
-  context: &LemmyContext,
-) -> Result<User_, LemmyError>
-where
-  T: AsBase<A> + ActorAndObjectRef,
-{
-  let actor = activity.actor()?;
-  let user_uri = actor.as_single_xsd_any_uri().context(location_info!())?;
-  get_or_fetch_and_upsert_user(&user_uri, context).await
-}
-
-pub(in crate) fn get_community_id_from_activity<T, A>(activity: &T) -> Result<Url, LemmyError>
-where
-  T: AsBase<A> + ActorAndObjectRef + AsObject<A>,
-{
-  let cc = activity.cc().context(location_info!())?;
-  let cc = cc.as_many().context(location_info!())?;
-  Ok(
-    cc.first()
-      .context(location_info!())?
-      .as_xsd_any_uri()
-      .context(location_info!())?
-      .to_owned(),
-  )
-}