diff options
author | louiz’ <louiz@louiz.org> | 2016-06-10 10:00:48 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2016-06-10 10:00:48 +0200 |
commit | 272c0e4995f2fe94fb2366c15453fdada341861a (patch) | |
tree | c1023991d62b9e4b0e798ba82bfdc25e00024724 /src/bridge | |
parent | 7540f6793342aeb1e9cec53208b347ca8a346c36 (diff) | |
download | biboumi-272c0e4995f2fe94fb2366c15453fdada341861a.tar.gz biboumi-272c0e4995f2fe94fb2366c15453fdada341861a.tar.bz2 biboumi-272c0e4995f2fe94fb2366c15453fdada341861a.tar.xz biboumi-272c0e4995f2fe94fb2366c15453fdada341861a.zip |
Reset the preferred private JID when all resources leave a room
For example if we are talking in private with nick Joe from
room #foo, and then we leave that room, we start receiving Joe’s
message from the server-wide JID
e2e tests included!!!
Diffstat (limited to 'src/bridge')
-rw-r--r-- | src/bridge/bridge.cpp | 19 | ||||
-rw-r--r-- | src/bridge/bridge.hpp | 5 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 95ca68e..3a7a147 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -344,7 +344,12 @@ void Bridge::leave_irc_channel(Iid&& iid, std::string&& status_message, const st const auto resources = this->number_of_resources_in_chan(key); if (resources == 1) - irc->send_part_command(iid.get_local(), status_message); + { + irc->send_part_command(iid.get_local(), status_message); + // Since there are no resources left in that channel, we don't + // want to receive private messages using this room's JID + this->remove_all_preferred_from_jid_of_room(iid.get_local()); + } else { IrcChannel* chan = irc->get_channel(iid.get_local()); @@ -767,6 +772,18 @@ void Bridge::remove_preferred_from_jid(const std::string& nick) this->preferred_user_from.erase(it); } +void Bridge::remove_all_preferred_from_jid_of_room(const std::string& channel_name) +{ + for (auto it = this->preferred_user_from.begin(); it != this->preferred_user_from.end();) + { + Iid iid(Jid(it->second).local); + if (iid.get_local() == channel_name) + it = this->preferred_user_from.erase(it); + else + ++it; + } +} + void Bridge::add_waiting_irc(irc_responder_callback_t&& callback) { this->waiting_irc.emplace_back(std::move(callback)); diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp index eabd9af..01f8f78 100644 --- a/src/bridge/bridge.hpp +++ b/src/bridge/bridge.hpp @@ -186,6 +186,11 @@ public: */ void remove_preferred_from_jid(const std::string& nick); /** + * Given a channel_name, remove all preferred from_jid that come + * from this chan. + */ + void remove_all_preferred_from_jid_of_room(const std::string& channel_name); + /** * Add a callback to the waiting list of irc callbacks. */ void add_waiting_irc(irc_responder_callback_t&& callback); |