aboutsummaryrefslogtreecommitdiffstats
path: root/irc_im.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-07-01 00:46:55 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-07-01 00:46:55 +0100
commit52a252173062bbce66040ef2b79c15dc2e2c03e6 (patch)
treeefce48c61d34dfb9e1ac6e81405dd933a9e14a10 /irc_im.c
parent06f9548d5f3b0909c8cdbd092dd3118c661be67b (diff)
When receiving a channel name hint, and a channel with that name already
exists, remove it if it's fully unused, instead of failing immediately. (Fixes #639.)
Diffstat (limited to 'irc_im.c')
-rw-r--r--irc_im.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/irc_im.c b/irc_im.c
index 5f33e579..f9c1b865 100644
--- a/irc_im.c
+++ b/irc_im.c
@@ -420,7 +420,7 @@ static gboolean bee_irc_chat_new( bee_t *bee, struct groupchat *c )
int i;
/* Try to find a channel that expects to receive a groupchat.
- This flag is set by groupchat_stub_invite(). */
+ This flag is set earlier in our current call trace. */
for( l = irc->channels; l; l = l->next )
{
ic = l->data;
@@ -529,7 +529,7 @@ static gboolean bee_irc_chat_topic( bee_t *bee, struct groupchat *c, const char
static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const char *name )
{
irc_t *irc = bee->ui_data;
- irc_channel_t *ic = c->ui_data;
+ irc_channel_t *ic = c->ui_data, *oic;
char stripped[MAX_NICK_LENGTH+1], *full_name;
/* Don't rename a channel if the user's in it already. */
@@ -542,18 +542,37 @@ static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const c
if( set_getbool( &bee->set, "lcnicks" ) )
nick_lc( stripped );
- full_name = g_strdup_printf( "#%s", stripped );
+ if( stripped[0] == '\0' )
+ return FALSE;
- if( stripped[0] && irc_channel_by_name( irc, full_name ) == NULL )
- {
- g_free( ic->name );
- ic->name = full_name;
- }
- else
+ full_name = g_strdup_printf( "#%s", stripped );
+ if( ( oic = irc_channel_by_name( irc, full_name ) ) )
{
- g_free( full_name );
+ char *type, *chat_type;
+
+ type = set_getstr( &oic->set, "type" );
+ chat_type = set_getstr( &oic->set, "chat_type" );
+
+ if( type && chat_type && oic->data == FALSE &&
+ strcmp( type, "chat" ) == 0 &&
+ strcmp( chat_type, "groupchat" ) == 0 )
+ {
+ /* There's a channel with this name already, but it looks
+ like it's not in use yet. Most likely the IRC client
+ rejoined the channel after a reconnect. Remove it so
+ we can reuse its name. */
+ irc_channel_free( oic );
+ }
+ else
+ {
+ g_free( full_name );
+ return FALSE;
+ }
}
+ g_free( ic->name );
+ ic->name = full_name;
+
return TRUE;
}