Changeset 8ad5c34 for protocols/purple


Ignore:
Timestamp:
2010-05-02T15:53:18Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
15794dc
Parents:
a348d00
Message:

Added support for creating groupchats. This can only be done in a horribly
broken way which is surely going to break somehow someday.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/purple.c

    ra348d00 r8ad5c34  
    5151{
    5252        return purple_ic_by_pa( purple_connection_get_account( gc ) );
     53}
     54
     55static gboolean purple_menu_cmp( const char *a, const char *b )
     56{
     57        while( *a && *b )
     58        {
     59                while( *a == '_' ) a ++;
     60                while( *b == '_' ) b ++;
     61                if( tolower( *a ) != tolower( *b ) )
     62                        return FALSE;
     63               
     64                a ++;
     65                b ++;
     66        }
     67       
     68        return ( *a == '\0' && *b == '\0' );
    5369}
    5470
     
    372388}
    373389
     390struct groupchat *purple_chat_with( struct im_connection *ic, char *who )
     391{
     392        /* No, "of course" this won't work this way. Or in fact, it almost
     393           does, but it only lets you send msgs to it, you won't receive
     394           any. Instead, we have to click the virtual menu item.
     395        PurpleAccount *pa = ic->proto_data;
     396        PurpleConversation *pc;
     397        PurpleConvChat *pcc;
     398        struct groupchat *gc;
     399       
     400        gc = imcb_chat_new( ic, "BitlBee-libpurple groupchat" );
     401        gc->data = pc = purple_conversation_new( PURPLE_CONV_TYPE_CHAT, pa, "BitlBee-libpurple groupchat" );
     402        pc->ui_data = gc;
     403       
     404        pcc = PURPLE_CONV_CHAT( pc );
     405        purple_conv_chat_add_user( pcc, ic->acc->user, "", 0, TRUE );
     406        purple_conv_chat_invite_user( pcc, who, "Please join my chat", FALSE );
     407        //purple_conv_chat_add_user( pcc, who, "", 0, TRUE );
     408        */
     409       
     410        /* There went my nice afternoon. :-( */
     411       
     412        PurpleAccount *pa = ic->proto_data;
     413        PurplePlugin *prpl = purple_plugins_find_with_id( pa->protocol_id );
     414        PurplePluginProtocolInfo *pi = prpl->info->extra_info;
     415        PurpleBuddy *pb = purple_find_buddy( (PurpleAccount*) ic->proto_data, who );
     416        PurpleMenuAction *mi;
     417        GList *menu;
     418        void (*callback)(PurpleBlistNode *, gpointer); /* FFFFFFFFFFFFFUUUUUUUUUUUUUU */
     419       
     420        if( !pb || !pi || !pi->blist_node_menu )
     421                return NULL;
     422       
     423        menu = pi->blist_node_menu( &pb->node );
     424        while( menu )
     425        {
     426                mi = menu->data;
     427                if( purple_menu_cmp( mi->label, "initiate chat" ) ||
     428                    purple_menu_cmp( mi->label, "initiate conference" ) )
     429                        break;
     430                menu = menu->next;
     431        }
     432       
     433        if( menu == NULL )
     434                return NULL;
     435       
     436        /* Call the fucker. */
     437        callback = (void*) mi->callback;
     438        callback( &pb->node, menu->data );
     439       
     440        return NULL;
     441}
     442
     443void purple_chat_invite( struct groupchat *gc, char *who, char *message )
     444{
     445        PurpleConversation *pc = gc->data;
     446        PurpleConvChat *pcc = PURPLE_CONV_CHAT( pc );
     447       
     448        purple_conv_chat_invite_user( pcc, who, message && *message ? message : "Please join my chat", FALSE );
     449}
     450
    374451void purple_transfer_request( struct im_connection *ic, file_transfer_t *ft, char *handle );
    375452
     
    537614        struct groupchat *gc = conv->ui_data;
    538615        GList *b;
     616       
     617        if( !gc->joined && strcmp( conv->account->protocol_id, "prpl-msn" ) == 0 )
     618        {
     619                /* Work around the broken MSN module which fucks up the user's
     620                   handle completely when informing him/her that he just
     621                   successfully joined the room s/he just created (v2.6.6). */
     622                imcb_chat_add_buddy( gc, gc->ic->acc->user );
     623        }
    539624       
    540625        for( b = cbuddies; b; b = b->next )
     
    9851070        /* TODO(wilmer): Set these only for protocols that support them? */
    9861071        funcs.chat_msg = purple_chat_msg;
     1072        funcs.chat_with = purple_chat_with;
     1073        funcs.chat_invite = purple_chat_invite;
    9871074        funcs.transfer_request = purple_transfer_request;
    9881075       
Note: See TracChangeset for help on using the changeset viewer.