diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-12 00:30:10 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-12 00:30:10 +0200 |
commit | fe95f97101616bf68a5754ebd1ac245650db2007 (patch) | |
tree | bb4c54c6720959fb19269b433e85dad72299e010 | |
parent | 5b96f2ccb76ae432b1880631520f25a7cb170a1b (diff) | |
download | xK-fe95f97101616bf68a5754ebd1ac245650db2007.tar.gz xK-fe95f97101616bf68a5754ebd1ac245650db2007.tar.xz xK-fe95f97101616bf68a5754ebd1ac245650db2007.zip |
degesch: rejoin channels on reconnect
Unless we've left them and the buffer just stays open, that is.
-rw-r--r-- | degesch.c | 38 |
1 files changed, 27 insertions, 11 deletions
@@ -863,6 +863,8 @@ struct channel struct channel_user *users; ///< Channel users struct str_vector names_buf; ///< Buffer for RPL_NAMREPLY + + bool left_manually; ///< Don't rejoin on reconnect }; static struct channel * @@ -4851,6 +4853,9 @@ irc_handle_join (struct server *s, const struct irc_message *msg) if (!channel) return; + // Reset the field so that we rejoin the channel after reconnecting + channel->left_manually = false; + // Add the user to the channel char *nickname = irc_cut_nickname (msg->prefix); irc_channel_link_user (channel, irc_get_or_make_user (s, nickname), ""); @@ -5468,11 +5473,18 @@ irc_on_registered (struct server *s, const char *nickname) // XXX: we can also use WHOIS if it's not supported (optional by RFC 2812) irc_send (s, "USERHOST %s", s->irc_user->nickname); + // TODO: split autojoin at commas and make a joined set with regular rejoins const char *autojoin = get_config_string (s->config, "autojoin"); if (autojoin) irc_send (s, "JOIN :%s", autojoin); - // TODO: rejoin all current channels (mark those we've left manually?) + struct str_map_iter iter; + str_map_iter_init (&iter, &s->irc_channels); + + struct channel *channel; + while ((channel = str_map_iter_next (&iter))) + if (!channel->left_manually) + irc_send (s, "JOIN :%s", channel->name); } static void @@ -6624,6 +6636,19 @@ show_buffers_list (struct app_context *ctx) } static void +part_channel (struct server *s, const char *channel_name, const char *reason) +{ + if (*reason) + irc_send (s, "PART %s :%s", channel_name, reason); + else + irc_send (s, "PART %s", channel_name); + + struct channel *channel; + if ((channel = str_map_find (&s->irc_channels, channel_name))) + channel->left_manually = true; +} + +static void handle_buffer_close (struct app_context *ctx, struct handler_args *a) { struct buffer *buffer = NULL; @@ -6643,7 +6668,7 @@ handle_buffer_close (struct app_context *ctx, struct handler_args *a) { // The user would be unable to recreate the buffer otherwise if (buffer->type == BUFFER_CHANNEL) - irc_send (buffer->server, "PART %s", buffer->channel->name); + part_channel (buffer->server, buffer->channel->name, ""); if (buffer == ctx->current_buffer) buffer_activate (ctx, ctx->last_buffer @@ -7084,15 +7109,6 @@ handle_command_join (struct handler_args *a) return true; } -static void -part_channel (struct server *s, const char *channel_name, const char *reason) -{ - if (*reason) - irc_send (s, "PART %s :%s", channel_name, reason); - else - irc_send (s, "PART %s", channel_name); -} - static bool handle_command_part (struct handler_args *a) { |