Removing is_activity_already_known

This commit is contained in:
Dessalines 2021-11-22 13:07:23 -05:00
parent 744f242061
commit b7ad93611d
2 changed files with 2 additions and 24 deletions

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
activities::{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, activity_lists::AnnouncableActivities,
http::{is_activity_already_known, ActivityCommonFields}, http::ActivityCommonFields,
insert_activity, insert_activity,
objects::community::ApubCommunity, objects::community::ApubCommunity,
protocol::activities::{community::announce::AnnounceActivity, CreateOrUpdateType}, protocol::activities::{community::announce::AnnounceActivity, CreateOrUpdateType},
@ -109,9 +109,6 @@ impl ActivityHandler for AnnounceActivity {
let object_value = serde_json::to_value(&self.object)?; let object_value = serde_json::to_value(&self.object)?;
let object_data: ActivityCommonFields = serde_json::from_value(object_value.to_owned())?; let object_data: ActivityCommonFields = serde_json::from_value(object_value.to_owned())?;
if is_activity_already_known(context.pool(), &object_data.id).await? {
return Ok(());
}
insert_activity(&object_data.id, object_value, false, true, context.pool()).await?; insert_activity(&object_data.id, object_value, false, true, context.pool()).await?;
} }
} }

View file

@ -24,7 +24,7 @@ use lemmy_apub_lib::{
traits::{ActivityHandler, ActorType}, traits::{ActivityHandler, ActorType},
APUB_JSON_CONTENT_TYPE, APUB_JSON_CONTENT_TYPE,
}; };
use lemmy_db_schema::{source::activity::Activity, DbPool}; use lemmy_db_schema::source::activity::Activity;
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use log::info; use log::info;
@ -97,10 +97,6 @@ where
.await?; .await?;
verify_signature(&request, &actor.public_key())?; verify_signature(&request, &actor.public_key())?;
// Do nothing if we received the same activity before
if is_activity_already_known(context.pool(), &activity_data.id).await? {
return Ok(HttpResponse::Ok().finish());
}
info!("Verifying activity {}", activity_data.id.to_string()); info!("Verifying activity {}", activity_data.id.to_string());
activity activity
.verify(&Data::new(context.clone()), request_counter) .verify(&Data::new(context.clone()), request_counter)
@ -178,21 +174,6 @@ pub(crate) async fn get_activity(
} }
} }
pub(crate) async fn is_activity_already_known(
pool: &DbPool,
activity_id: &Url,
) -> Result<bool, LemmyError> {
let activity_id = activity_id.to_owned().into();
let existing = blocking(pool, move |conn| {
Activity::read_from_apub_id(conn, &activity_id)
})
.await?;
match existing {
Ok(_) => Ok(true),
Err(_) => Ok(false),
}
}
fn assert_activity_not_local(id: &Url, hostname: &str) -> Result<(), LemmyError> { fn assert_activity_not_local(id: &Url, hostname: &str) -> Result<(), LemmyError> {
let activity_domain = id.domain().context(location_info!())?; let activity_domain = id.domain().context(location_info!())?;