fix: insert liked element also in single obj view

This commit is contained in:
əlemi 2024-04-30 02:57:50 +02:00
parent 2c302b4fbf
commit 3237a38d74
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,6 +1,6 @@
pub mod replies; pub mod replies;
use apb::ObjectMut; use apb::{CollectionMut, ObjectMut};
use axum::extract::{Path, Query, State}; use axum::extract::{Path, Query, State};
use sea_orm::{ColumnTrait, ModelTrait, QueryFilter}; use sea_orm::{ColumnTrait, ModelTrait, QueryFilter};
@ -35,11 +35,11 @@ pub async fn view(
.await? .await?
.ok_or_else(UpubError::not_found)?; .ok_or_else(UpubError::not_found)?;
let object = match item { let (object, liked) = match item {
Event::Tombstone => return Err(UpubError::not_found()), Event::Tombstone => return Err(UpubError::not_found()),
Event::Activity(_) => return Err(UpubError::not_found()), Event::Activity(_) => return Err(UpubError::not_found()),
Event::StrayObject { object, liked: _ } => object, Event::StrayObject { object, liked } => (object, liked),
Event::DeepActivity { activity: _, liked: _, object } => object, Event::DeepActivity { activity: _, liked, object } => (object, liked),
}; };
let attachments = object.find_related(model::attachment::Entity) let attachments = object.find_related(model::attachment::Entity)
@ -55,11 +55,18 @@ pub async fn view(
// .set_collection_type(Some(apb::CollectionType::OrderedCollection)) // .set_collection_type(Some(apb::CollectionType::OrderedCollection))
// .set_first(apb::Node::link(crate::url!(ctx, "/objects/{id}/replies/page"))) // .set_first(apb::Node::link(crate::url!(ctx, "/objects/{id}/replies/page")))
// .set_total_items(Some(object.comments as u64)); // .set_total_items(Some(object.comments as u64));
let likes_count = object.likes as u64;
let mut obj = object.ap().set_attachment(apb::Node::array(attachments));
Ok(JsonLD( if let Some(liked) = liked {
object.ap() obj = obj.set_audience(apb::Node::object( // TODO setting this again ewww...
// .set_replies(apb::Node::object(replies)) serde_json::Value::new_object()
.set_attachment(apb::Node::array(attachments)) .set_collection_type(Some(apb::CollectionType::OrderedCollection))
.ld_context() .set_total_items(Some(likes_count))
)) .set_ordered_items(apb::Node::links(vec![liked]))
));
}
Ok(JsonLD(obj.ld_context()))
} }