aboutsummaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/degesch.c b/degesch.c
index 2388080..85e43c6 100644
--- a/degesch.c
+++ b/degesch.c
@@ -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)
{