Changeset 1aa74f55 for irc_im.c


Ignore:
Timestamp:
2010-08-23T10:34:36Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
bd599b9
Parents:
241f9f6
Message:

Process incoming XMPP groupchat invites in a saner way: Create a temporary
channel the user can easily /join.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_im.c

    r241f9f6 r1aa74f55  
    613613}
    614614
     615static gboolean bee_irc_chat_invite( bee_t *bee, bee_user_t *bu, const char *name, const char *msg )
     616{
     617        char *channel, *s;
     618        irc_t *irc = bee->ui_data;
     619        irc_user_t *iu = bu->ui_data;
     620        irc_channel_t *chan;
     621       
     622        if( strchr( CTYPES, name[0] ) )
     623                channel = g_strdup( name );
     624        else
     625                channel = g_strdup_printf( "#%s", name );
     626       
     627        if( ( s = strchr( channel, '@' ) ) )
     628                *s = '\0';
     629       
     630        if( strlen( channel ) > MAX_NICK_LENGTH )
     631        {
     632                /* If the channel name is very long (like those insane GTalk
     633                   UUID names), try if we can use the inviter's nick. */
     634                s = g_strdup_printf( "#%s", iu->nick );
     635                if( irc_channel_by_name( irc, s ) == NULL )
     636                {
     637                        g_free( channel );
     638                        channel = s;
     639                }
     640        }
     641       
     642        if( ( chan = irc_channel_new( irc, channel ) ) &&
     643            set_setstr( &chan->set, "type", "chat" ) &&
     644            set_setstr( &chan->set, "chat_type", "room" ) &&
     645            set_setstr( &chan->set, "account", bu->ic->acc->tag ) &&
     646            set_setstr( &chan->set, "room", (char*) name ) )
     647        {
     648                /* I'm assuming that if the user didn't "chat add" the room
     649                   himself but got invited, it's temporary, so make this a
     650                   temporary mapping that is removed as soon as we /PART. */
     651                chan->flags |= IRC_CHANNEL_TEMP;
     652        }
     653        else
     654        {
     655                irc_channel_free( chan );
     656                chan = NULL;
     657        }
     658        g_free( channel );
     659       
     660        irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "<< \002BitlBee\002 - Invitation to chatroom %s >>", name );
     661        if( msg )
     662                irc_send_msg( iu, "PRIVMSG", irc->user->nick, msg, NULL );
     663        if( chan )
     664        {
     665                irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "To join the room, just /join %s", chan->name );
     666                irc_send_invite( iu, chan );
     667        }
     668       
     669        return TRUE;
     670}
     671
    615672/* IRC->IM */
    616673static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond );
     
    909966        bee_irc_chat_topic,
    910967        bee_irc_chat_name_hint,
     968        bee_irc_chat_invite,
    911969       
    912970        bee_irc_ft_in_start,
Note: See TracChangeset for help on using the changeset viewer.