summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-09-14 14:51:50 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-09-14 14:51:50 +0200
commit049e9d23c5b91e0af17b8b44c26216beee05b0dd (patch)
treea2608f921f78ab3bdb712f285218e53fe7299c6e
parent4c3ab508c728c486306e21ed08ab98bc06e3aa95 (diff)
downloadweechat-049e9d23c5b91e0af17b8b44c26216beee05b0dd.zip
irc: open a query buffer on PRIVMSG received from self nick when capability echo-message is NOT enabled (issue #2016)
-rw-r--r--src/plugins/irc/irc-protocol.c7
-rw-r--r--tests/unit/plugins/irc/test-irc-protocol.cpp70
2 files changed, 54 insertions, 23 deletions
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 4d1c1e41c..68f7422d4 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -3109,6 +3109,9 @@ IRC_PROTOCOL_CALLBACK(privmsg)
pos_target++;
}
+ cap_echo_message = weechat_hashtable_has_key (server->cap_list,
+ "echo-message");
+
/* receiver is a channel ? */
if (is_channel)
{
@@ -3233,8 +3236,6 @@ IRC_PROTOCOL_CALLBACK(privmsg)
/* CTCP to user */
if (msg_args[0] == '\01')
{
- cap_echo_message = weechat_hashtable_has_key (server->cap_list,
- "echo-message");
msg_already_received = weechat_hashtable_has_key (
server->echo_msg_recv, irc_message);
if (!msg_already_received && cap_echo_message)
@@ -3264,7 +3265,7 @@ IRC_PROTOCOL_CALLBACK(privmsg)
if (strcmp (ptr_channel->name, remote_nick) != 0)
irc_channel_pv_rename (server, ptr_channel, remote_nick);
}
- else if (!nick_is_me)
+ else if (!nick_is_me || !cap_echo_message)
{
ptr_channel = irc_channel_new (server,
IRC_CHANNEL_TYPE_PRIVATE,
diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp
index c9ed785d9..abda9ebea 100644
--- a/tests/unit/plugins/irc/test-irc-protocol.cpp
+++ b/tests/unit/plugins/irc/test-irc-protocol.cpp
@@ -155,6 +155,12 @@ extern char *irc_protocol_cap_to_enable (const char *capabilities,
FAIL(string_dyn_free (msg, 0)); \
}
+#define CHECK_PV_CLOSE(__nick, __prefix, __message, __tags) \
+ CHECK_PV(__nick, __prefix, __message, __tags); \
+ gui_buffer_close ( \
+ gui_buffer_search_by_full_name ("irc." IRC_FAKE_SERVER \
+ "." __nick));
+
#define CHECK_NO_MSG \
if (arraylist_size (recorded_messages) > 0) \
{ \
@@ -2738,9 +2744,9 @@ TEST(IrcProtocolWithServer, privmsg)
"irc_privmsg,notify_message,prefix_nick_248,nick_bob,"
"host_user@host,log1");
RECV(":bob!user@host PRIVMSG alice :this is the message ");
- CHECK_PV("bob", "bob", "this is the message ",
- "irc_privmsg,notify_private,prefix_nick_248,nick_bob,"
- "host_user@host,log1");
+ CHECK_PV_CLOSE("bob", "bob", "this is the message ",
+ "irc_privmsg,notify_private,prefix_nick_248,nick_bob,"
+ "host_user@host,log1");
/* message with tags to channel/user */
RECV("@tag1=value1;tag2=value2 :bob!user@host PRIVMSG #test "
@@ -2750,9 +2756,9 @@ TEST(IrcProtocolWithServer, privmsg)
"notify_message,prefix_nick_248,nick_bob,host_user@host,log1");
RECV("@tag1=value1;tag2=value2 :bob!user@host PRIVMSG alice "
":this is the message ");
- CHECK_PV("bob", "bob", "this is the message ",
- "irc_privmsg,irc_tag_tag1=value1,irc_tag_tag2=value2,"
- "notify_private,prefix_nick_248,nick_bob,host_user@host,log1");
+ CHECK_PV_CLOSE("bob", "bob", "this is the message ",
+ "irc_privmsg,irc_tag_tag1=value1,irc_tag_tag2=value2,"
+ "notify_private,prefix_nick_248,nick_bob,host_user@host,log1");
/*
* message to channel/user from self nick
@@ -2781,19 +2787,43 @@ TEST(IrcProtocolWithServer, privmsg)
* message from self nick in private
* (case of bouncer or if echo-message capability is enabled)
*/
- RECV(":alice!user@host PRIVMSG bob2 :this is the message ");
- CHECK_SRV("--", "Msg(alice) -> bob2: this is the message ",
- "irc_privmsg,self_msg,notify_none,no_highlight,"
- "nick_alice,host_user@host,log1");
+ if (i == 0)
+ {
+ /* without echo-message */
+ RECV(":alice!user@host PRIVMSG bob :this is the message ");
+ CHECK_PV_CLOSE("bob", "alice", "this is the message ",
+ "irc_privmsg,self_msg,notify_none,no_highlight,"
+ "prefix_nick_white,nick_alice,host_user@host,log1");
+ }
+ else
+ {
+ /* with echo-message */
+ RECV(":alice!user@host PRIVMSG bob :this is the message ");
+ CHECK_SRV("--", "Msg(alice) -> bob: this is the message ",
+ "irc_privmsg,self_msg,notify_none,no_highlight,"
+ "nick_alice,host_user@host,log1");
+ }
/*
* message from self nick in private, with password hidden (nickserv)
* (case of bouncer or if echo-message capability is enabled)
*/
- RECV(":alice!user@host PRIVMSG nickserv :identify secret");
- CHECK_SRV("--", "Msg(alice) -> nickserv: identify ******",
- "irc_privmsg,self_msg,notify_none,no_highlight,"
- "nick_alice,host_user@host,log1");
+ if (i == 0)
+ {
+ /* without echo-message */
+ RECV(":alice!user@host PRIVMSG nickserv :identify secret");
+ CHECK_PV_CLOSE("nickserv", "alice", "identify ******",
+ "irc_privmsg,self_msg,notify_none,no_highlight,"
+ "prefix_nick_white,nick_alice,host_user@host,log1");
+ }
+ else
+ {
+ /* with echo-message */
+ RECV(":alice!user@host PRIVMSG nickserv :identify secret");
+ CHECK_SRV("--", "Msg(alice) -> nickserv: identify ******",
+ "irc_privmsg,self_msg,notify_none,no_highlight,"
+ "nick_alice,host_user@host,log1");
+ }
/* broken CTCP to channel */
RECV(":bob!user@host PRIVMSG #test :\01");
@@ -2843,13 +2873,13 @@ TEST(IrcProtocolWithServer, privmsg)
CHECK_SRV("--", "Unknown CTCP requested by bob: TEST",
"irc_privmsg,irc_ctcp,host_user@host,log1");
RECV(":bob!user@host PRIVMSG alice :\01ACTION");
- CHECK_PV("bob", " *", "bob",
- "irc_privmsg,irc_action,notify_private,nick_bob,"
- "host_user@host,log1");
+ CHECK_PV_CLOSE("bob", " *", "bob",
+ "irc_privmsg,irc_action,notify_private,nick_bob,"
+ "host_user@host,log1");
RECV(":bob!user@host PRIVMSG alice :\01ACTION is testing");
- CHECK_PV("bob", " *", "bob is testing",
- "irc_privmsg,irc_action,notify_private,nick_bob,"
- "host_user@host,log1");
+ CHECK_PV_CLOSE("bob", " *", "bob is testing",
+ "irc_privmsg,irc_action,notify_private,nick_bob,"
+ "host_user@host,log1");
RECV(":bob!user@host PRIVMSG alice :\01VERSION");
info = irc_ctcp_eval_reply (ptr_server,
irc_ctcp_get_reply (ptr_server, "VERSION"));