fix: only count announces from persons

This commit is contained in:
əlemi 2024-05-30 22:16:48 +02:00
parent 86ed372a54
commit e636afd283
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 5 additions and 6 deletions

View file

@ -21,9 +21,10 @@ struct ContextInner {
actor: model::actor::Model, actor: model::actor::Model,
instance: model::instance::Model, instance: model::instance::Model,
pkey: String, pkey: String,
relay: Relays, #[allow(unused)] relay: Relays,
} }
#[allow(unused)]
pub struct Relays { pub struct Relays {
sources: BTreeSet<String>, sources: BTreeSet<String>,
sinks: BTreeSet<String>, sinks: BTreeSet<String>,
@ -178,6 +179,7 @@ impl Context {
.await .await
} }
#[allow(unused)]
pub fn is_relay(&self, id: &str) -> bool { pub fn is_relay(&self, id: &str) -> bool {
self.0.relay.sources.contains(id) || self.0.relay.sinks.contains(id) self.0.relay.sources.contains(id) || self.0.relay.sinks.contains(id)
} }

View file

@ -1,6 +1,5 @@
use apb::{target::Addressed, Activity, Base, Object}; use apb::{target::Addressed, Activity, Base, Object};
use reqwest::StatusCode; use sea_orm::{sea_query::Expr, ActiveValue::{Set, NotSet}, ColumnTrait, EntityTrait, QueryFilter, QuerySelect, SelectColumns};
use sea_orm::{sea_query::Expr, ActiveValue::{Set, NotSet}, ColumnTrait, Condition, EntityTrait, QueryFilter, QuerySelect, SelectColumns};
use crate::{errors::{LoggableError, UpubError}, model, server::{addresser::Addresser, builders::AnyQuery, normalizer::Normalizer}}; use crate::{errors::{LoggableError, UpubError}, model, server::{addresser::Addresser, builders::AnyQuery, normalizer::Normalizer}};
@ -267,7 +266,7 @@ impl apb::server::Inbox for Context {
let announced = self.fetch_object(&announced_id).await?; let announced = self.fetch_object(&announced_id).await?;
// relays send us activities as Announce, but we don't really want to count those towards the // relays send us activities as Announce, but we don't really want to count those towards the
// total shares count of an object, so just fetch the object and be done with it // total shares count of an object, so just fetch the object and be done with it
if self.is_relay(&activity_model.actor) { if matches!(actor.actor_type, apb::ActorType::Person) {
tracing::info!("relay {} broadcasted {}", activity_model.actor, announced_id); tracing::info!("relay {} broadcasted {}", activity_model.actor, announced_id);
return Ok(()) return Ok(())
} }

View file

@ -2,8 +2,6 @@ use apb::{Node, Base, Object, Document};
use sea_orm::{sea_query::Expr, ActiveValue::{NotSet, Set}, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter}; use sea_orm::{sea_query::Expr, ActiveValue::{NotSet, Set}, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter};
use crate::{errors::UpubError, model, server::Context}; use crate::{errors::UpubError, model, server::Context};
use super::fetcher::Fetcher;
#[axum::async_trait] #[axum::async_trait]
pub trait Normalizer { pub trait Normalizer {
async fn insert_object(&self, obj: impl apb::Object, server: Option<String>) -> crate::Result<model::object::Model>; async fn insert_object(&self, obj: impl apb::Object, server: Option<String>) -> crate::Result<model::object::Model>;