~singpolyma/biboumi

b79dbefbe71824d8d42c5034a6900644a0850c4c — Florent Le Coz 7 years ago 0ee47f6
If we sent a message to a user, their notices are considered private messages

fix #2882
3 files changed, 33 insertions(+), 3 deletions(-)

M CHANGELOG
M src/irc/irc_client.cpp
M src/irc/irc_client.hpp
M CHANGELOG => CHANGELOG +4 -1
@@ 1,5 1,8 @@
Version 2.0
- Support PING requests in all directions
 - Support PING requests in all directions
 - Improve the way we forward received NOTICEs by remembering to
   which users we previously sent a private message.  This improves the
   user experience when talking to NickServ.

Version 1.1                                             2014-16-07


M src/irc/irc_client.cpp => src/irc/irc_client.cpp +25 -2
@@ 243,7 243,9 @@ void IrcClient::send_private_message(const std::string& username, const std::str
      this->send_message(IrcMessage(std::string(type), {username, body.substr(pos, 400)}));
      pos += 400;
    }

  // We always try to insert and we don't care if the username was already
  // in the set.
  this->nicks_to_treat_as_private.insert(username);
}

void IrcClient::send_part_command(const std::string& chan_name, const std::string& status_message)


@@ 292,9 294,30 @@ void IrcClient::on_notice(const IrcMessage& message)
  const std::string body = message.arguments[1];

  if (!to.empty() && this->chantypes.find(to[0]) == this->chantypes.end())
    this->bridge->send_xmpp_message(this->hostname, from, body);
    {
      // The notice is for the us precisely.

      // Find out if we already sent a private message to this user. If yes
      // we treat that message as a private message coming from
      // it. Otherwise we treat it as a notice coming from the server.
      IrcUser user(from);
      std::string nick = utils::tolower(user.nick);
      log_debug("received notice from nick: " << nick);
      if (this->nicks_to_treat_as_private.find(nick) !=
          this->nicks_to_treat_as_private.end())
        { // We previously sent a message to that nick)
          // this->bridge->send_message(iid, nick, body, muc);
          this->bridge->send_message({nick + "!" + this->hostname}, nick, body,
                                     false);
        }
      else
        this->bridge->send_xmpp_message(this->hostname, from, body);
    }
  else
    {
      // The notice was directed at a channel we are in. Modify the message
      // to indicate that it is a notice, and make it a MUC message coming
      // from the MUC JID
      IrcMessage modified_message(std::move(from), "PRIVMSG", {to, "\u000303[notice]\u0003 "s + body});
      this->on_channel_message(modified_message);
    }

M src/irc/irc_client.hpp => src/irc/irc_client.hpp +4 -0
@@ 289,6 289,10 @@ private:
   * connection succeeds on that port.
   */
  std::stack<std::pair<std::string, bool>> ports_to_try;
  /**
   * A set of (lowercase) nicknames to which we sent a private message.
   */
  std::set<std::string> nicks_to_treat_as_private;

  IrcClient(const IrcClient&) = delete;
  IrcClient(IrcClient&&) = delete;