From 955b3728a3d3d06449cfcebe6cee3470295d4fd0 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Thu, 6 Aug 2015 21:58:34 +0200 Subject: degesch: don't send PART on /close when not joined --- degesch.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/degesch.c b/degesch.c index ac14042..2146005 100644 --- a/degesch.c +++ b/degesch.c @@ -3308,6 +3308,13 @@ irc_get_channel_user_prefix (struct server *s, str_append_c (output, channel_user->prefixes.str[0]); } +static bool +irc_channel_is_joined (struct channel *channel) +{ + // TODO: find a better way of checking if we're on a channel + return !!channel->users; +} + // Note that this eats the user reference static void irc_channel_link_user (struct channel *channel, struct user *user, @@ -7043,7 +7050,8 @@ handle_buffer_close (struct app_context *ctx, struct handler_args *a) else { // The user would be unable to recreate the buffer otherwise - if (buffer->type == BUFFER_CHANNEL) + if (buffer->type == BUFFER_CHANNEL + && irc_channel_is_joined (buffer->channel)) part_channel (buffer->server, buffer->channel->name, ""); buffer_remove_safe (ctx, buffer); } @@ -7468,8 +7476,7 @@ handle_command_join (struct handler_args *a) else if (a->buffer->type != BUFFER_CHANNEL) log_server_error (a->s, a->buffer, "#s: #s", "Can't join", "no channel name given and this buffer is not a channel"); - // TODO: have a better way of checking if we're on the channel - else if (a->buffer->channel->users) + else if (irc_channel_is_joined (a->buffer->channel)) log_server_error (a->s, a->buffer, "#s: #s", "Can't join", "you already are on the channel"); else if (*a->arguments) @@ -7494,8 +7501,7 @@ handle_command_part (struct handler_args *a) else if (a->buffer->type != BUFFER_CHANNEL) log_server_error (a->s, a->buffer, "#s: #s", "Can't part", "no channel name given and this buffer is not a channel"); - // TODO: have a better way of checking if we're on the channel - else if (!a->buffer->channel->users) + else if (!irc_channel_is_joined (a->buffer->channel)) log_server_error (a->s, a->buffer, "#s: #s", "Can't part", "you're not on the channel"); else @@ -7538,8 +7544,7 @@ handle_command_cycle (struct handler_args *a) else if (a->buffer->type != BUFFER_CHANNEL) log_server_error (a->s, a->buffer, "#s: #s", "Can't cycle", "no channel name given and this buffer is not a channel"); - // TODO: have a better way of checking if we're on the channel - else if (!a->buffer->channel->users) + else if (!irc_channel_is_joined (a->buffer->channel)) log_server_error (a->s, a->buffer, "#s: #s", "Can't cycle", "you're not on the channel"); else -- cgit v1.2.3-70-g09d2