diff --git a/src/model/object.rs b/src/model/object.rs index 3087b12..731288c 100644 --- a/src/model/object.rs +++ b/src/model/object.rs @@ -1,4 +1,4 @@ -use apb::{BaseMut, ObjectMut, Collection}; +use apb::{BaseMut, Object, Collection, CollectionMut, ObjectMut}; use sea_orm::entity::prelude::*; use crate::routes::activitypub::jsonld::LD; @@ -41,9 +41,21 @@ impl Model { context: object.context().id(), in_reply_to: object.in_reply_to().id(), published: object.published().ok_or(super::FieldError("published"))?, - comments: object.replies().get().map(|x| x.total_items().unwrap_or(0)).unwrap_or(0) as i64, - likes: 0, - shares: 0, + comments: object.replies() + .get() + .map_or(0, |x| x.total_items().unwrap_or(0)) as i64, + likes: object.audience() + .get() + .map_or(0, |x| + x.as_collection() + .map_or(0, |x| x.total_items().unwrap_or(0)) + ) as i64, + shares: object.generator() + .get() + .map_or(0, |x| + x.as_collection() + .map_or(0, |x| x.total_items().unwrap_or(0)) + ) as i64, to: object.to().into(), bto: object.bto().into(), cc: object.cc().into(), @@ -69,6 +81,21 @@ impl Model { .set_cc(apb::Node::links(self.cc.0.clone())) .set_bcc(apb::Node::Empty) .set_sensitive(Some(self.sensitive)) + .set_generator(apb::Node::object( + serde_json::Value::new_object() + .set_collection_type(Some(apb::CollectionType::OrderedCollection)) + .set_total_items(Some(self.shares as u64)) + )) + .set_audience(apb::Node::object( + serde_json::Value::new_object() + .set_collection_type(Some(apb::CollectionType::OrderedCollection)) + .set_total_items(Some(self.likes as u64)) + )) + .set_replies(apb::Node::object( + serde_json::Value::new_object() + .set_collection_type(Some(apb::CollectionType::OrderedCollection)) + .set_total_items(Some(self.comments as u64)) + )) } }