From d05b610636e813af44fc06821a07aeb8e1b2b332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sat, 9 May 2015 23:50:44 +0200 Subject: [PATCH] degesch: remove people from channels when leaving --- degesch.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/degesch.c b/degesch.c index 0f4cd6e..58b68a4 100644 --- a/degesch.c +++ b/degesch.c @@ -2462,6 +2462,14 @@ irc_remove_user_from_channel (struct user *user, struct channel *channel) irc_channel_unlink_user (channel, iter); } +static void +irc_left_channel (struct channel *channel) +{ + // TODO: shouldn't we decrease reference count on the channel? + LIST_FOR_EACH (struct channel_user, iter, channel->users) + irc_channel_unlink_user (channel, iter); +} + // --- Core functionality ------------------------------------------------------ // Most of the core IRC code comes from ZyklonB which is mostly blocking. @@ -2755,6 +2763,12 @@ on_irc_disconnected (struct server *s) s->socket = -1; s->state = IRC_DISCONNECTED; + struct str_map_iter iter; + str_map_iter_init (&iter, &s->irc_channels); + struct channel *channel; + while ((channel = str_map_iter_next (&iter))) + irc_left_channel (channel); + user_unref (s->irc_user); s->irc_user = NULL; @@ -3388,7 +3402,12 @@ irc_handle_kick (struct server *s, const struct irc_message *msg) // It would be is weird for this to be false if (user && channel) - irc_remove_user_from_channel (user, channel); + { + if (irc_is_this_us (s, target)) + irc_left_channel (channel); + else + irc_remove_user_from_channel (user, channel); + } if (buffer) { @@ -3563,7 +3582,12 @@ irc_handle_part (struct server *s, const struct irc_message *msg) // It would be is weird for this to be false if (user && channel) - irc_remove_user_from_channel (user, channel); + { + if (irc_is_this_us (s, msg->prefix)) + irc_left_channel (channel); + else + irc_remove_user_from_channel (user, channel); + } if (buffer) {