From a3921622cb304f5c6f88dd9386d3be34c4b4a036 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 30 May 2024 19:51:06 +0200 Subject: [PATCH] fix: fetch object on inbox/outbox, not normalizer should also fix the fact that some posts miss context --- src/server/inbox.rs | 5 +++++ src/server/normalizer.rs | 12 +++++------- src/server/outbox.rs | 3 +++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/server/inbox.rs b/src/server/inbox.rs index 9c5a958..1689323 100644 --- a/src/server/inbox.rs +++ b/src/server/inbox.rs @@ -18,6 +18,11 @@ impl apb::server::Inbox for Context { tracing::error!("refusing to process activity without embedded object: {}", serde_json::to_string_pretty(&activity).unwrap()); return Err(UpubError::unprocessable()); }; + if let Some(reply) = object_node.in_reply_to().id() { + if let Err(e) = self.fetch_object(&reply).await { + tracing::warn!("failed fetching replies for received object: {e}"); + } + } let activity_model = self.insert_activity(activity, Some(server.clone())).await?; let object_model = self.insert_object(object_node, Some(server)).await?; let expanded_addressing = self.expand_addressing(activity_model.addressed()).await?; diff --git a/src/server/normalizer.rs b/src/server/normalizer.rs index d7253a9..8aeef66 100644 --- a/src/server/normalizer.rs +++ b/src/server/normalizer.rs @@ -53,13 +53,11 @@ impl Normalizer for super::Context { // update replies counter if let Set(Some(ref in_reply_to)) = object_model.in_reply_to { - if self.fetch_object(in_reply_to).await.is_ok() { - model::object::Entity::update_many() - .filter(model::object::Column::Id.eq(in_reply_to)) - .col_expr(model::object::Column::Replies, Expr::col(model::object::Column::Replies).add(1)) - .exec(self.db()) - .await?; - } + model::object::Entity::update_many() + .filter(model::object::Column::Id.eq(in_reply_to)) + .col_expr(model::object::Column::Replies, Expr::col(model::object::Column::Replies).add(1)) + .exec(self.db()) + .await?; } // update statuses counter if let Some(object_author) = uid { diff --git a/src/server/outbox.rs b/src/server/outbox.rs index eae93b0..e36993a 100644 --- a/src/server/outbox.rs +++ b/src/server/outbox.rs @@ -36,6 +36,9 @@ impl apb::server::Outbox for Context { let aid = self.aid(&uuid::Uuid::new_v4().to_string()); let activity_targets = activity.addressed(); + if let Some(reply) = object.in_reply_to().id() { + self.fetch_object(&reply).await?; + } // TODO regex hell here i come... let re = regex::Regex::new(r"@(.+)@([^ ]+)").expect("failed compiling regex pattern");