diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-08-07 22:06:24 +0100 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-08-07 22:06:24 +0100 |
commit | 203a2d2e8857e4c83f8f5e1a89de03ea08538cb2 (patch) | |
tree | a55e88fda74a3c77c29890e6da53e1c2b6e987d5 | |
parent | 7b87539aedd967884d4e4eed75d1052a233720eb (diff) |
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.
-rw-r--r-- | protocols/bee.h | 1 | ||||
-rw-r--r-- | protocols/bee_user.c | 4 | ||||
-rw-r--r-- | protocols/nogaim.h | 3 | ||||
-rw-r--r-- | protocols/twitter/twitter.c | 14 | ||||
-rw-r--r-- | protocols/twitter/twitter.h | 6 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.c | 17 |
6 files changed, 42 insertions, 3 deletions
diff --git a/protocols/bee.h b/protocols/bee.h index a8517f2e..5792e988 100644 --- a/protocols/bee.h +++ b/protocols/bee.h @@ -79,6 +79,7 @@ typedef struct bee_user bee_t *bee; void *ui_data; + void *data; /* Can be used by the IM module. */ } bee_user_t; /* This one's mostly used so save space and make it easier (cheaper) to diff --git a/protocols/bee_user.c b/protocols/bee_user.c index 4399a566..5acd5b83 100644 --- a/protocols/bee_user.c +++ b/protocols/bee_user.c @@ -42,6 +42,8 @@ bee_user_t *bee_user_new( bee_t *bee, struct im_connection *ic, const char *hand if( bee->ui->user_new ) bee->ui->user_new( bee, bu ); + if( ic->acc->prpl->buddy_data_add ) + ic->acc->prpl->buddy_data_add( bu ); /* Offline by default. This will set the right flags. */ imcb_buddy_status( ic, handle, 0, NULL, NULL ); @@ -56,6 +58,8 @@ int bee_user_free( bee_t *bee, bee_user_t *bu ) if( bee->ui->user_free ) bee->ui->user_free( bee, bu ); + if( bu->ic->acc->prpl->buddy_data_free ) + bu->ic->acc->prpl->buddy_data_free( bu ); g_free( bu->handle ); g_free( bu->fullname ); diff --git a/protocols/nogaim.h b/protocols/nogaim.h index 1665a730..be67bb24 100644 --- a/protocols/nogaim.h +++ b/protocols/nogaim.h @@ -246,6 +246,9 @@ struct prpl { /* Incoming transfer request */ void (* transfer_request) (struct im_connection *, file_transfer_t *ft, char *handle ); + void (* buddy_data_add) (struct bee_user *bu); + void (* buddy_data_free) (struct bee_user *bu); + /* Some placeholders so eventually older plugins may cooperate with newer BitlBees. */ void *resv1; void *resv2; diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 85d10a56..ca279b8f 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -394,6 +394,16 @@ static int twitter_send_typing( struct im_connection *ic, char *who, int typing // return value; //} +static void twitter_buddy_data_add( struct bee_user *bu ) +{ + bu->data = g_new0( struct twitter_user_data, 1 ); +} + +static void twitter_buddy_data_free( struct bee_user *bu ) +{ + g_free( bu->data ); +} + static void twitter_handle_command( struct im_connection *ic, char *message ) { struct twitter_data *td = ic->proto_data; @@ -407,7 +417,7 @@ static void twitter_handle_command( struct im_connection *ic, char *message ) g_free( cmds ); return; } - else if( !set_getbool( &ic->set, "commands" ) ) + else if( !set_getbool( &ic->acc->set, "commands" ) ) { /* Not supporting commands. */ } @@ -490,6 +500,8 @@ void twitter_initmodule() ret->add_deny = twitter_add_deny; ret->rem_deny = twitter_rem_deny; ret->send_typing = twitter_send_typing; + ret->buddy_data_add = twitter_buddy_data_add; + ret->buddy_data_free = twitter_buddy_data_free; ret->handle_cmp = g_strcasecmp; register_protocol(ret); diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h index 9485520f..0acb3b4d 100644 --- a/protocols/twitter/twitter.h +++ b/protocols/twitter/twitter.h @@ -57,6 +57,12 @@ struct twitter_data char *prefix; /* Used to generate contact + channel name. */ }; +struct twitter_user_data +{ + guint64 last_id; + time_t last_time; +}; + /** * This has the same function as the msn_connections GSList. We use this to * make sure the connection is still alive in callbacks before we do anything diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index a24e9969..699558b2 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -430,10 +430,11 @@ static xt_status twitter_xt_get_status( struct xt_node *node, struct twitter_xml * - all <status>es within the <status> element and * - the next_cursor. */ -static xt_status twitter_xt_get_status_list( struct xt_node *node, struct twitter_xml_list *txl ) +static xt_status twitter_xt_get_status_list( struct im_connection *ic, struct xt_node *node, struct twitter_xml_list *txl ) { struct twitter_xml_status *txs; struct xt_node *child; + bee_user_t *bu; // Set the type of the list. txl->type = TXL_STATUS; @@ -448,6 +449,18 @@ static xt_status twitter_xt_get_status_list( struct xt_node *node, struct twitte twitter_xt_get_status(child, txs); // Put the item in the front of the list. txl->list = g_slist_prepend (txl->list, txs); + + if (txs->user && txs->user->screen_name && + (bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name))) + { + struct twitter_user_data *tud = bu->data; + + if (txs->id > tud->last_id) + { + tud->last_id = txs->id; + tud->last_time = txs->created_at; + } + } } else if ( g_strcasecmp( "next_cursor", child->name ) == 0) { @@ -626,7 +639,7 @@ static void twitter_http_get_home_timeline(struct http_request *req) parser = xt_new( NULL, txl ); xt_feed( parser, req->reply_body, req->body_size ); // The root <statuses> node should hold the list of statuses <status> - twitter_xt_get_status_list(parser->root, txl); + twitter_xt_get_status_list(ic, parser->root, txl); xt_free( parser ); // See if the user wants to see the messages in a groupchat window or as private messages. |