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 sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
use crate::routes::activitypub::jsonld::LD;
|
use crate::routes::activitypub::jsonld::LD;
|
||||||
|
@ -59,13 +59,6 @@ impl Model {
|
||||||
.set_content(self.content.as_deref())
|
.set_content(self.content.as_deref())
|
||||||
.set_context(apb::Node::maybe_link(self.context.clone()))
|
.set_context(apb::Node::maybe_link(self.context.clone()))
|
||||||
.set_in_reply_to(apb::Node::maybe_link(self.in_reply_to.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_published(Some(self.published))
|
||||||
.set_to(apb::Node::links(self.to.0.clone()))
|
.set_to(apb::Node::links(self.to.0.clone()))
|
||||||
.set_bto(apb::Node::Empty)
|
.set_bto(apb::Node::Empty)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pub mod replies;
|
pub mod replies;
|
||||||
|
|
||||||
|
use apb::{BaseMut, CollectionMut, ObjectMut};
|
||||||
use axum::extract::{Path, Query, State};
|
use axum::extract::{Path, Query, State};
|
||||||
use sea_orm::{ColumnTrait, QueryFilter};
|
use sea_orm::{ColumnTrait, QueryFilter};
|
||||||
|
|
||||||
|
@ -18,19 +19,36 @@ pub async fn view(
|
||||||
} else {
|
} else {
|
||||||
ctx.oid(id.clone())
|
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(model::object::Column::Id.eq(&oid))
|
||||||
.filter(auth.filter_condition())
|
.filter(auth.filter_condition())
|
||||||
.into_model::<EmbeddedActivity>()
|
.into_model::<EmbeddedActivity>()
|
||||||
.one(ctx.db())
|
.one(ctx.db())
|
||||||
.await?
|
.await?;
|
||||||
{
|
|
||||||
Some(EmbeddedActivity { activity: _, object: Some(object) }) => Ok(JsonLD(object.ap().ld_context())),
|
let object = match result {
|
||||||
Some(EmbeddedActivity { activity: _, object: None }) => Err(UpubError::not_found()),
|
Some(EmbeddedActivity { activity: _, object: Some(obj) }) => obj,
|
||||||
None => if auth.is_local() && query.fetch && !ctx.is_local(&oid) {
|
_ => {
|
||||||
Ok(JsonLD(ctx.fetch_object(&oid).await?.ap().ld_context()))
|
if auth.is_local() && query.fetch && !ctx.is_local(&oid) {
|
||||||
|
ctx.fetch_object(&oid).await?
|
||||||
} else {
|
} 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
|
/// get bare id, usually an uuid but unspecified
|
||||||
pub fn id(&self, id: String) -> String {
|
pub fn id(&self, uri: &str) -> String {
|
||||||
if id.starts_with(&self.0.domain) {
|
if uri.starts_with(&self.0.domain) {
|
||||||
id.split('/').last().unwrap_or("").to_string()
|
uri.split('/').last().unwrap_or("").to_string()
|
||||||
} else {
|
} else {
|
||||||
id
|
uri
|
||||||
|
.replace("https://", "+")
|
||||||
|
.replace("http://", "+")
|
||||||
|
.replace('/', "@")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue