fix: DDS static messages only work when at least two instances are running (#1467)

This commit is contained in:
三咲雅 · Misaki Masa 2024-08-11 16:38:25 +08:00 committed by GitHub
parent ce944bca88
commit 44f45fd8e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View file

@ -72,10 +72,10 @@ impl Pubsub {
return Self::pub_(body); return Self::pub_(body);
} }
let (kind, peers) = (body.kind(), PEERS.read()); let kind = body.kind();
if receiver == 0 && peers.values().any(|c| c.able(kind)) { if receiver == 0 && Self::any_remote_own(kind) {
Client::push(body); Client::push(body);
} else if peers.get(&receiver).is_some_and(|c| c.able(kind)) { } else if PEERS.read().get(&receiver).is_some_and(|c| c.able(kind)) {
Client::push(body.with_receiver(receiver)); Client::push(body.with_receiver(receiver));
} }
} }
@ -140,7 +140,7 @@ impl Pubsub {
if LOCAL.read().contains_key("@yank") { if LOCAL.read().contains_key("@yank") {
Self::pub_(BodyYank::dummy()); Self::pub_(BodyYank::dummy());
} }
if Self::own_static_ability("@yank") { if Self::any_remote_own("@yank") {
Client::push(BodyYank::borrowed(cut, urls)); Client::push(BodyYank::borrowed(cut, urls));
} }
if BOOT.local_events.contains("@yank") { if BOOT.local_events.contains("@yank") {
@ -185,7 +185,7 @@ impl Pubsub {
} }
#[inline] #[inline]
fn own_static_ability(kind: &str) -> bool { fn any_remote_own(kind: &str) -> bool {
REMOTE.read().contains_key(kind) // Owned abilities REMOTE.read().contains_key(kind) // Owned abilities
|| PEERS.read().values().any(|p| p.able(kind)) // Remote peers' abilities || PEERS.read().values().any(|p| p.able(kind)) // Remote peers' abilities
|| BOOT.remote_events.contains(kind) // Owned abilities from the command-line argument || BOOT.remote_events.contains(kind) // Owned abilities from the command-line argument

View file

@ -72,7 +72,7 @@ impl Server {
} }
line.push('\n'); line.push('\n');
clients.into_iter().filter(|c| c.id != id).for_each(|c| _ = c.tx.send(line.clone())); clients.into_iter().for_each(|c| _ = c.tx.send(line.clone()));
} }
else => break else => break
} }