fix: look up remote parent by ap_id to thread remote-to-remote replies

This commit is contained in:
2026-05-28 02:59:45 +02:00
parent 4f1b9a5cfb
commit 75e6fe61ca

View File

@@ -227,14 +227,25 @@ impl ActivityPubRepository for PgActivityPubRepository {
let capped: String = content.chars().take(MAX_REMOTE_CONTENT_CHARS).collect(); let capped: String = content.chars().take(MAX_REMOTE_CONTENT_CHARS).collect();
let (in_reply_to_id, in_reply_to_url) = match in_reply_to { let (in_reply_to_id, in_reply_to_url) = match in_reply_to {
Some(url) => { 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| { let local_uuid = url::Url::parse(url).ok().and_then(|u| {
u.path() u.path()
.strip_prefix(THOUGHTS_PATH_PREFIX) .strip_prefix(THOUGHTS_PATH_PREFIX)
.and_then(|s| s.split('/').next()) .and_then(|s| s.split('/').next())
.and_then(|s| uuid::Uuid::parse_str(s).ok()) .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), None => (None, None),
}; };