If we sent a message to a user, their notices are considered private messages

fix #2882
This commit is contained in:
Florent Le Coz
2015-01-12 22:50:06 +01:00
parent 0ee47f628d
commit b79dbefbe7
3 changed files with 33 additions and 3 deletions
+4 -1
View File
@@ -1,5 +1,8 @@
Version 2.0 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 Version 1.1 2014-16-07
+25 -2
View File
@@ -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)})); this->send_message(IrcMessage(std::string(type), {username, body.substr(pos, 400)}));
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) 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]; const std::string body = message.arguments[1];
if (!to.empty() && this->chantypes.find(to[0]) == this->chantypes.end()) 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 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}); IrcMessage modified_message(std::move(from), "PRIVMSG", {to, "\u000303[notice]\u0003 "s + body});
this->on_channel_message(modified_message); this->on_channel_message(modified_message);
} }
+4
View File
@@ -289,6 +289,10 @@ private:
* connection succeeds on that port. * connection succeeds on that port.
*/ */
std::stack<std::pair<std::string, bool>> ports_to_try; 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(const IrcClient&) = delete;
IrcClient(IrcClient&&) = delete; IrcClient(IrcClient&&) = delete;