use crate::proxy::types::{ProxyAnnouncement, ProxyInfo, RemoteProxy};
use crate::synced_store::SyncedStore;
pub fn build_announcements(proxies: &[ProxyInfo]) -> Vec<ProxyAnnouncement> {
proxies
.iter()
.map(|p| ProxyAnnouncement {
id: p.id.clone(),
name: p.name.clone(),
listen_port: p.listen_port,
url: p.url.clone(),
})
.collect()
}
pub async fn extract_remote_proxies(
store: &SyncedStore<Vec<ProxyAnnouncement>>,
local_device_id: &str,
) -> Vec<RemoteProxy> {
store
.all()
.await
.into_iter()
.filter(|(device_id, _)| device_id != local_device_id)
.flat_map(|(device_id, slice)| {
slice.data.into_iter().map(move |a| RemoteProxy {
peer_id: device_id.clone(),
peer_name: String::new(), id: a.id,
name: a.name,
url: a.url,
listen_port: a.listen_port,
})
})
.collect()
}