aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-06-28 01:07:46 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-06-28 01:07:46 +0100
commit1c40aa73b52e4507404c82056170069a859fb0cb (patch)
tree6dd325cd318c645e16c6d01fa8296cd17aaabaa4
parent134a02cd563c395d0026d9d1b07eb136394798ca (diff)
Mark nameless groupchat channels as temporary so they don't stick around
forever.
-rw-r--r--irc.h4
-rw-r--r--irc_channel.c5
-rw-r--r--irc_im.c29
-rw-r--r--storage_xml.c3
4 files changed, 36 insertions, 5 deletions
diff --git a/irc.h b/irc.h
index 74e66075..b9257645 100644
--- a/irc.h
+++ b/irc.h
@@ -131,7 +131,9 @@ extern const struct irc_user_funcs irc_user_self_funcs;
typedef enum
{
- IRC_CHANNEL_JOINED = 1,
+ IRC_CHANNEL_JOINED = 1, /* The user is currently in the channel. */
+ IRC_CHANNEL_TEMP = 2, /* Erase the channel when the user leaves,
+ and don't save it. */
/* Hack: Set this flag right before jumping into IM when we expect
a call to imcb_chat_new(). */
diff --git a/irc_channel.c b/irc_channel.c
index f0e564bc..534f49c4 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -201,7 +201,12 @@ int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu, gboolean silent, co
irc_send_part( ic, iu, msg );
if( iu == ic->irc->user )
+ {
ic->flags &= ~IRC_CHANNEL_JOINED;
+
+ if( ic->flags & IRC_CHANNEL_TEMP )
+ irc_channel_free( ic );
+ }
return 1;
}
diff --git a/irc_im.c b/irc_im.c
index f4c5f390..6572be44 100644
--- a/irc_im.c
+++ b/irc_im.c
@@ -454,10 +454,8 @@ static gboolean bee_irc_chat_free( bee_t *bee, struct groupchat *c )
if( ic->flags & IRC_CHANNEL_JOINED )
irc_channel_printf( ic, "Cleaning up channel, bye!" );
- /* irc_channel_free( ic ); */
-
- irc_channel_del_user( ic, ic->irc->user, FALSE, "Chatroom closed by server" );
ic->data = NULL;
+ irc_channel_del_user( ic, ic->irc->user, FALSE, "Chatroom closed by server" );
return TRUE;
}
@@ -500,6 +498,9 @@ static gboolean bee_irc_chat_remove_user( bee_t *bee, struct groupchat *c, bee_u
{
irc_t *irc = bee->ui_data;
+ /* TODO: Possible bug here: If a module removes $user here instead of just
+ using imcb_chat_free() and the channel was IRC_CHANNEL_TEMP, we get into
+ a broken state around here. */
irc_channel_del_user( c->ui_data, bu == bee->user ? irc->user : bu->ui_data, FALSE, NULL );
return TRUE;
@@ -695,14 +696,18 @@ static gboolean bee_irc_channel_chat_invite( irc_channel_t *ic, irc_user_t *iu )
}
static char *set_eval_room_account( set_t *set, char *value );
+static char *set_eval_chat_type( set_t *set, char *value );
static gboolean bee_irc_channel_init( irc_channel_t *ic )
{
set_add( &ic->set, "account", NULL, set_eval_room_account, ic );
- set_add( &ic->set, "chat_type", "groupchat", NULL, ic );
+ set_add( &ic->set, "chat_type", "groupchat", set_eval_chat_type, ic );
set_add( &ic->set, "nick", NULL, NULL, ic );
set_add( &ic->set, "room", NULL, NULL, ic );
+ /* chat_type == groupchat */
+ ic->flags |= IRC_CHANNEL_TEMP;
+
return TRUE;
}
@@ -722,6 +727,20 @@ static char *set_eval_room_account( set_t *set, char *value )
return g_strdup_printf( "%s(%s)", acc->prpl->name, acc->user );
}
+static char *set_eval_chat_type( set_t *set, char *value )
+{
+ struct irc_channel *ic = set->data;
+
+ if( strcmp( value, "groupchat" ) == 0 )
+ ic->flags |= IRC_CHANNEL_TEMP;
+ else if( strcmp( value, "room" ) == 0 )
+ ic->flags &= ~IRC_CHANNEL_TEMP;
+ else
+ return NULL;
+
+ return value;
+}
+
static gboolean bee_irc_channel_free( irc_channel_t *ic )
{
set_del( &ic->set, "account" );
@@ -729,6 +748,8 @@ static gboolean bee_irc_channel_free( irc_channel_t *ic )
set_del( &ic->set, "nick" );
set_del( &ic->set, "room" );
+ ic->flags &= ~IRC_CHANNEL_TEMP;
+
return TRUE;
}
diff --git a/storage_xml.c b/storage_xml.c
index d20469af..f97b2cd5 100644
--- a/storage_xml.c
+++ b/storage_xml.c
@@ -516,6 +516,9 @@ static storage_status_t xml_save( irc_t *irc, int overwrite )
{
irc_channel_t *ic = l->data;
+ if( ic->flags & IRC_CHANNEL_TEMP )
+ continue;
+
if( !xml_printf( fd, 1, "<channel name=\"%s\" type=\"%s\">\n",
ic->name, set_getstr( &ic->set, "type" ) ) )
goto write_error;