command/message: make messages/subscriptions local to the current partition

This commit is contained in:
Max Kellermann 2020-01-20 12:44:48 +01:00
parent 438a6d7595
commit fd2b2cf0bc
2 changed files with 12 additions and 1 deletions

View File

@ -1354,6 +1354,9 @@ additional services.
New messages are indicated by the ``message``
idle event.
If your MPD instance has multiple partitions, note that
client-to-client messages are local to the current partition.
:command:`subscribe {NAME}`
Subscribe to a channel. The channel is created if it
does not exist already. The name may consist of

View File

@ -78,7 +78,12 @@ handle_channels(Client &client, gcc_unused Request args, Response &r)
assert(args.empty());
std::set<std::string> channels;
const auto &partition = client.GetPartition();
for (const auto &c : *client.GetInstance().client_list) {
if (&c.GetPartition() != &partition)
continue;
const auto &subscriptions = c.GetSubscriptions();
channels.insert(subscriptions.begin(),
subscriptions.end());
@ -119,8 +124,11 @@ handle_send_message(Client &client, Request args, Response &r)
bool sent = false;
const ClientMessage msg(channel_name, message_text);
const auto &partition = client.GetPartition();
for (auto &c : *client.GetInstance().client_list)
if (c.PushMessage(msg))
if (&c.GetPartition() == &partition &&
c.PushMessage(msg))
sent = true;
if (sent)