diff options
author | louiz’ <louiz@louiz.org> | 2016-10-24 00:18:34 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2016-10-24 00:19:30 +0200 |
commit | 5990a8bf8ae622f075a7e2a12b2f5ac0cab8713b (patch) | |
tree | 9435e2de69d12734645116a58243667c8d4cee8c /src | |
parent | c3bb9fe2e2c2a0b2773e9b9824c4e675448b862f (diff) | |
download | biboumi-5990a8bf8ae622f075a7e2a12b2f5ac0cab8713b.tar.gz biboumi-5990a8bf8ae622f075a7e2a12b2f5ac0cab8713b.tar.bz2 biboumi-5990a8bf8ae622f075a7e2a12b2f5ac0cab8713b.tar.xz biboumi-5990a8bf8ae622f075a7e2a12b2f5ac0cab8713b.zip |
Correctly handle the nick change inside the virtual channel
Diffstat (limited to 'src')
-rw-r--r-- | src/irc/irc_client.cpp | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index 9877806..6a87b99 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -931,29 +931,38 @@ void IrcClient::on_quit(const IrcMessage& message) void IrcClient::on_nick(const IrcMessage& message) { - const std::string new_nick = message.arguments[0]; + const std::string new_nick = IrcUser(message.arguments[0]).nick; + const std::string current_nick = IrcUser(message.prefix).nick; + const auto change_nick_func = [&](const std::string& chan_name, const IrcChannel* channel) + { + IrcUser* user; + if (channel->get_self() && channel->get_self()->nick == current_nick) + user = channel->get_self(); + else + user = channel->find_user(current_nick); + if (user) + { + std::string old_nick = user->nick; + Iid iid(chan_name, this->hostname, Iid::Type::Channel); + const bool self = channel->get_self()->nick == old_nick; + const char user_mode = user->get_most_significant_mode(this->sorted_user_modes); + this->bridge.send_nick_change(std::move(iid), old_nick, new_nick, user_mode, self); + user->nick = new_nick; + if (self) + { + channel->get_self()->nick = new_nick; + this->current_nick = new_nick; + } + } + }; + + if (this->get_dummy_channel().joined) + { + change_nick_func("", &this->get_dummy_channel()); + } for (auto it = this->channels.begin(); it != this->channels.end(); ++it) { - const std::string chan_name = it->first; - IrcChannel* channel = it->second.get(); - IrcUser* user = channel->find_user(message.prefix); - if (user) - { - std::string old_nick = user->nick; - Iid iid; - iid.set_local(chan_name); - iid.set_server(this->hostname); - iid.type = Iid::Type::Channel; - const bool self = channel->get_self()->nick == old_nick; - const char user_mode = user->get_most_significant_mode(this->sorted_user_modes); - this->bridge.send_nick_change(std::move(iid), old_nick, new_nick, user_mode, self); - user->nick = new_nick; - if (self) - { - channel->get_self()->nick = new_nick; - this->current_nick = new_nick; - } - } + change_nick_func(it->first, it->second.get()); } } |