From: Felix Ableitner Date: Mon, 15 Mar 2021 12:58:54 +0000 (+0100) Subject: Insert announced activities into DB for fetching (fixes #1494) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/readmes/%7B%7D/%22%7Burl%7D/%7Bthis.src%28%27jpg%27%29%7D?a=commitdiff_plain;h=621355b6ef3c83ddc2f334da30ebc4a8487c9d57;p=lemmy.git Insert announced activities into DB for fetching (fixes #1494) --- diff --git a/crates/apub/src/activities/send/community.rs b/crates/apub/src/activities/send/community.rs index 3e77248f..185f4b57 100644 --- a/crates/apub/src/activities/send/community.rs +++ b/crates/apub/src/activities/send/community.rs @@ -4,6 +4,7 @@ use crate::{ check_is_apub_id_valid, extensions::context::lemmy_context, fetcher::user::get_or_fetch_and_upsert_user, + insert_activity, ActorType, }; use activitystreams::{ @@ -27,7 +28,7 @@ use lemmy_api_structs::blocking; use lemmy_db_queries::DbPool; use lemmy_db_schema::source::community::Community; use lemmy_db_views_actor::community_follower_view::CommunityFollowerView; -use lemmy_utils::{location_info, LemmyError}; +use lemmy_utils::{location_info, settings::structs::Settings, LemmyError}; use lemmy_websocket::LemmyContext; use url::Url; @@ -164,11 +165,20 @@ impl ActorType for Community { /// Wraps an activity sent to the community in an announce, and then sends the announce to all /// community followers. + /// + /// If we are announcing a local activity, it hasn't been stored in the database yet, and we need + /// to do it here, so that it can be fetched by ID. Remote activities are inserted into DB in the + /// inbox. async fn send_announce( &self, activity: AnyBase, context: &LemmyContext, ) -> Result<(), LemmyError> { + let inner_id = activity.id().context(location_info!())?; + if inner_id.domain() == Some(&Settings::get().get_hostname_without_port()?) { + insert_activity(inner_id, activity.clone(), true, false, context.pool()).await?; + } + let mut announce = Announce::new(self.actor_id.to_owned().into_inner(), activity); announce .set_many_contexts(lemmy_context()?)