Changeset d6aa6dd


Ignore:
Timestamp:
2010-06-24T00:43:15Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
38ff846
Parents:
90ba416
Message:

Load the whole Twitter contact list at login time if mode=chat/many,
instead of adding contacts as they post tweets. Also in mode=chat, populate
the channel *before* adding the user to it, avoiding a flood of joins.

Location:
protocols/twitter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    r90ba416 rd6aa6dd  
    4040                return 0;
    4141
    42         // If the user uses multiple private message windows we need to get the
    43         // users buddies.
    44         if (g_strcasecmp(set_getstr(&ic->acc->set, "mode"), "many") == 0)
    45                 twitter_get_statuses_friends(ic, -1);
    46 
    4742        // Do stuff..
    4843        twitter_get_home_timeline(ic, -1);
     
    5651        struct twitter_data *td = ic->proto_data;
    5752       
    58         imcb_log( ic, "Connecting to Twitter" );
     53        imcb_log( ic, "Getting initial statuses" );
    5954
    6055        // Run this once. After this queue the main loop function.
     
    6661}
    6762
     63static void twitter_oauth_start( struct im_connection *ic );
     64
     65void twitter_login_finish( struct im_connection *ic )
     66{
     67        struct twitter_data *td = ic->proto_data;
     68       
     69        if( set_getbool( &ic->acc->set, "oauth" ) && !td->oauth_info )
     70                twitter_oauth_start( ic );
     71        else if( g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "one" ) != 0 &&
     72                 !( td->flags & TWITTER_HAVE_FRIENDS ) )
     73        {
     74                imcb_log( ic, "Getting contact list" );
     75                twitter_get_statuses_friends( ic, -1 );
     76        }
     77        else
     78                twitter_main_loop_start( ic );
     79}
    6880
    6981static const struct oauth_service twitter_oauth =
     
    128140                ic->acc->pass = oauth_to_string( info );
    129141               
    130                 twitter_main_loop_start( ic );
     142                twitter_login_finish( ic );
    131143        }
    132144       
     
    211223        imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL );
    212224       
    213         if( td->oauth_info || !set_getbool( &acc->set, "oauth" ) )
    214                 twitter_main_loop_start( ic );
    215         else
    216                 twitter_oauth_start( ic );
     225        imcb_log( ic, "Connecting" );
     226       
     227        twitter_login_finish( ic );
    217228}
    218229
  • protocols/twitter/twitter.h

    r90ba416 rd6aa6dd  
    3333#endif
    3434
     35typedef enum
     36{
     37        TWITTER_HAVE_FRIENDS = 1,
     38} twitter_flags_t;
     39
    3540struct twitter_data
    3641{
     
    4247        struct groupchat *home_timeline_gc;
    4348        gint http_fails;
     49        twitter_flags_t flags;
    4450       
    4551        gboolean url_ssl;
     
    5662GSList *twitter_connections;
    5763
     64void twitter_login_finish( struct im_connection *ic );
     65
    5866#endif //_TWITTER_H
  • protocols/twitter/twitter_lib.c

    r90ba416 rd6aa6dd  
    5959};
    6060
     61static void twitter_groupchat_init(struct im_connection *ic);
     62
    6163/**
    6264 * Frees a twitter_xml_user struct.
     
    433435}
    434436
     437static void twitter_groupchat_init(struct im_connection *ic)
     438{
     439        char *name_hint;
     440        struct groupchat *gc;
     441        struct twitter_data *td = ic->proto_data;
     442       
     443        td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" );
     444       
     445        name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user );
     446        imcb_chat_name_hint( gc, name_hint );
     447        g_free( name_hint );
     448}
     449
    435450/**
    436451 * Function that is called to see the statuses in a groupchat window.
     
    445460        // Create a new groupchat if it does not exsist.
    446461        if (!td->home_timeline_gc)
    447         {   
    448                 char *name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user );
    449                 td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" );
    450                 imcb_chat_name_hint( gc, name_hint );
    451                 g_free( name_hint );
    452                 // Add the current user to the chat...
     462                twitter_groupchat_init(ic);
     463       
     464        gc = td->home_timeline_gc;
     465        if (!gc->joined)
    453466                imcb_chat_add_buddy( gc, ic->acc->user );
    454         }
    455         else
    456         {   
    457                 gc = td->home_timeline_gc;
    458         }
    459467
    460468        for ( l = list; l ; l = g_slist_next(l) )
     
    604612       
    605613        // Check if the HTTP request went well.
    606         if (req->status_code != 200) {
     614        if (req->status_code == 401)
     615        {
     616                imcb_error( ic, "Authentication failure" );
     617                imc_logout( ic, FALSE );
     618                return;
     619        } else if (req->status_code != 200) {
    607620                // It didn't go well, output the error and return.
    608                 if (++td->http_fails >= 5)
    609                         imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
    610                
     621                imcb_error(ic, "Could not retrieve " TWITTER_SHOW_FRIENDS_URL ": %s", twitter_parse_error(req));
     622                imc_logout( ic, TRUE );
    611623                return;
    612624        } else {
    613625                td->http_fails = 0;
    614626        }
     627       
     628        if( !td->home_timeline_gc &&
     629            g_strcasecmp( set_getstr( &ic->acc->set, "mode" ), "chat" ) == 0 )
     630                twitter_groupchat_init( ic );
    615631
    616632        txl = g_new0(struct twitter_xml_list, 1);
     
    639655        txl_free(txl);
    640656        g_free(txl);
     657       
     658        td->flags |= TWITTER_HAVE_FRIENDS;
     659        twitter_login_finish(ic);
    641660}
    642661
Note: See TracChangeset for help on using the changeset viewer.