From cb6b50dc0109ee3a201a4012b63f3914cc5ea6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 7 Nov 2017 23:05:05 +0100 Subject: Change how we count the number of connected resources to a server --- src/bridge/bridge.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 8587264..eb1d553 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -894,7 +894,19 @@ void Bridge::send_muc_leave(const Iid& iid, const std::string& nick, this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), this->user_jid + "/" + res, self, user_requested); if (self) - this->remove_all_resources_from_chan(iid.to_tuple()); + { + // Copy the resources currently in that channel + const auto resources_in_chan = this->resources_in_chan[iid.to_tuple()]; + + this->remove_all_resources_from_chan(iid.to_tuple()); + + // Now, for each resource that was in that channel, remove it from the server if it’s + // not in any other channel + for (const auto& r: resources_in_chan) + if (this->number_of_channels_the_resource_is_in(iid.get_server(), r) == 0) + this->remove_resource_from_server(iid.get_server(), r); + + } } IrcClient* irc = this->find_irc_client(iid.get_server()); @@ -1236,9 +1248,13 @@ std::size_t Bridge::number_of_channels_the_resource_is_in(const std::string& irc std::size_t res = 0; for (auto pair: this->resources_in_chan) { - if (std::get<0>(pair.first) == irc_hostname && pair.second.count(resource) != 0) + if (std::get<1>(pair.first) == irc_hostname && pair.second.count(resource) != 0) res++; } + + IrcClient* irc = this->find_irc_client(irc_hostname); + if (irc && (irc->get_dummy_channel().joined || irc->get_dummy_channel().joining)) + res++; return res; } -- cgit v1.2.3