p2p_chat/ui/runner/actions/
resolver.rs1use std::str::FromStr;
3
4use anyhow::{anyhow, Result};
5use libp2p::PeerId;
6
7use super::context::CommandContext;
8
9pub(crate) async fn resolve_peer_id(destination: &str, context: &CommandContext) -> Result<PeerId> {
22 if let Ok(peer_id) = PeerId::from_str(destination) {
23 return Ok(peer_id);
24 }
25
26 let friends = context.node().friends.list_friends().await?;
27 friends
28 .into_iter()
29 .find(|f| f.nickname.as_deref() == Some(destination))
30 .map(|f| f.peer_id)
31 .ok_or_else(|| anyhow!("Peer not found by ID or nickname: '{}'", destination))
32}