diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-21 19:22:31 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-23 19:10:13 +0100 |
commit | 55d08a604f7d8a9877a99918e6b19c61983207a7 (patch) | |
tree | fadca7618d728d08907dffb4082e0de41c1a5cef | |
parent | e0cdfb1cefae496c5d774c188bb73841cf3d4f1e (diff) | |
download | weechat-55d08a604f7d8a9877a99918e6b19c61983207a7.zip |
irc: fix autojoin on server connection (closes #1873)
Now the autojoin is made only one time, until the server buffer is closed.
A new flag `autojoin_done` is added to know whether the autojoin has already
been done or not on the server. It is set to 1 on first autojoin, and reset to
0 only if the server buffer is closed.
The flag `reconnect_join` is removed, because it is now obsolete.
-rw-r--r-- | ChangeLog.adoc | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-buffer.c | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 73 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-upgrade.c | 2 |
6 files changed, 43 insertions, 40 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 02dbb3a84..76866499f 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -21,6 +21,7 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] Bug fixes:: * core: fix display glitch in command errors when a wide char is set in option weechat.look.command_chars (issue #1871) + * irc: fix join of channels in "autojoin" server option on first connection to server if auto reconnection is performed (issue #1873) * typing: fix crash when pointer buffer is not received in callback for signal "input_text_changed" (issue #1869) Build:: diff --git a/src/plugins/irc/irc-buffer.c b/src/plugins/irc/irc-buffer.c index 791c40ee3..a2332a3d5 100644 --- a/src/plugins/irc/irc-buffer.c +++ b/src/plugins/irc/irc-buffer.c @@ -219,6 +219,9 @@ irc_buffer_close_cb (const void *pointer, void *data, ptr_server->reconnect_delay = 0; ptr_server->reconnect_start = 0; + /* consider auto-join has never been done */ + ptr_server->autojoin_done = 0; + /* close server channels/privates */ ptr_channel = ptr_server->channels; while (ptr_channel) diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 163e4ff67..70686b9b3 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -1586,7 +1586,6 @@ irc_command_connect_one_server (struct t_irc_server *server, { server->reconnect_delay = 0; server->reconnect_start = 0; - server->reconnect_join = (server->channels) ? 1 : 0; } /* connect OK */ @@ -4630,7 +4629,6 @@ irc_command_reconnect_one_server (struct t_irc_server *server, { server->reconnect_delay = 0; server->reconnect_start = 0; - server->reconnect_join = (server->channels) ? 1 : 0; } /* reconnect OK */ diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 055b4380b..397d5cfc1 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -1615,7 +1615,7 @@ irc_server_alloc (const char *name) new_server->reconnect_delay = 0; new_server->reconnect_start = 0; new_server->command_time = 0; - new_server->reconnect_join = 0; + new_server->autojoin_done = 0; new_server->disable_autojoin = 0; new_server->is_away = 0; new_server->away_message = NULL; @@ -5357,9 +5357,7 @@ irc_server_reconnect (struct t_irc_server *server) server->reconnect_start = 0; - if (irc_server_connect (server)) - server->reconnect_join = 1; - else + if (!irc_server_connect (server)) irc_server_reconnect_schedule (server); } @@ -5551,8 +5549,11 @@ irc_server_autojoin_create_buffers (struct t_irc_server *server) char *autojoin, *autojoin2, **channels; int num_channels, i; - /* buffers are opened only if no channels are currently opened */ - if (server->channels) + /* + * buffers are opened only if auto-join was not already done + * and if no channels are currently opened + */ + if (server->autojoin_done || server->channels) return; /* evaluate server option "autojoin" */ @@ -5707,39 +5708,39 @@ irc_server_autojoin_channels (struct t_irc_server *server) { char *autojoin; - if (!server->disable_autojoin) + if (server->disable_autojoin) { - /* auto-join after disconnection (only rejoins opened channels) */ - if (server->reconnect_join) + server->disable_autojoin = 0; + return; + } + + if (!server->autojoin_done && !server->channels) + { + /* auto-join when connecting to server for first time */ + autojoin = irc_server_eval_expression ( + server, + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN)); + if (autojoin && autojoin[0]) { - if (server->channels) - { - autojoin = irc_server_build_autojoin (server); - if (autojoin) - { - irc_server_sendf (server, - IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, - "JOIN %s", - autojoin); - free (autojoin); - } - } - server->reconnect_join = 0; + irc_command_join_server (server, autojoin, 0, 0); + server->autojoin_done = 1; } - else + if (autojoin) + free (autojoin); + } + else if (server->channels) + { + /* auto-join after disconnection (only rejoins opened channels) */ + autojoin = irc_server_build_autojoin (server); + if (autojoin) { - /* auto-join when connecting to server for first time */ - autojoin = irc_server_eval_expression ( - server, - IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN)); - if (autojoin && autojoin[0]) - irc_command_join_server (server, autojoin, 0, 0); - if (autojoin) - free (autojoin); + irc_server_sendf (server, + IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, + "JOIN %s", + autojoin); + free (autojoin); } } - - server->disable_autojoin = 0; } /* @@ -6167,7 +6168,7 @@ irc_server_hdata_server_cb (const void *pointer, void *data, WEECHAT_HDATA_VAR(struct t_irc_server, reconnect_delay, INTEGER, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, reconnect_start, TIME, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, command_time, TIME, 0, NULL, NULL); - WEECHAT_HDATA_VAR(struct t_irc_server, reconnect_join, INTEGER, 0, NULL, NULL); + WEECHAT_HDATA_VAR(struct t_irc_server, autojoin_done, INTEGER, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, disable_autojoin, INTEGER, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, is_away, INTEGER, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_irc_server, away_message, STRING, 0, NULL, NULL); @@ -6530,7 +6531,7 @@ irc_server_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_time (ptr_item, "command_time", server->command_time)) return 0; - if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_join", server->reconnect_join)) + if (!weechat_infolist_new_var_integer (ptr_item, "autojoin_done", server->autojoin_done)) return 0; if (!weechat_infolist_new_var_integer (ptr_item, "disable_autojoin", server->disable_autojoin)) return 0; @@ -6917,7 +6918,7 @@ irc_server_print_log () weechat_log_printf (" reconnect_delay . . . . . : %d", ptr_server->reconnect_delay); weechat_log_printf (" reconnect_start . . . . . : %lld", (long long)ptr_server->reconnect_start); weechat_log_printf (" command_time. . . . . . . : %lld", (long long)ptr_server->command_time); - weechat_log_printf (" reconnect_join. . . . . . : %d", ptr_server->reconnect_join); + weechat_log_printf (" autojoin_done . . . . . . : %d", ptr_server->autojoin_done); weechat_log_printf (" disable_autojoin. . . . . : %d", ptr_server->disable_autojoin); weechat_log_printf (" is_away . . . . . . . . . : %d", ptr_server->is_away); weechat_log_printf (" away_message. . . . . . . : '%s'", ptr_server->away_message); diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index b4964ed1b..a8e0ce100 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -241,7 +241,7 @@ struct t_irc_server time_t reconnect_start; /* this time + delay = reconnect time */ time_t command_time; /* this time + command_delay = time to */ /* autojoin channels */ - int reconnect_join; /* 1 if channels opened to rejoin */ + int autojoin_done; /* 1 if autojoin has been done */ int disable_autojoin; /* 1 if user asked to not autojoin chans */ int is_away; /* 1 is user is marked as away */ char *away_message; /* away message, NULL if not away */ diff --git a/src/plugins/irc/irc-upgrade.c b/src/plugins/irc/irc-upgrade.c index ff7a71efe..374fbf195 100644 --- a/src/plugins/irc/irc-upgrade.c +++ b/src/plugins/irc/irc-upgrade.c @@ -589,7 +589,7 @@ irc_upgrade_read_cb (const void *pointer, void *data, irc_upgrade_current_server->reconnect_delay = weechat_infolist_integer (infolist, "reconnect_delay"); irc_upgrade_current_server->reconnect_start = weechat_infolist_time (infolist, "reconnect_start"); irc_upgrade_current_server->command_time = weechat_infolist_time (infolist, "command_time"); - irc_upgrade_current_server->reconnect_join = weechat_infolist_integer (infolist, "reconnect_join"); + irc_upgrade_current_server->autojoin_done = weechat_infolist_integer (infolist, "autojoin_done"); irc_upgrade_current_server->disable_autojoin = weechat_infolist_integer (infolist, "disable_autojoin"); irc_upgrade_current_server->is_away = weechat_infolist_integer (infolist, "is_away"); str = weechat_infolist_string (infolist, "away_message"); |