1
0
Fork 0
forked from alemi/upub

fix: also fix context for fetched objects

This commit is contained in:
əlemi 2024-04-23 03:04:54 +02:00
parent 53dcfcb993
commit 852b45f8dd
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -128,7 +128,7 @@ async fn fetch_object_inner(ctx: &Context, id: &str, depth: usize) -> crate::Res
).await?.json::<serde_json::Value>().await?; ).await?.json::<serde_json::Value>().await?;
let addressed = object.addressed(); let addressed = object.addressed();
let object_model = model::object::Model::new(&object)?; let mut object_model = model::object::Model::new(&object)?;
if let Some(reply) = &object_model.in_reply_to { if let Some(reply) = &object_model.in_reply_to {
if depth <= 16 { if depth <= 16 {
@ -138,6 +138,17 @@ async fn fetch_object_inner(ctx: &Context, id: &str, depth: usize) -> crate::Res
} }
} }
// fix context also for remote posts
// TODO this is not really appropriate because we're mirroring incorrectly remote objects, but
// it makes it SOO MUCH EASIER for us to fetch threads and stuff, so we're filling it for them
match (&object_model.in_reply_to, &object_model.context) {
(Some(reply_id), None) => // get context from replied object
object_model.context = fetch_object_inner(ctx, reply_id, depth + 1).await?.context,
(None, None) => // generate a new context
object_model.context = Some(crate::url!(ctx, "/context/{}", uuid::Uuid::new_v4().to_string())),
(_, Some(_)) => {}, // leave it as set by user
}
for attachment in object.attachment() { for attachment in object.attachment() {
let attachment_model = model::attachment::ActiveModel::new(&attachment, object_model.id.clone())?; let attachment_model = model::attachment::ActiveModel::new(&attachment, object_model.id.clone())?;
model::attachment::Entity::insert(attachment_model) model::attachment::Entity::insert(attachment_model)