diff --git a/crates/application/src/services/federation_event.rs b/crates/application/src/services/federation_event.rs index 5fe335a..5fa432f 100644 --- a/crates/application/src/services/federation_event.rs +++ b/crates/application/src/services/federation_event.rs @@ -48,6 +48,29 @@ impl FederationEventService { Some(u) => u, None => return Ok(()), }; + // For replies to remote posts: in_reply_to_url is None but in_reply_to_id + // points to the locally-stored remote thought. Resolve its ap_id so the + // outbound Note includes inReplyTo and Mastodon threads it correctly. + let thought = if thought.in_reply_to_url.is_none() { + if let Some(ref reply_id) = thought.in_reply_to_id { + match self.thoughts.find_by_id(reply_id).await? { + Some(parent) => { + let parent_ap_url = parent.ap_id.unwrap_or_else(|| { + format!("{}/thoughts/{}", self.base_url, reply_id) + }); + domain::models::thought::Thought { + in_reply_to_url: Some(parent_ap_url), + ..thought + } + } + None => thought, + } + } else { + thought + } + } else { + thought + }; self.ap .broadcast_create(user_id, &thought, user.username.as_str()) .await