~singpolyma/biboumi

5739d418e2b35dfc038fe1a12f8b5c7eeeed6868 — Florent Le Coz 8 years ago 0d9c1ba
Better way to leave the dummy room
M src/bridge/bridge.cpp => src/bridge/bridge.cpp +3 -1
@@ 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);
  }
}


M src/irc/irc_channel.cpp => src/irc/irc_channel.cpp +6 -0
@@ 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)

M src/irc/irc_channel.hpp => src/irc/irc_channel.hpp +1 -0
@@ 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;

M src/irc/irc_client.cpp => src/irc/irc_client.cpp +11 -1
@@ 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);
}

M src/irc/irc_client.hpp => src/irc/irc_client.hpp +5 -0
@@ 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; }