summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2022-03-07 07:16:24 +0100
committerSébastien Helleu <flashcode@flashtux.org>2022-03-10 21:12:46 +0100
commitbb03e184259086ee522e28d490ced5ea2d1778e5 (patch)
treed92f69739b7a1e3baf61416236a26169e090f670 /src/plugins/irc
parent5d809df6ede402920543fd7041707df6439c7955 (diff)
downloadweechat-bb03e184259086ee522e28d490ced5ea2d1778e5.zip
irc: display only one message in /autojoin command output
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-command.c62
-rw-r--r--src/plugins/irc/irc-join.c67
-rw-r--r--src/plugins/irc/irc-join.h10
3 files changed, 60 insertions, 79 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index 648ad3930..a968d983c 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -903,6 +903,8 @@ IRC_COMMAND_CALLBACK(auth)
IRC_COMMAND_CALLBACK(autojoin)
{
struct t_irc_channel *ptr_channel2;
+ const char *ptr_autojoin;
+ char *old_autojoin;
int i;
IRC_BUFFER_GET_SERVER_CHANNEL(buffer);
@@ -914,6 +916,10 @@ IRC_COMMAND_CALLBACK(autojoin)
WEECHAT_COMMAND_MIN_ARGS(2, "");
+ ptr_autojoin = IRC_SERVER_OPTION_STRING(ptr_server,
+ IRC_SERVER_OPTION_AUTOJOIN);
+ old_autojoin = strdup ((ptr_autojoin) ? ptr_autojoin : "");
+
/* add channel(s) */
if (weechat_strcasecmp (argv[1], "add") == 0)
{
@@ -927,10 +933,10 @@ IRC_COMMAND_CALLBACK(autojoin)
_("%s%s: \"%s\" command can only be executed in a channel "
"buffer"),
weechat_prefix ("error"), IRC_PLUGIN_NAME, "autojoin add");
- return WEECHAT_RC_OK;
+ goto end;
}
irc_join_add_channel_to_autojoin (ptr_server, ptr_channel->name,
- ptr_channel->key, 1);
+ ptr_channel->key);
}
for (i = 2; i < argc; i++)
{
@@ -939,23 +945,22 @@ IRC_COMMAND_CALLBACK(autojoin)
{
irc_join_add_channel_to_autojoin (ptr_server,
ptr_channel2->name,
- ptr_channel2->key,
- 1);
+ ptr_channel2->key);
}
else
{
- irc_join_add_channel_to_autojoin (ptr_server, argv[i], NULL, 1);
+ irc_join_add_channel_to_autojoin (ptr_server, argv[i], NULL);
}
}
- return WEECHAT_RC_OK;
+ goto end;
}
/* add raw channel(s) */
if (weechat_strcasecmp (argv[1], "addraw") == 0)
{
WEECHAT_COMMAND_MIN_ARGS(3, "addraw");
- irc_join_add_channels_to_autojoin (ptr_server, argv_eol[2], 1);
- return WEECHAT_RC_OK;
+ irc_join_add_channels_to_autojoin (ptr_server, argv_eol[2]);
+ goto end;
}
/* delete channel(s) */
@@ -971,25 +976,47 @@ IRC_COMMAND_CALLBACK(autojoin)
_("%s%s: \"%s\" command can only be executed in a channel "
"buffer"),
weechat_prefix ("error"), IRC_PLUGIN_NAME, "autojoin add");
- return WEECHAT_RC_OK;
+ goto end;
}
irc_join_remove_channel_from_autojoin (ptr_server,
- ptr_channel->name,
- 1);
+ ptr_channel->name);
}
for (i = 2; i < argc; i++)
{
- irc_join_remove_channel_from_autojoin (ptr_server, argv[i], 1);
+ irc_join_remove_channel_from_autojoin (ptr_server, argv[i]);
}
- return WEECHAT_RC_OK;
+ goto end;
}
/* save currently joined channels */
if (weechat_strcasecmp (argv[1], "save") == 0)
{
- irc_join_save_channels_to_autojoin (ptr_server, 1);
- return WEECHAT_RC_OK;
+ irc_join_save_channels_to_autojoin (ptr_server);
+ goto end;
+ }
+
+end:
+ ptr_autojoin = IRC_SERVER_OPTION_STRING(ptr_server,
+ IRC_SERVER_OPTION_AUTOJOIN);
+ if ((old_autojoin && !ptr_autojoin) || (!old_autojoin && ptr_autojoin)
+ || (strcmp (old_autojoin, ptr_autojoin) != 0))
+ {
+ if (old_autojoin && old_autojoin[0])
+ {
+ weechat_printf (ptr_server->buffer,
+ _("Autojoin changed from \"%s\" to \"%s\""),
+ old_autojoin,
+ ptr_autojoin);
+ }
+ else
+ {
+ weechat_printf (ptr_server->buffer,
+ _("Autojoin changed from empty value to \"%s\""),
+ ptr_autojoin);
+ }
}
+ if (old_autojoin)
+ free (old_autojoin);
return WEECHAT_RC_OK;
}
@@ -2869,7 +2896,7 @@ irc_command_join_server (struct t_irc_server *server, const char *arguments,
if (save_autojoin)
{
irc_join_add_channel_to_autojoin (server, pos_channel,
- ptr_key, 0);
+ ptr_key);
}
}
}
@@ -4253,8 +4280,7 @@ IRC_COMMAND_CALLBACK(part)
{
for (i = 0; i < num_channels; i++)
{
- irc_join_remove_channel_from_autojoin (ptr_server,
- channels[i], 0);
+ irc_join_remove_channel_from_autojoin (ptr_server, channels[i]);
}
weechat_string_free_split (channels);
}
diff --git a/src/plugins/irc/irc-join.c b/src/plugins/irc/irc-join.c
index 48df3f374..7e350b530 100644
--- a/src/plugins/irc/irc-join.c
+++ b/src/plugins/irc/irc-join.c
@@ -352,58 +352,12 @@ irc_join_add_channels (struct t_irc_server *server,
}
/*
- * Sets server autojoin option.
- *
- * If verbose == 1, displays a message on the server buffer with old and new
- * autojoin value.
- */
-
-void
-irc_join_set_autojoin (struct t_irc_server *server, const char *autojoin,
- int verbose)
-{
- const char *ptr_old_autojoin;
- char *old_autojoin;
-
- if (!server)
- return;
-
- ptr_old_autojoin = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN);
- old_autojoin = (ptr_old_autojoin && ptr_old_autojoin[0]) ?
- strdup (ptr_old_autojoin) : NULL;
-
- weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN],
- autojoin, 1);
-
- if (verbose)
- {
- if (old_autojoin)
- {
- weechat_printf (server->buffer,
- _("Autojoin changed from \"%s\" to \"%s\""),
- old_autojoin,
- autojoin);
- }
- else
- {
- weechat_printf (server->buffer,
- _("Autojoin changed from empty value to \"%s\""),
- autojoin);
- }
- }
-
- if (old_autojoin)
- free (old_autojoin);
-}
-
-/*
* Adds a channel with optional key to the autojoin option of a server.
*/
void
irc_join_add_channel_to_autojoin (struct t_irc_server *server,
- const char *channel_name, const char *key,
- int verbose)
+ const char *channel_name, const char *key)
{
char *new_autojoin;
@@ -417,7 +371,8 @@ irc_join_add_channel_to_autojoin (struct t_irc_server *server,
key);
if (new_autojoin)
{
- irc_join_set_autojoin (server, new_autojoin, verbose);
+ weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN],
+ new_autojoin, 1);
free (new_autojoin);
}
}
@@ -428,7 +383,7 @@ irc_join_add_channel_to_autojoin (struct t_irc_server *server,
void
irc_join_add_channels_to_autojoin (struct t_irc_server *server,
- const char *join, int verbose)
+ const char *join)
{
char *new_autojoin;
@@ -438,7 +393,8 @@ irc_join_add_channels_to_autojoin (struct t_irc_server *server,
join);
if (new_autojoin)
{
- irc_join_set_autojoin (server, new_autojoin, verbose);
+ weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN],
+ new_autojoin, 1);
free (new_autojoin);
}
}
@@ -496,8 +452,7 @@ irc_join_remove_channel (struct t_irc_server *server,
void
irc_join_remove_channel_from_autojoin (struct t_irc_server *server,
- const char *channel_name,
- int verbose)
+ const char *channel_name)
{
char *new_autojoin;
@@ -510,7 +465,8 @@ irc_join_remove_channel_from_autojoin (struct t_irc_server *server,
channel_name);
if (new_autojoin)
{
- irc_join_set_autojoin (server, new_autojoin, verbose);
+ weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN],
+ new_autojoin, 1);
free (new_autojoin);
}
}
@@ -520,7 +476,7 @@ irc_join_remove_channel_from_autojoin (struct t_irc_server *server,
*/
void
-irc_join_save_channels_to_autojoin (struct t_irc_server *server, int verbose)
+irc_join_save_channels_to_autojoin (struct t_irc_server *server)
{
struct t_arraylist *arraylist;
struct t_irc_channel *ptr_channel;
@@ -554,7 +510,8 @@ irc_join_save_channels_to_autojoin (struct t_irc_server *server, int verbose)
new_autojoin = irc_join_build_string (arraylist);
if (new_autojoin)
{
- irc_join_set_autojoin (server, new_autojoin, verbose);
+ weechat_config_option_set (server->options[IRC_SERVER_OPTION_AUTOJOIN],
+ new_autojoin, 1);
free (new_autojoin);
}
diff --git a/src/plugins/irc/irc-join.h b/src/plugins/irc/irc-join.h
index bdc53d51b..eb1d396fd 100644
--- a/src/plugins/irc/irc-join.h
+++ b/src/plugins/irc/irc-join.h
@@ -38,16 +38,14 @@ extern char *irc_join_add_channels (struct t_irc_server *server,
const char *join, const char *join2);
extern void irc_join_add_channel_to_autojoin (struct t_irc_server *server,
const char *channel_name,
- const char *key, int verbose);
+ const char *key);
extern void irc_join_add_channels_to_autojoin (struct t_irc_server *server,
- const char *join, int verbose);
+ const char *join);
extern char *irc_join_remove_channel (struct t_irc_server *server,
const char *join,
const char *channel_name);
extern void irc_join_remove_channel_from_autojoin (struct t_irc_server *server,
- const char *channel_name,
- int verbose);
-extern void irc_join_save_channels_to_autojoin (struct t_irc_server *server,
- int verbose);
+ const char *channel_name);
+extern void irc_join_save_channels_to_autojoin (struct t_irc_server *server);
#endif /* WEECHAT_PLUGIN_IRC_JOIN_H */