diff options
Diffstat (limited to 'src/irc')
-rw-r--r-- | src/irc/irc_channel.cpp | 5 | ||||
-rw-r--r-- | src/irc/irc_channel.hpp | 2 | ||||
-rw-r--r-- | src/irc/irc_client.cpp | 17 |
3 files changed, 13 insertions, 11 deletions
diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 1fd34aa..58f8d5c 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -33,8 +33,9 @@ IrcUser* IrcChannel::find_user(const std::string& name) const return nullptr; } -void IrcChannel::remove_user(const IrcUser* user) +std::unique_ptr<IrcUser> IrcChannel::remove_user(const IrcUser* user) { + std::unique_ptr<IrcUser> result{}; const auto nick = user->nick; const bool is_self = (user == this->self); const auto it = std::find_if(this->users.begin(), this->users.end(), @@ -44,6 +45,7 @@ void IrcChannel::remove_user(const IrcUser* user) }); if (it != this->users.end()) { + result = std::move(*it); this->users.erase(it); if (is_self) { @@ -57,4 +59,5 @@ void IrcChannel::remove_all_users() { this->users.clear(); this->self = nullptr; + return result; } diff --git a/src/irc/irc_channel.hpp b/src/irc/irc_channel.hpp index dff1b78..ee89209 100644 --- a/src/irc/irc_channel.hpp +++ b/src/irc/irc_channel.hpp @@ -32,8 +32,8 @@ public: IrcUser* add_user(const std::string& name, const std::map<char, char>& prefix_to_mode); IrcUser* find_user(const std::string& name) const; - void remove_user(const IrcUser* user); void remove_all_users(); + std::unique_ptr<IrcUser> remove_user(const IrcUser* user); const std::vector<std::unique_ptr<IrcUser>>& get_users() const { return this->users; } diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index a866726..c5ef36c 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -951,18 +951,18 @@ void IrcClient::on_part(const IrcMessage& message) { std::string nick = user->nick; bool self = channel->get_self() && channel->get_self()->nick == nick; - channel->remove_user(user); - Iid iid; - iid.set_local(chan_name); - iid.set_server(this->hostname); - iid.type = Iid::Type::Channel; + auto user_ptr = channel->remove_user(user); if (self) { this->channels.erase(utils::tolower(chan_name)); // channel pointer is now invalid channel = nullptr; } - this->bridge.send_muc_leave(iid, std::move(nick), txt, self, true); + Iid iid; + iid.set_local(chan_name); + iid.set_server(this->hostname); + iid.type = Iid::Type::Channel; + this->bridge.send_muc_leave(iid, *user_ptr, txt, self, true); } } @@ -979,8 +979,7 @@ void IrcClient::on_error(const IrcMessage& message) IrcChannel* channel = pair.second.get(); if (!channel->joined) continue; - std::string own_nick = channel->get_self()->nick; - this->bridge.send_muc_leave(iid, std::move(own_nick), leave_message, true, false); + this->bridge.send_muc_leave(iid, *channel->get_self(), leave_message, true, false); } this->channels.clear(); this->send_gateway_message("ERROR: " + leave_message); @@ -1005,7 +1004,7 @@ void IrcClient::on_quit(const IrcMessage& message) iid.set_local(chan_name); iid.set_server(this->hostname); iid.type = Iid::Type::Channel; - this->bridge.send_muc_leave(iid, user->nick, txt, self, false); + this->bridge.send_muc_leave(iid, *user, txt, self, false); channel->remove_user(user); } } |