Merge pull request 'Insert announced activities into DB for fetching (fixes #1494)' (#187) from insert-local-announce into main

Reviewed-on: https://yerbamate.ml/LemmyNet/lemmy/pulls/187
This commit is contained in:
dessalines 2021-03-16 13:47:32 +00:00
commit db4fe8031c
5 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,4 @@
version: '3.3' version: '2.2'
services: services:
lemmy: lemmy:
@ -38,7 +38,7 @@ services:
restart: always restart: always
pictrs: pictrs:
image: asonix/pictrs:v0.2.5-r0 image: asonix/pictrs:v0.2.6-r1
user: 991:991 user: 991:991
ports: ports:
- "127.0.0.1:8537:8080" - "127.0.0.1:8537:8080"

View File

@ -4,6 +4,7 @@ use crate::{
check_is_apub_id_valid, check_is_apub_id_valid,
extensions::context::lemmy_context, extensions::context::lemmy_context,
fetcher::user::get_or_fetch_and_upsert_user, fetcher::user::get_or_fetch_and_upsert_user,
insert_activity,
ActorType, ActorType,
}; };
use activitystreams::{ use activitystreams::{
@ -27,7 +28,7 @@ use lemmy_api_structs::blocking;
use lemmy_db_queries::DbPool; use lemmy_db_queries::DbPool;
use lemmy_db_schema::source::community::Community; use lemmy_db_schema::source::community::Community;
use lemmy_db_views_actor::community_follower_view::CommunityFollowerView; 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 lemmy_websocket::LemmyContext;
use url::Url; 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 /// Wraps an activity sent to the community in an announce, and then sends the announce to all
/// community followers. /// 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( async fn send_announce(
&self, &self,
activity: AnyBase, activity: AnyBase,
context: &LemmyContext, context: &LemmyContext,
) -> Result<(), LemmyError> { ) -> 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); let mut announce = Announce::new(self.actor_id.to_owned().into_inner(), activity);
announce announce
.set_many_contexts(lemmy_context()?) .set_many_contexts(lemmy_context()?)

View File

@ -42,7 +42,7 @@ services:
restart: always restart: always
pictrs: pictrs:
image: asonix/pictrs:v0.2.5-r0 image: asonix/pictrs:v0.2.6-r1
ports: ports:
- "8537:8080" - "8537:8080"
user: 991:991 user: 991:991

View File

@ -23,7 +23,7 @@ services:
pictrs: pictrs:
restart: always restart: always
image: asonix/pictrs:v0.2.5-r0 image: asonix/pictrs:v0.2.6-r1
user: 991:991 user: 991:991
volumes: volumes:
- ./volumes/pictrs_alpha:/mnt - ./volumes/pictrs_alpha:/mnt

View File

@ -38,7 +38,7 @@ services:
- lemmy - lemmy
pictrs: pictrs:
image: asonix/pictrs:v0.2.5-r0 image: asonix/pictrs:v0.2.6-r1
ports: ports:
- "127.0.0.1:8537:8080" - "127.0.0.1:8537:8080"
user: 991:991 user: 991:991