Commit 5739d418 authored by louiz’'s avatar louiz’

Better way to leave the dummy room

parent 0d9c1ba3
......@@ -44,7 +44,9 @@ void Bridge::shutdown()
{
for (auto it = this->irc_clients.begin(); it != this->irc_clients.end(); ++it)
{
it->second->send_quit_command("Gateway shutdown");
const std::string exit_message("Gateway shutdown");
it->second->send_quit_command(exit_message);
it->second->leave_dummy_channel(exit_message);
}
}
......
......@@ -48,6 +48,12 @@ void IrcChannel::remove_user(const IrcUser* user)
}
}
void IrcChannel::remove_all_users()
{
this->users.clear();
this->self.reset();
}
DummyIrcChannel::DummyIrcChannel():
IrcChannel(),
joining(false)
......
......@@ -24,6 +24,7 @@ public:
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();
protected:
std::unique_ptr<IrcUser> self;
......
......@@ -199,7 +199,7 @@ void IrcClient::send_part_command(const std::string& chan_name, const std::strin
if (channel->joined == true)
{
if (chan_name.empty())
this->bridge->send_muc_leave(Iid(std::string("%") + this->hostname), std::string(this->current_nick), "", true);
this->leave_dummy_channel(status_message);
else
this->send_message(IrcMessage("PART", {chan_name, status_message}));
}
......@@ -652,3 +652,13 @@ DummyIrcChannel& IrcClient::get_dummy_channel()
{
return this->dummy_channel;
}
void IrcClient::leave_dummy_channel(const std::string& exit_message)
{
if (!this->dummy_channel.joined)
return;
this->dummy_channel.joined = false;
this->dummy_channel.joining = false;
this->dummy_channel.remove_all_users();
this->bridge->send_muc_leave(Iid(std::string("%") + this->hostname), std::string(this->current_nick), exit_message, true);
}
......@@ -198,6 +198,11 @@ public:
* Get a reference to the unique dummy channel
*/
DummyIrcChannel& get_dummy_channel();
/**
* Leave the dummy channel: forward a message to the user to indicate that
* he left it, and mark it as not joined.
*/
void leave_dummy_channel(const std::string& exit_message);
const std::string& get_hostname() const { return this->hostname; }
std::string get_nick() const { return this->current_nick; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment