1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-02 07:46:38 +02:00

irc: add option "-noswitch" for command /join (task #12275)

This commit is contained in:
Sebastien Helleu
2012-10-09 21:33:09 +02:00
parent aa6b886386
commit 5cfeb2f2bc
28 changed files with 338 additions and 176 deletions
+70 -30
View File
@@ -106,7 +106,7 @@ char *irc_server_chanmodes_default = "beI,k,l";
const char *irc_server_send_default_tags = NULL; /* default tags when */
/* sending a message */
time_t irc_server_last_check_manual_joins = 0;
time_t irc_server_last_check_join_channels = 0;
void irc_server_reconnect (struct t_irc_server *server);
@@ -912,16 +912,21 @@ irc_server_alloc (const char *name)
new_server->last_redirect = NULL;
new_server->notify_list = NULL;
new_server->last_notify = NULL;
new_server->manual_joins = weechat_hashtable_new (4,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_INTEGER,
NULL,
NULL);
new_server->channel_join_key = weechat_hashtable_new (4,
new_server->join_manual = weechat_hashtable_new (4,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_INTEGER,
NULL,
NULL);
new_server->join_channel_key = weechat_hashtable_new (4,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
new_server->join_noswitch = weechat_hashtable_new (4,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
new_server->buffer = NULL;
new_server->buffer_as_string = NULL;
new_server->channels = NULL;
@@ -1368,8 +1373,9 @@ irc_server_free_data (struct t_irc_server *server)
irc_server_outqueue_free_all (server, i);
}
irc_notify_free_all (server);
weechat_hashtable_free (server->manual_joins);
weechat_hashtable_free (server->channel_join_key);
weechat_hashtable_free (server->join_manual);
weechat_hashtable_free (server->join_channel_key);
weechat_hashtable_free (server->join_noswitch);
irc_redirect_free_all (server);
if (server->channels)
irc_channel_free_all (server);
@@ -2605,21 +2611,41 @@ irc_server_timer_sasl_cb (void *data, int remaining_calls)
}
/*
* irc_server_check_manual_joins_cb: callback called for each manual join of a
* server, it will delete old channels in
* this hashtable
* irc_server_check_join_manual_cb: callback called for each manual join of a
* server, it will delete old channels in
* this hashtable
*/
void
irc_server_check_manual_joins_cb (void *data, struct t_hashtable *hashtable,
const void *key, const void *value)
irc_server_check_join_manual_cb (void *data, struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_irc_server *server;
server = (struct t_irc_server *)data;
if (server)
{
if (*((int *)value) + 60 < time (NULL))
if (*((int *)value) + (60 * 5) < time (NULL))
weechat_hashtable_remove (hashtable, key);
}
}
/*
* irc_server_check_join_noswitch_cb: callback called for each join without
* switch of a server, it will delete old
* channels in this hashtable
*/
void
irc_server_check_join_noswitch_cb (void *data, struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_irc_server *server;
server = (struct t_irc_server *)data;
if (server)
{
if (*((int *)value) + (60 * 5) < time (NULL))
weechat_hashtable_remove (hashtable, key);
}
}
@@ -2738,12 +2764,19 @@ irc_server_timer_cb (void *data, int remaining_calls)
ptr_redirect = ptr_next_redirect;
}
/* remove old channels in "manual_joins" (each 60 seconds) */
if (current_time > irc_server_last_check_manual_joins + 60)
/*
* remove old channels in "join_manual" and "join_noswitch"
* (every 5 minutes)
*/
if (current_time > irc_server_last_check_join_channels + (60 * 5))
{
weechat_hashtable_map (ptr_server->manual_joins,
&irc_server_check_manual_joins_cb,
weechat_hashtable_map (ptr_server->join_manual,
&irc_server_check_join_manual_cb,
ptr_server);
weechat_hashtable_map (ptr_server->join_noswitch,
&irc_server_check_join_noswitch_cb,
ptr_server);
irc_server_last_check_join_channels = current_time;
}
}
}
@@ -2822,10 +2855,13 @@ irc_server_close_connection (struct t_irc_server *server)
irc_redirect_free_all (server);
/* remove all manual joins */
weechat_hashtable_remove_all (server->manual_joins);
weechat_hashtable_remove_all (server->join_manual);
/* remove all keys for pending joins */
weechat_hashtable_remove_all (server->channel_join_key);
weechat_hashtable_remove_all (server->join_channel_key);
/* remove all keys for joins without switch */
weechat_hashtable_remove_all (server->join_noswitch);
/* server is now disconnected */
server->is_connected = 0;
@@ -4030,7 +4066,7 @@ irc_server_autojoin_channels (struct t_irc_server *server)
/* auto-join when connecting to server for first time */
autojoin = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN);
if (!server->disable_autojoin && autojoin && autojoin[0])
irc_command_join_server (server, autojoin, 0);
irc_command_join_server (server, autojoin, 0, 0);
}
server->disable_autojoin = 0;
@@ -4460,8 +4496,9 @@ irc_server_hdata_server_cb (void *data, const char *hdata_name)
WEECHAT_HDATA_VAR(struct t_irc_server, last_redirect, POINTER, 0, NULL, "irc_redirect");
WEECHAT_HDATA_VAR(struct t_irc_server, notify_list, POINTER, 0, NULL, "irc_notify");
WEECHAT_HDATA_VAR(struct t_irc_server, last_notify, POINTER, 0, NULL, "irc_notify");
WEECHAT_HDATA_VAR(struct t_irc_server, manual_joins, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, channel_join_key, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, join_manual, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, join_channel_key, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, join_noswitch, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, buffer, POINTER, 0, NULL, "buffer");
WEECHAT_HDATA_VAR(struct t_irc_server, buffer_as_string, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, channels, POINTER, 0, NULL, "irc_channel");
@@ -4982,12 +5019,15 @@ irc_server_print_log ()
weechat_log_printf (" last_redirect. . . . : 0x%lx", ptr_server->last_redirect);
weechat_log_printf (" notify_list. . . . . : 0x%lx", ptr_server->notify_list);
weechat_log_printf (" last_notify. . . . . : 0x%lx", ptr_server->last_notify);
weechat_log_printf (" manual_joins . . . . : 0x%lx (hashtable: '%s')",
ptr_server->manual_joins,
weechat_hashtable_get_string (ptr_server->manual_joins, "keys_values"));
weechat_log_printf (" channel_join_key . . : 0x%lx (hashtable: '%s')",
ptr_server->channel_join_key,
weechat_hashtable_get_string (ptr_server->channel_join_key, "keys_values"));
weechat_log_printf (" join_manual. . . . . : 0x%lx (hashtable: '%s')",
ptr_server->join_manual,
weechat_hashtable_get_string (ptr_server->join_manual, "keys_values"));
weechat_log_printf (" join_channel_key . . : 0x%lx (hashtable: '%s')",
ptr_server->join_channel_key,
weechat_hashtable_get_string (ptr_server->join_channel_key, "keys_values"));
weechat_log_printf (" join_noswitch. . . . : 0x%lx (hashtable: '%s')",
ptr_server->join_noswitch,
weechat_hashtable_get_string (ptr_server->join_noswitch, "keys_values"));
weechat_log_printf (" buffer . . . . . . . : 0x%lx", ptr_server->buffer);
weechat_log_printf (" buffer_as_string . . : 0x%lx", ptr_server->buffer_as_string);
weechat_log_printf (" channels . . . . . . : 0x%lx", ptr_server->channels);