forked from alemi/upub
fix: replies only in object view, page uris
This commit is contained in:
parent
67c4051226
commit
ab5d0cb61a
3 changed files with 36 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
|||
use apb::{BaseMut, CollectionMut, ObjectMut};
|
||||
use apb::{BaseMut, ObjectMut};
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
use crate::routes::activitypub::jsonld::LD;
|
||||
|
@ -59,13 +59,6 @@ impl Model {
|
|||
.set_content(self.content.as_deref())
|
||||
.set_context(apb::Node::maybe_link(self.context.clone()))
|
||||
.set_in_reply_to(apb::Node::maybe_link(self.in_reply_to.clone()))
|
||||
.set_replies(apb::Node::object(
|
||||
serde_json::Value::new_object()
|
||||
.set_id(Some(&format!("{}/replies", self.id)))
|
||||
.set_collection_type(Some(apb::CollectionType::OrderedCollection))
|
||||
.set_first(apb::Node::link(format!("{}/replies/page", self.id)))
|
||||
.set_total_items(Some(self.comments as u64))
|
||||
))
|
||||
.set_published(Some(self.published))
|
||||
.set_to(apb::Node::links(self.to.0.clone()))
|
||||
.set_bto(apb::Node::Empty)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
pub mod replies;
|
||||
|
||||
use apb::{BaseMut, CollectionMut, ObjectMut};
|
||||
use axum::extract::{Path, Query, State};
|
||||
use sea_orm::{ColumnTrait, QueryFilter};
|
||||
|
||||
|
@ -18,19 +19,36 @@ pub async fn view(
|
|||
} else {
|
||||
ctx.oid(id.clone())
|
||||
};
|
||||
match model::addressing::Entity::find_activities()
|
||||
|
||||
let result = model::addressing::Entity::find_activities()
|
||||
.filter(model::object::Column::Id.eq(&oid))
|
||||
.filter(auth.filter_condition())
|
||||
.into_model::<EmbeddedActivity>()
|
||||
.one(ctx.db())
|
||||
.await?
|
||||
{
|
||||
Some(EmbeddedActivity { activity: _, object: Some(object) }) => Ok(JsonLD(object.ap().ld_context())),
|
||||
Some(EmbeddedActivity { activity: _, object: None }) => Err(UpubError::not_found()),
|
||||
None => if auth.is_local() && query.fetch && !ctx.is_local(&oid) {
|
||||
Ok(JsonLD(ctx.fetch_object(&oid).await?.ap().ld_context()))
|
||||
.await?;
|
||||
|
||||
let object = match result {
|
||||
Some(EmbeddedActivity { activity: _, object: Some(obj) }) => obj,
|
||||
_ => {
|
||||
if auth.is_local() && query.fetch && !ctx.is_local(&oid) {
|
||||
ctx.fetch_object(&oid).await?
|
||||
} else {
|
||||
Err(UpubError::not_found())
|
||||
return Err(UpubError::not_found())
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
let replies =
|
||||
serde_json::Value::new_object()
|
||||
.set_id(Some(&crate::url!(ctx, "/objects/{id}/replies")))
|
||||
.set_collection_type(Some(apb::CollectionType::OrderedCollection))
|
||||
.set_first(apb::Node::link(crate::url!(ctx, "/objects/{id}/replies/page")))
|
||||
.set_total_items(Some(object.comments as u64));
|
||||
|
||||
|
||||
Ok(JsonLD(
|
||||
object.ap()
|
||||
.set_replies(apb::Node::object(replies))
|
||||
.ld_context()
|
||||
))
|
||||
}
|
||||
|
|
|
@ -105,11 +105,14 @@ impl Context {
|
|||
}
|
||||
|
||||
/// get bare id, usually an uuid but unspecified
|
||||
pub fn id(&self, id: String) -> String {
|
||||
if id.starts_with(&self.0.domain) {
|
||||
id.split('/').last().unwrap_or("").to_string()
|
||||
pub fn id(&self, uri: &str) -> String {
|
||||
if uri.starts_with(&self.0.domain) {
|
||||
uri.split('/').last().unwrap_or("").to_string()
|
||||
} else {
|
||||
id
|
||||
uri
|
||||
.replace("https://", "+")
|
||||
.replace("http://", "+")
|
||||
.replace('/', "@")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue