1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 17:23:15 +02:00

irc: don't switch to buffer of joined channel if it was not manually joined nor present in server autojoin option

This commit is contained in:
Sébastien Helleu
2023-04-03 20:00:32 +02:00
parent b8f40cfa99
commit 1c3b871204
5 changed files with 87 additions and 5 deletions
+1
View File
@@ -56,6 +56,7 @@ Bug fixes::
* fset: remove scroll to top of fset buffer when options are added or removed (issue #1892)
* irc: fix join of channels in "autojoin" server option on first connection to server if auto reconnection is performed (issue #1873)
* irc: update autojoin option with redirected channels when autojoin_dynamic is enabled (issue #1898)
* irc: don't switch to buffer of joined channel if it was not manually joined nor present in server autojoin option
* irc: fix target buffer for commands 432/433 (erroneous nickname/nickname already in use) when the nickname looks like a channel
* spell: check buffer pointer received in info "spell_dict"
* typing: fix crash when pointer buffer is not received in callback for signal "input_text_changed" (issue #1869)
+10 -2
View File
@@ -33,6 +33,7 @@
#include "irc-color.h"
#include "irc-command.h"
#include "irc-config.h"
#include "irc-join.h"
#include "irc-modelist.h"
#include "irc-nick.h"
#include "irc-protocol.h"
@@ -247,7 +248,7 @@ irc_channel_create_buffer (struct t_irc_server *server,
{
struct t_gui_buffer *ptr_buffer, *ptr_buffer_for_merge;
int buffer_created, current_buffer_number, buffer_position;
int manual_join, noswitch;
int autojoin_join, manual_join, noswitch;
char str_number[32], *channel_name_lower, *buffer_name;
const char *short_name, *localvar_channel;
@@ -397,6 +398,10 @@ irc_channel_create_buffer (struct t_irc_server *server,
}
/* switch to new buffer (if needed) */
autojoin_join = irc_join_has_channel (
server,
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN),
channel_name);
manual_join = 0;
noswitch = 0;
channel_name_lower = NULL;
@@ -416,9 +421,12 @@ irc_channel_create_buffer (struct t_irc_server *server,
if (channel_type == IRC_CHANNEL_TYPE_CHANNEL)
{
if (noswitch
|| (!manual_join && !autojoin_join)
|| (manual_join && !weechat_config_boolean (irc_config_look_buffer_switch_join))
|| (!manual_join && !weechat_config_boolean (irc_config_look_buffer_switch_autojoin)))
|| (autojoin_join && !weechat_config_boolean (irc_config_look_buffer_switch_autojoin)))
{
switch_to_channel = 0;
}
}
if (switch_to_channel)
{
+42 -3
View File
@@ -379,6 +379,47 @@ end:
return (result) ? result : strdup ("");
}
/*
* Checks if a channel is in a join string.
*
* Returns:
* 1: channel found in join string (case insensitive comparison)
* 0: channel NOT found in join string
*/
int
irc_join_has_channel (struct t_irc_server *server,
const char *join, const char *channel_name)
{
struct t_arraylist *arraylist;
struct t_irc_join_channel *ptr_join_chan;
int i, found;
if (!join || !join[0] || !channel_name || !channel_name[0])
return 0;
arraylist = irc_join_split (server, join, 0);
if (!arraylist)
return 0;
found = 0;
for (i = 0; i < weechat_arraylist_size (arraylist); i++)
{
ptr_join_chan = (struct t_irc_join_channel *)weechat_arraylist_get (
arraylist, i);
if (irc_server_strcasecmp (server, ptr_join_chan->name,
channel_name) == 0)
{
found = 1;
break;
}
}
weechat_arraylist_free (arraylist);
return found;
}
/*
* Adds a channel with optional key to the join string.
*
@@ -800,9 +841,7 @@ irc_join_sort_autojoin (struct t_irc_server *server)
if (!ptr_autojoin || !ptr_autojoin[0])
return;
new_autojoin = irc_join_sort_channels (
server,
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN));
new_autojoin = irc_join_sort_channels (server, ptr_autojoin);
if (new_autojoin)
{
weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN],
+2
View File
@@ -32,6 +32,8 @@ extern struct t_arraylist *irc_join_split (struct t_irc_server *server,
const char *join,
int sort);
extern char *irc_join_build_string (struct t_arraylist *arraylist);
extern int irc_join_has_channel (struct t_irc_server *server,
const char *join, const char *channel_name);
extern char *irc_join_add_channel (struct t_irc_server *server,
const char *join, const char *channel_name,
const char *key);
+32
View File
@@ -351,6 +351,38 @@ TEST(IrcJoin, SplitBuildString)
irc_server_free (server);
}
/*
* Tests functions:
* irc_join_has_channel
*/
TEST(IrcJoin, HasChannel)
{
struct t_irc_server *server;
server = irc_server_alloc ("my_ircd");
CHECK(server);
LONGS_EQUAL(0, irc_join_has_channel (NULL, NULL, NULL));
LONGS_EQUAL(0, irc_join_has_channel (server, NULL, NULL));
LONGS_EQUAL(0, irc_join_has_channel (server, NULL, ""));
LONGS_EQUAL(0, irc_join_has_channel (server, "#abc,#def key_abc", NULL));
LONGS_EQUAL(0, irc_join_has_channel (server, "#abc,#def key_abc", ""));
LONGS_EQUAL(0, irc_join_has_channel (server, "#abc,#def key_abc", "#zzz"));
LONGS_EQUAL(1, irc_join_has_channel (NULL, "#abc,#def key_abc", "#abc"));
LONGS_EQUAL(1, irc_join_has_channel (NULL, "#abc,#def key_abc", "#ABC"));
LONGS_EQUAL(1, irc_join_has_channel (NULL, "#abc,#def key_abc", "#def"));
LONGS_EQUAL(1, irc_join_has_channel (NULL, "#abc,#def key_abc", "#DEF"));
LONGS_EQUAL(1, irc_join_has_channel (server, "#abc,#def key_abc", "#abc"));
LONGS_EQUAL(1, irc_join_has_channel (server, "#abc,#def key_abc", "#ABC"));
LONGS_EQUAL(1, irc_join_has_channel (server, "#abc,#def key_abc", "#def"));
LONGS_EQUAL(1, irc_join_has_channel (server, "#abc,#def key_abc", "#DEF"));
irc_server_free (server);
}
/*
* Tests functions:
* irc_join_add_channel