diff --git a/src/server/fetcher.rs b/src/server/fetcher.rs index 1f5f6f44..a9687135 100644 --- a/src/server/fetcher.rs +++ b/src/server/fetcher.rs @@ -128,7 +128,7 @@ async fn fetch_object_inner(ctx: &Context, id: &str, depth: usize) -> crate::Res ).await?.json::().await?; 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 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() { let attachment_model = model::attachment::ActiveModel::new(&attachment, object_model.id.clone())?; model::attachment::Entity::insert(attachment_model)