diff options
author | louiz’ <louiz@louiz.org> | 2016-07-03 15:43:11 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2016-07-03 16:01:15 +0200 |
commit | 0ce75ab52111ba27ca99961057b36b68f0a135a8 (patch) | |
tree | 5602c9c6be700c7f11b4cb12625c8b23fbcc2bd9 /src/bridge | |
parent | dadfc349d96ca7d365d5d073e2f10f8f71f16bf2 (diff) | |
download | biboumi-0ce75ab52111ba27ca99961057b36b68f0a135a8.tar.gz biboumi-0ce75ab52111ba27ca99961057b36b68f0a135a8.tar.bz2 biboumi-0ce75ab52111ba27ca99961057b36b68f0a135a8.tar.xz biboumi-0ce75ab52111ba27ca99961057b36b68f0a135a8.zip |
Properly remove the resource from the server when we leave the last channel
Diffstat (limited to 'src/bridge')
-rw-r--r-- | src/bridge/bridge.cpp | 15 | ||||
-rw-r--r-- | src/bridge/bridge.hpp | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 6de2516..613e0e2 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -349,9 +349,11 @@ void Bridge::leave_irc_channel(Iid&& iid, std::string&& status_message, const st this->send_muc_leave(std::move(iid), std::move(nick), "Biboumi note: "s + std::to_string(resources - 1) + " resources are still in this channel.", true, resource); + if (this->number_of_channels_the_resource_is_in(iid.get_server(), resource) == 0) + this->remove_resource_from_server(iid.get_server(), resource); } } - } +} void Bridge::send_irc_nick_change(const Iid& iid, const std::string& new_nick) { @@ -868,6 +870,17 @@ std::size_t Bridge::number_of_resources_in_chan(const Bridge::ChannelKey& channe return it->second.size(); } +std::size_t Bridge::number_of_channels_the_resource_is_in(const std::string& irc_hostname, const std::string& resource) const +{ + 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) + res++; + } + return res; +} + void Bridge::generate_channel_join_for_resource(const Iid& iid, const std::string& resource) { IrcClient* irc = this->get_irc_client(iid.get_server()); diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index 6feb282..3430b06 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -278,6 +278,7 @@ private: void add_resource_to_server(const IrcHostname& irc_hostname, const std::string& resource); void remove_resource_from_server(const IrcHostname& irc_hostname, const std::string& resource); bool is_resource_in_server(const IrcHostname& irc_hostname, const std::string& resource) const; + size_t number_of_channels_the_resource_is_in(const std::string& irc_hostname, const std::string& resource) const; /** * Generate all the stanzas to be sent to this resource, simulating a join on this channel. |