]> Untitled Git - lemmy.git/commitdiff
Merge two functions into one
authorFelix Ableitner <me@nutomic.com>
Tue, 2 Nov 2021 13:02:39 +0000 (14:02 +0100)
committerFelix Ableitner <me@nutomic.com>
Tue, 2 Nov 2021 20:39:06 +0000 (21:39 +0100)
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/mod.rs
crates/apub/src/objects/community.rs

index 62e7c56fd5a15b3a006fe93c3049393111fb288a..f560b09f6e78b73b9af5fc00739218f1a78eae71 100644 (file)
@@ -1,11 +1,5 @@
 use crate::{
-  activities::{
-    community::list_community_follower_inboxes,
-    generate_activity_id,
-    send_lemmy_activity,
-    verify_activity,
-    verify_is_public,
-  },
+  activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_is_public},
   activity_lists::AnnouncableActivities,
   fetcher::object_id::ObjectId,
   http::is_activity_already_known,
@@ -50,7 +44,9 @@ impl AnnounceActivity {
       )?,
       unparsed: Default::default(),
     };
-    let inboxes = list_community_follower_inboxes(community, additional_inboxes, context).await?;
+    let inboxes = community
+      .get_follower_inboxes(additional_inboxes, context)
+      .await?;
     send_lemmy_activity(context, &announce, &announce.id, community, inboxes, false).await
   }
 }
index ebc6e7f9208d5496c3bbd0a74afed5550363000e..96e692d58c587e4d15ee26346de76ceb73baa369 100644 (file)
@@ -1,19 +1,15 @@
-use itertools::Itertools;
-use url::Url;
-
-use lemmy_apub_lib::traits::ActorType;
-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-
 use crate::{
   activities::send_lemmy_activity,
   activity_lists::AnnouncableActivities,
-  check_is_apub_id_valid,
   fetcher::object_id::ObjectId,
   insert_activity,
   objects::community::ApubCommunity,
   protocol::activities::community::announce::AnnounceActivity,
 };
+use lemmy_apub_lib::traits::ActorType;
+use lemmy_utils::LemmyError;
+use lemmy_websocket::LemmyContext;
+use url::Url;
 
 pub mod add_mod;
 pub mod announce;
@@ -23,28 +19,6 @@ pub mod report;
 pub mod undo_block_user;
 pub mod update;
 
-async fn list_community_follower_inboxes(
-  community: &ApubCommunity,
-  additional_inboxes: Vec<Url>,
-  context: &LemmyContext,
-) -> Result<Vec<Url>, LemmyError> {
-  Ok(
-    vec![
-      community
-        .get_follower_inboxes(context.pool(), &context.settings())
-        .await?,
-      additional_inboxes,
-    ]
-    .iter()
-    .flatten()
-    .unique()
-    .filter(|inbox| inbox.host_str() != Some(&context.settings().hostname))
-    .filter(|inbox| check_is_apub_id_valid(inbox, false, &context.settings()).is_ok())
-    .map(|inbox| inbox.to_owned())
-    .collect(),
-  )
-}
-
 pub(crate) async fn send_to_community<T: ActorType>(
   activity: AnnouncableActivities,
   activity_id: &Url,
index 89258fe0cee2e861cd008b96adbb179085797614..0947ebf371a8afd017fefbfd7780e3e2e0700b5b 100644 (file)
@@ -1,5 +1,3 @@
-use std::ops::Deref;
-
 use activitystreams::{
   actor::{kind::GroupType, Endpoints},
   object::kind::ImageType,
@@ -7,22 +5,9 @@ use activitystreams::{
 use chrono::NaiveDateTime;
 use itertools::Itertools;
 use log::debug;
+use std::ops::Deref;
 use url::Url;
 
-use lemmy_api_common::blocking;
-use lemmy_apub_lib::{
-  traits::{ActorType, ApubObject},
-  values::MediaTypeMarkdown,
-};
-use lemmy_db_schema::{source::community::Community, DbPool};
-use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
-use lemmy_utils::{
-  settings::structs::Settings,
-  utils::{convert_datetime, markdown_to_html},
-  LemmyError,
-};
-use lemmy_websocket::LemmyContext;
-
 use crate::{
   check_is_apub_id_valid,
   collections::{community_moderators::ApubCommunityModerators, CommunityContext},
@@ -35,6 +20,18 @@ use crate::{
     Source,
   },
 };
+use lemmy_api_common::blocking;
+use lemmy_apub_lib::{
+  traits::{ActorType, ApubObject},
+  values::MediaTypeMarkdown,
+};
+use lemmy_db_schema::source::community::Community;
+use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
+use lemmy_utils::{
+  utils::{convert_datetime, markdown_to_html},
+  LemmyError,
+};
+use lemmy_websocket::LemmyContext;
 
 #[derive(Clone, Debug)]
 pub struct ApubCommunity(Community);
@@ -198,23 +195,28 @@ impl ApubCommunity {
   /// For a given community, returns the inboxes of all followers.
   pub(crate) async fn get_follower_inboxes(
     &self,
-    pool: &DbPool,
-    settings: &Settings,
+    additional_inboxes: Vec<Url>,
+    context: &LemmyContext,
   ) -> Result<Vec<Url>, LemmyError> {
     let id = self.id;
 
-    let follows = blocking(pool, move |conn| {
+    let follows = blocking(context.pool(), move |conn| {
       CommunityFollowerView::for_community(conn, id)
     })
     .await??;
-    let inboxes = follows
+    let follower_inboxes: Vec<Url> = follows
       .into_iter()
       .filter(|f| !f.follower.local)
       .map(|f| f.follower.shared_inbox_url.unwrap_or(f.follower.inbox_url))
       .map(|i| i.into_inner())
+      .collect();
+    let inboxes = vec![follower_inboxes, additional_inboxes]
+      .into_iter()
+      .flatten()
       .unique()
+      .filter(|inbox| inbox.host_str() != Some(&context.settings().hostname))
       // Don't send to blocked instances
-      .filter(|inbox| check_is_apub_id_valid(inbox, false, settings).is_ok())
+      .filter(|inbox| check_is_apub_id_valid(inbox, false, &context.settings()).is_ok())
       .collect();
 
     Ok(inboxes)