Changeset 203a2d2 for protocols


Ignore:
Timestamp:
2010-08-07T21:06:24Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
b890626
Parents:
7b87539
Message:

Allow protocol modules to keep per-contact protocol-specific data. Use
this in the Twitter module to remember the id and timestamp of a contact's
last tweet, which can later be used for simple replies/retweets.

Location:
protocols
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • protocols/bee.h

    r7b87539 r203a2d2  
    8080        bee_t *bee;
    8181        void *ui_data;
     82        void *data; /* Can be used by the IM module. */
    8283} bee_user_t;
    8384
  • protocols/bee_user.c

    r7b87539 r203a2d2  
    4343        if( bee->ui->user_new )
    4444                bee->ui->user_new( bee, bu );
     45        if( ic->acc->prpl->buddy_data_add )
     46                ic->acc->prpl->buddy_data_add( bu );
    4547       
    4648        /* Offline by default. This will set the right flags. */
     
    5759        if( bee->ui->user_free )
    5860                bee->ui->user_free( bee, bu );
     61        if( bu->ic->acc->prpl->buddy_data_free )
     62                bu->ic->acc->prpl->buddy_data_free( bu );
    5963       
    6064        g_free( bu->handle );
  • protocols/nogaim.h

    r7b87539 r203a2d2  
    247247        void (* transfer_request) (struct im_connection *, file_transfer_t *ft, char *handle );
    248248       
     249        void (* buddy_data_add) (struct bee_user *bu);
     250        void (* buddy_data_free) (struct bee_user *bu);
     251       
    249252        /* Some placeholders so eventually older plugins may cooperate with newer BitlBees. */
    250253        void *resv1;
  • protocols/twitter/twitter.c

    r7b87539 r203a2d2  
    395395//}
    396396
     397static void twitter_buddy_data_add( struct bee_user *bu )
     398{
     399        bu->data = g_new0( struct twitter_user_data, 1 );
     400}
     401
     402static void twitter_buddy_data_free( struct bee_user *bu )
     403{
     404        g_free( bu->data );
     405}
     406
    397407static void twitter_handle_command( struct im_connection *ic, char *message )
    398408{
     
    408418                return;
    409419        }
    410         else if( !set_getbool( &ic->set, "commands" ) )
     420        else if( !set_getbool( &ic->acc->set, "commands" ) )
    411421        {
    412422                /* Not supporting commands. */
     
    491501        ret->rem_deny = twitter_rem_deny;
    492502        ret->send_typing = twitter_send_typing;
     503        ret->buddy_data_add = twitter_buddy_data_add;
     504        ret->buddy_data_free = twitter_buddy_data_free;
    493505        ret->handle_cmp = g_strcasecmp;
    494506       
  • protocols/twitter/twitter.h

    r7b87539 r203a2d2  
    5858};
    5959
     60struct twitter_user_data
     61{
     62        guint64 last_id;
     63        time_t last_time;
     64};
     65
    6066/**
    6167 * This has the same function as the msn_connections GSList. We use this to
  • protocols/twitter/twitter_lib.c

    r7b87539 r203a2d2  
    431431 *  - the next_cursor.
    432432 */
    433 static xt_status twitter_xt_get_status_list( struct xt_node *node, struct twitter_xml_list *txl )
     433static xt_status twitter_xt_get_status_list( struct im_connection *ic, struct xt_node *node, struct twitter_xml_list *txl )
    434434{
    435435        struct twitter_xml_status *txs;
    436436        struct xt_node *child;
     437        bee_user_t *bu;
    437438
    438439        // Set the type of the list.
     
    449450                        // Put the item in the front of the list.
    450451                        txl->list = g_slist_prepend (txl->list, txs);
     452                       
     453                        if (txs->user && txs->user->screen_name &&
     454                            (bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name)))
     455                        {
     456                                struct twitter_user_data *tud = bu->data;
     457                               
     458                                if (txs->id > tud->last_id)
     459                                {
     460                                        tud->last_id = txs->id;
     461                                        tud->last_time = txs->created_at;
     462                                }
     463                        }
    451464                }
    452465                else if ( g_strcasecmp( "next_cursor", child->name ) == 0)
     
    627640        xt_feed( parser, req->reply_body, req->body_size );
    628641        // The root <statuses> node should hold the list of statuses <status>
    629         twitter_xt_get_status_list(parser->root, txl);
     642        twitter_xt_get_status_list(ic, parser->root, txl);
    630643        xt_free( parser );
    631644
Note: See TracChangeset for help on using the changeset viewer.