@@ -30,7 +30,7 @@ use crate::message::{
30
30
} ;
31
31
use crate :: mimeparser:: { parse_message_ids, AvatarAction , MimeMessage , SystemMessage } ;
32
32
use crate :: param:: { Param , Params } ;
33
- use crate :: peer_channels:: { get_iroh_topic_for_msg , insert_topic_stub, iroh_add_peer_for_topic } ;
33
+ use crate :: peer_channels:: { add_gossip_peer_from_header , insert_topic_stub} ;
34
34
use crate :: peerstate:: Peerstate ;
35
35
use crate :: reaction:: { set_msg_reaction, Reaction } ;
36
36
use crate :: securejoin:: { self , handle_securejoin_handshake, observe_securejoin_on_other_device} ;
@@ -41,7 +41,6 @@ use crate::sync::Sync::*;
41
41
use crate :: tools:: { self , buf_compress, remove_subject_prefix} ;
42
42
use crate :: { chatlist_events, location} ;
43
43
use crate :: { contact, imap} ;
44
- use iroh_net:: NodeAddr ;
45
44
46
45
/// This is the struct that is returned after receiving one email (aka MIME message).
47
46
///
@@ -1446,61 +1445,27 @@ async fn add_parts(
1446
1445
1447
1446
if let Some ( node_addr) = mime_parser. get_header ( HeaderDef :: IrohNodeAddr ) {
1448
1447
chat_id = DC_CHAT_ID_TRASH ;
1449
- match serde_json:: from_str :: < NodeAddr > ( node_addr) . context ( "Failed to parse node address" ) {
1450
- Ok ( node_addr) => {
1451
- info ! ( context, "Adding iroh peer with address {node_addr:?}." ) ;
1452
- match mime_parser. get_header ( HeaderDef :: InReplyTo ) {
1453
- Some ( in_reply_to) => match rfc724_mid_exists ( context, in_reply_to) . await ? {
1454
- Some ( ( instance_id, _ts_sent) ) => {
1455
- context. emit_event ( EventType :: WebxdcRealtimeAdvertisementReceived {
1456
- msg_id : instance_id,
1457
- } ) ;
1458
- if let Some ( topic) =
1459
- get_iroh_topic_for_msg ( context, instance_id) . await ?
1460
- {
1461
- let node_id = node_addr. node_id ;
1462
- let relay_server =
1463
- node_addr. relay_url ( ) . map ( |relay| relay. as_str ( ) ) ;
1464
- iroh_add_peer_for_topic (
1465
- context,
1466
- instance_id,
1467
- topic,
1468
- node_id,
1469
- relay_server,
1470
- )
1471
- . await ?;
1472
- if context
1473
- . get_config_bool ( Config :: WebxdcRealtimeEnabled )
1474
- . await ?
1475
- {
1476
- let iroh = context. get_or_try_init_peer_channel ( ) . await ?;
1477
- iroh. maybe_add_gossip_peers ( topic, vec ! [ node_addr] ) . await ?;
1478
- }
1479
- info ! ( context, "Added iroh peer to the topic of {instance_id}." ) ;
1480
- } else {
1481
- warn ! (
1482
- context,
1483
- "Could not add iroh peer because {instance_id} has no topic."
1484
- ) ;
1485
- }
1486
- }
1487
- None => {
1488
- warn ! (
1489
- context,
1490
- "Cannot add iroh peer because WebXDC instance does not exist."
1491
- ) ;
1492
- }
1493
- } ,
1494
- None => {
1495
- warn ! (
1496
- context,
1497
- "Cannot add iroh peer because the message has no In-Reply-To."
1498
- ) ;
1448
+ match mime_parser. get_header ( HeaderDef :: InReplyTo ) {
1449
+ Some ( in_reply_to) => match rfc724_mid_exists ( context, in_reply_to) . await ? {
1450
+ Some ( ( instance_id, _ts_sent) ) => {
1451
+ if let Err ( err) =
1452
+ add_gossip_peer_from_header ( context, instance_id, node_addr) . await
1453
+ {
1454
+ warn ! ( context, "Failed to add iroh peer from header: {err:#}." ) ;
1499
1455
}
1500
1456
}
1501
- }
1502
- Err ( err) => {
1503
- warn ! ( context, "Couldn't parse NodeAddr: {err:#}." ) ;
1457
+ None => {
1458
+ warn ! (
1459
+ context,
1460
+ "Cannot add iroh peer because WebXDC instance does not exist."
1461
+ ) ;
1462
+ }
1463
+ } ,
1464
+ None => {
1465
+ warn ! (
1466
+ context,
1467
+ "Cannot add iroh peer because the message has no In-Reply-To."
1468
+ ) ;
1504
1469
}
1505
1470
}
1506
1471
}
0 commit comments