feat: show likes and shares and replies in objects
it's done with anonymous inline collections, which hold a "totalItems" field. for replies it's perfect, for likes it's stretched ("audience", used as a Collection) and for shares it's really stretched ("generator", used as a Collection). also using audience and generator as collections seems weird because they should be objects but collections are objects so it should be fine? i haven't seen these fields used anyway so it should be safe to "claim" it for ourselves?
This commit is contained in:
parent
95f9d05875
commit
5ae9a140b4
1 changed files with 31 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
use apb::{BaseMut, ObjectMut, Collection};
|
use apb::{BaseMut, Object, Collection, CollectionMut, ObjectMut};
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
use crate::routes::activitypub::jsonld::LD;
|
use crate::routes::activitypub::jsonld::LD;
|
||||||
|
@ -41,9 +41,21 @@ impl Model {
|
||||||
context: object.context().id(),
|
context: object.context().id(),
|
||||||
in_reply_to: object.in_reply_to().id(),
|
in_reply_to: object.in_reply_to().id(),
|
||||||
published: object.published().ok_or(super::FieldError("published"))?,
|
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,
|
comments: object.replies()
|
||||||
likes: 0,
|
.get()
|
||||||
shares: 0,
|
.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(),
|
to: object.to().into(),
|
||||||
bto: object.bto().into(),
|
bto: object.bto().into(),
|
||||||
cc: object.cc().into(),
|
cc: object.cc().into(),
|
||||||
|
@ -69,6 +81,21 @@ impl Model {
|
||||||
.set_cc(apb::Node::links(self.cc.0.clone()))
|
.set_cc(apb::Node::links(self.cc.0.clone()))
|
||||||
.set_bcc(apb::Node::Empty)
|
.set_bcc(apb::Node::Empty)
|
||||||
.set_sensitive(Some(self.sensitive))
|
.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))
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue