diff --git a/src/server/fetcher.rs b/src/server/fetcher.rs index 039dac9..7434ea3 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) }