From 4d4cbe0ef8c6345e04de2b92594e6d03bb06eb85 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 20 Apr 2024 04:24:48 +0200 Subject: [PATCH] feat: create mock activities for fetched objects --- src/server/fetcher.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/server/fetcher.rs b/src/server/fetcher.rs index 039dac97..7434ea3c 100644 --- a/src/server/fetcher.rs +++ b/src/server/fetcher.rs @@ -131,12 +131,31 @@ impl Fetcher for Context { let addressed = object.addressed(); let object_model = model::object::Model::new(&object)?; - model::object::Entity::insert(object_model.clone().into_active_model()) - .exec(self.db()).await?; + // since bare objects make no sense in our representation, we create a mock activity attributed to + // our server actor which creates this object. we respect all addressing we were made aware of + // and claim no ownership of this object, pointing to the original author if it's given. + // TODO it may be cool to make a system that, when the "true" activity is discovered, deletes + // this and replaces the addressing entries? idk kinda lot of work + let wrapper_activity_model = model::activity::Model { + id: self.aid(uuid::Uuid::new_v4().to_string()), + activity_type: apb::ActivityType::Create, + actor: self.base(), + object: Some(object_model.id.clone()), + target: object_model.attributed_to.clone(), + cc: object_model.cc.clone(), + bcc: object_model.bcc.clone(), + to: object_model.to.clone(), + bto: object_model.bto.clone(), + published: chrono::Utc::now(), + }; let expanded_addresses = self.expand_addressing(addressed).await?; - // TODO we don't know which activity created this! - self.address_to("", Some(&object_model.id), &expanded_addresses).await?; + self.address_to(&wrapper_activity_model.id, Some(&object_model.id), &expanded_addresses).await?; + + model::activity::Entity::insert(wrapper_activity_model.into_active_model()) + .exec(self.db()).await?; + model::object::Entity::insert(object_model.clone().into_active_model()) + .exec(self.db()).await?; Ok(object_model) }