From 75e6fe61ca92d09a9f88ca9657f5720bc0d8fc3c Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 28 May 2026 02:59:45 +0200 Subject: [PATCH] fix: look up remote parent by ap_id to thread remote-to-remote replies --- crates/adapters/postgres/src/activitypub/mod.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/adapters/postgres/src/activitypub/mod.rs b/crates/adapters/postgres/src/activitypub/mod.rs index abce3b4..e91557f 100644 --- a/crates/adapters/postgres/src/activitypub/mod.rs +++ b/crates/adapters/postgres/src/activitypub/mod.rs @@ -227,14 +227,25 @@ impl ActivityPubRepository for PgActivityPubRepository { let capped: String = content.chars().take(MAX_REMOTE_CONTENT_CHARS).collect(); let (in_reply_to_id, in_reply_to_url) = match in_reply_to { Some(url) => { - // If the parent is a local thought, extract its UUID for in_reply_to_id. + // Fast path: local thought URL contains the UUID directly. let local_uuid = url::Url::parse(url).ok().and_then(|u| { u.path() .strip_prefix(THOUGHTS_PATH_PREFIX) .and_then(|s| s.split('/').next()) .and_then(|s| uuid::Uuid::parse_str(s).ok()) }); - (local_uuid, Some(url.to_string())) + // Slow path: remote parent — look up by ap_id so remote-to-remote + // replies are threaded correctly in the feed. + let resolved = if local_uuid.is_some() { + local_uuid + } else { + sqlx::query_scalar::<_, uuid::Uuid>("SELECT id FROM thoughts WHERE ap_id=$1") + .bind(url) + .fetch_optional(&self.pool) + .await + .into_domain()? + }; + (resolved, Some(url.to_string())) } None => (None, None), };