From 1aa74f559af18e06195f34b721d65d69c29fcc0f Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Mon, 23 Aug 2010 11:34:36 +0100 Subject: Process incoming XMPP groupchat invites in a saner way: Create a temporary channel the user can easily /join. --- irc_im.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'irc_im.c') diff --git a/irc_im.c b/irc_im.c index 7ed2922e..6ddcb432 100644 --- a/irc_im.c +++ b/irc_im.c @@ -612,6 +612,63 @@ static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const c return TRUE; } +static gboolean bee_irc_chat_invite( bee_t *bee, bee_user_t *bu, const char *name, const char *msg ) +{ + char *channel, *s; + irc_t *irc = bee->ui_data; + irc_user_t *iu = bu->ui_data; + irc_channel_t *chan; + + if( strchr( CTYPES, name[0] ) ) + channel = g_strdup( name ); + else + channel = g_strdup_printf( "#%s", name ); + + if( ( s = strchr( channel, '@' ) ) ) + *s = '\0'; + + if( strlen( channel ) > MAX_NICK_LENGTH ) + { + /* If the channel name is very long (like those insane GTalk + UUID names), try if we can use the inviter's nick. */ + s = g_strdup_printf( "#%s", iu->nick ); + if( irc_channel_by_name( irc, s ) == NULL ) + { + g_free( channel ); + channel = s; + } + } + + if( ( chan = irc_channel_new( irc, channel ) ) && + set_setstr( &chan->set, "type", "chat" ) && + set_setstr( &chan->set, "chat_type", "room" ) && + set_setstr( &chan->set, "account", bu->ic->acc->tag ) && + set_setstr( &chan->set, "room", (char*) name ) ) + { + /* I'm assuming that if the user didn't "chat add" the room + himself but got invited, it's temporary, so make this a + temporary mapping that is removed as soon as we /PART. */ + chan->flags |= IRC_CHANNEL_TEMP; + } + else + { + irc_channel_free( chan ); + chan = NULL; + } + g_free( channel ); + + irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "<< \002BitlBee\002 - Invitation to chatroom %s >>", name ); + if( msg ) + irc_send_msg( iu, "PRIVMSG", irc->user->nick, msg, NULL ); + if( chan ) + { + irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "To join the room, just /join %s", chan->name ); + irc_send_invite( iu, chan ); + } + + return TRUE; +} + /* IRC->IM */ static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond ); @@ -908,6 +965,7 @@ const struct bee_ui_funcs irc_ui_funcs = { bee_irc_chat_remove_user, bee_irc_chat_topic, bee_irc_chat_name_hint, + bee_irc_chat_invite, bee_irc_ft_in_start, bee_irc_ft_out_start, -- cgit v1.2.3