degesch: rejoin channels on reconnect

Unless we've left them and the buffer just stays open, that is.
This commit is contained in:
Přemysl Eric Janouch 2015-07-12 00:30:10 +02:00
parent 5b96f2ccb7
commit fe95f97101
1 changed files with 27 additions and 11 deletions

View File

@ -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
@ -6623,6 +6635,19 @@ show_buffers_list (struct app_context *ctx)
log_global_indent (ctx, " [#d] #s", i++, iter->name);
}
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)
{
@ -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)
{