Changeset ce81acd


Ignore:
Timestamp:
2011-03-28T23:28:46Z (13 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
4f50ea5
Parents:
f01bc6f
Message:

For #721, add the numbers in front of tweets if show_ids is enabled. Left
to do: Document the feature and allow using the numbers in rt/replies.

Location:
protocols/twitter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    rf01bc6f rce81acd  
    245245        s->flags |= ACC_SET_OFFLINE_ONLY;
    246246       
     247        s = set_add( &acc->set, "show_ids", "false", set_eval_bool, acc );
     248        s->flags |= ACC_SET_OFFLINE_ONLY;
     249       
    247250        s = set_add( &acc->set, "oauth", def_oauth, set_eval_bool, acc );
    248251}
     
    291294        imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL );
    292295       
     296        if( set_getbool( &acc->set, "show_ids" ) )
     297                td->log = g_new0( struct twitter_log_data, TWITTER_LOG_LENGTH );
     298       
    293299        imcb_log( ic, "Connecting" );
    294300       
     
    319325                g_free( td->url_path );
    320326                g_free( td->pass );
     327                g_free( td->log );
    321328                g_free( td );
    322329        }
  • protocols/twitter/twitter.h

    rf01bc6f rce81acd  
    3838} twitter_flags_t;
    3939
     40struct twitter_log_data;
     41
    4042struct twitter_data
    4143{
     
    5658
    5759        char *prefix; /* Used to generate contact + channel name. */
     60       
     61        struct twitter_log_data *log;
     62        int log_id;
    5863};
    5964
     
    6267        guint64 last_id;
    6368        time_t last_time;
     69};
     70
     71#define TWITTER_LOG_LENGTH 100
     72struct twitter_log_data
     73{
     74        guint64 id;
     75        struct bee_user *bu;
    6476};
    6577
  • protocols/twitter/twitter_lib.c

    rf01bc6f rce81acd  
    6767        char *text;
    6868        struct twitter_xml_user *user;
    69         guint64 id;
     69        guint64 id, reply_to;
    7070};
    7171
     
    409409                {
    410410                        txs->id = g_ascii_strtoull (child->text, NULL, 10);
     411                }
     412                else if (g_strcasecmp( "in_reply_to_status_id", child->name ) == 0)
     413                {
     414                        txs->reply_to = g_ascii_strtoull (child->text, NULL, 10);
    411415                }
    412416        }
     
    502506}
    503507
     508static char *twitter_msg_add_id(struct im_connection *ic,
     509    struct twitter_xml_status *txs, const char *prefix)
     510{
     511        struct twitter_data *td = ic->proto_data;
     512        char *ret = NULL;
     513       
     514        if (!set_getbool(&ic->acc->set, "show_ids"))
     515        {
     516                if (*prefix)
     517                        return g_strconcat(prefix, txs->text, NULL);
     518                else
     519                        return NULL;
     520        }
     521       
     522        td->log[td->log_id].id = txs->id;
     523        td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name);
     524        if (txs->reply_to)
     525        {
     526                int i;
     527                for (i = 0; i < TWITTER_LOG_LENGTH; i ++)
     528                        if (td->log[i].id == txs->reply_to)
     529                        {
     530                                ret = g_strdup_printf( "\002[\002%02d->%02d\002]\002 %s%s",
     531                                                       td->log_id, i, prefix, txs->text);
     532                                break;
     533                        }
     534        }
     535        if (ret == NULL)
     536                ret = g_strdup_printf( "\002[\002%02d\002]\002 %s%s",
     537                                       td->log_id, prefix, txs->text);
     538        td->log_id = (td->log_id + 1) % TWITTER_LOG_LENGTH;
     539       
     540        return ret;
     541}
     542
    504543static void twitter_groupchat_init(struct im_connection *ic)
    505544{
     
    543582        for ( l = list; l ; l = g_slist_next(l) )
    544583        {
     584                char *msg;
     585               
    545586                status = l->data;
    546587                if (status->user == NULL || status->text == NULL)
     
    550591               
    551592                strip_html(status->text);
     593                msg = twitter_msg_add_id(ic, status, "");
    552594               
    553595                // Say it!
    554596                if (g_strcasecmp(td->user, status->user->screen_name) == 0)
    555                         imcb_chat_log (gc, "You: %s", status->text);
     597                        imcb_chat_log(gc, "You: %s", msg ? msg : status->text);
    556598                else
    557                         imcb_chat_msg (gc, status->user->screen_name, status->text, 0, status->created_at );
     599                        imcb_chat_msg(gc, status->user->screen_name,
     600                                      msg ? msg : status->text, 0, status->created_at );
     601               
     602                g_free(msg);
    558603               
    559604                // Update the home_timeline_id to hold the highest id, so that by the next request
    560                 // we won't pick up the updates allready in the list.
    561                 td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;
     605                // we won't pick up the updates already in the list.
     606                td->home_timeline_id = MAX(td->home_timeline_id, status->id);
    562607        }
    563608}
     
    584629        for ( l = list; l ; l = g_slist_next(l) )
    585630        {
    586                 char *text = NULL;
     631                char *prefix = NULL, *text = NULL;
    587632               
    588633                status = l->data;
     
    590635                strip_html( status->text );
    591636                if( mode_one )
    592                         text = g_strdup_printf( "\002<\002%s\002>\002 %s",
    593                                                 status->user->screen_name, status->text );
     637                        prefix = g_strdup_printf("\002<\002%s\002>\002 ",
     638                                                 status->user->screen_name);
    594639                else
    595640                        twitter_add_buddy(ic, status->user->screen_name, status->user->name);
    596641               
     642                text = twitter_msg_add_id(ic, status, prefix ? prefix : "");
     643               
    597644                imcb_buddy_msg( ic,
    598645                                mode_one ? from : status->user->screen_name,
    599                                 mode_one ? text : status->text,
     646                                text ? text : status->text,
    600647                                0, status->created_at );
    601648               
    602649                // Update the home_timeline_id to hold the highest id, so that by the next request
    603                 // we won't pick up the updates allready in the list.
    604                 td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;
     650                // we won't pick up the updates already in the list.
     651                td->home_timeline_id = MAX(td->home_timeline_id,  status->id);
    605652               
    606653                g_free( text );
     654                g_free( prefix );
    607655        }
    608656}
Note: See TracChangeset for help on using the changeset viewer.