diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 726edfc5f..557c5d8ae 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1442,33 +1442,59 @@ async fn add_parts( } if let Some(node_addr) = mime_parser.get_header(HeaderDef::IrohNodeAddr) { + chat_id = DC_CHAT_ID_TRASH; match serde_json::from_str::(node_addr).context("Failed to parse node address") { Ok(node_addr) => { info!(context, "Adding iroh peer with address {node_addr:?}."); - let instance_id = parent.context("Failed to get parent message")?.id; - context.emit_event(EventType::WebxdcRealtimeAdvertisementReceived { - msg_id: instance_id, - }); - if let Some(topic) = get_iroh_topic_for_msg(context, instance_id).await? { - let node_id = node_addr.node_id; - let relay_server = node_addr.relay_url().map(|relay| relay.as_str()); - iroh_add_peer_for_topic(context, instance_id, topic, node_id, relay_server) - .await?; - if context - .get_config_bool(Config::WebxdcRealtimeEnabled) - .await? - { - let iroh = context.get_or_try_init_peer_channel().await?; - iroh.maybe_add_gossip_peers(topic, vec![node_addr]).await?; + match mime_parser.get_header(HeaderDef::InReplyTo) { + Some(in_reply_to) => match rfc724_mid_exists(context, in_reply_to).await? { + Some((instance_id, _ts_sent)) => { + context.emit_event(EventType::WebxdcRealtimeAdvertisementReceived { + msg_id: instance_id, + }); + if let Some(topic) = + get_iroh_topic_for_msg(context, instance_id).await? + { + let node_id = node_addr.node_id; + let relay_server = + node_addr.relay_url().map(|relay| relay.as_str()); + iroh_add_peer_for_topic( + context, + instance_id, + topic, + node_id, + relay_server, + ) + .await?; + if context + .get_config_bool(Config::WebxdcRealtimeEnabled) + .await? + { + let iroh = context.get_or_try_init_peer_channel().await?; + iroh.maybe_add_gossip_peers(topic, vec![node_addr]).await?; + } + info!(context, "Added iroh peer to the topic of {instance_id}."); + } else { + warn!( + context, + "Could not add iroh peer because {instance_id} has no topic." + ); + } + } + None => { + warn!( + context, + "Cannot add iroh peer because WebXDC instance does not exist." + ); + } + }, + None => { + warn!( + context, + "Cannot add iroh peer because the message has no In-Reply-To." + ); } - info!(context, "Added iroh peer to the topic of {instance_id}."); - } else { - warn!( - context, - "Could not add iroh peer because {instance_id} has no topic." - ); } - chat_id = DC_CHAT_ID_TRASH; } Err(err) => { warn!(context, "Couldn't parse NodeAddr: {err:#}.");