fix: ya pub-to 0 checks if any peer is able to receive the message (#2697)

Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
Mika Vilpas 2025-05-02 14:12:40 +03:00 committed by GitHub
parent 01a13fd664
commit 37e8747c01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -100,12 +100,22 @@ impl Client {
);
}
match peers.get(&receiver).map(|p| p.able(kind)) {
Some(true) => {}
Some(false) => {
match (receiver, peers.get(&receiver).map(|p| p.able(kind))) {
// Send to all receivers
(Id(0), _) if peers.is_empty() => {
bail!("No receiver found. Check if any receivers are running.")
}
(Id(0), _) if peers.values().all(|p| !p.able(kind)) => {
bail!("No receiver has the ability to receive `{kind}` messages.")
}
(Id(0), _) => {}
// Send to a specific receiver
(_, Some(true)) => {}
(_, Some(false)) => {
bail!("Receiver `{receiver}` does not have the ability to receive `{kind}` messages.")
}
None => bail!("Receiver `{receiver}` not found. Check if the receiver is running."),
(_, None) => bail!("Receiver `{receiver}` not found. Check if the receiver is running."),
}
Ok(())