Changeset c9b5817 for protocols/twitter
- Timestamp:
- 2012-11-25T00:55:47Z (12 years ago)
- Branches:
- master
- Children:
- e9bdfbc
- Parents:
- 5f2f728
- Location:
- protocols/twitter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r5f2f728 rc9b5817 286 286 287 287 s = set_add(&acc->set, "show_ids", "true", set_eval_bool, acc); 288 s->flags |= ACC_SET_OFFLINE_ONLY;289 288 290 289 s = set_add(&acc->set, "show_old_mentions", "20", set_eval_int, acc); … … 363 362 imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL); 364 363 365 if (set_getbool(&acc->set, "show_ids"))366 td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH);364 td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH); 365 td->log_id = -1; 367 366 368 367 twitter_login_finish(ic); -
protocols/twitter/twitter_lib.c
r5f2f728 rc9b5817 458 458 * - the user in a twitter_xml_user struct. 459 459 */ 460 static gboolean twitter_xt_get_status(const json_value *node, struct twitter_xml_status *txs) 461 { 460 static struct twitter_xml_status *twitter_xt_get_status(const json_value *node) 461 { 462 struct twitter_xml_status *txs; 462 463 const json_value *rt = NULL, *entities = NULL; 463 464 464 465 if (node->type != json_object) 465 466 return FALSE; 467 txs = g_new0(struct twitter_xml_status, 1); 466 468 467 469 JSON_O_FOREACH (node, k, v) { … … 492 494 wasn't truncated because it may be lying. */ 493 495 if (rt) { 494 struct twitter_xml_status *rtxs = g_new0(struct twitter_xml_status, 1); 495 if (!twitter_xt_get_status(rt, rtxs)) { 496 struct twitter_xml_status *rtxs = twitter_xt_get_status(rt); 497 if (rtxs) { 498 g_free(txs->text); 499 txs->text = g_strdup_printf("RT @%s: %s", rtxs->user->screen_name, rtxs->text); 500 txs->id = rtxs->id; 496 501 txs_free(rtxs); 497 return TRUE; 498 } 499 500 g_free(txs->text); 501 txs->text = g_strdup_printf("RT @%s: %s", rtxs->user->screen_name, rtxs->text); 502 txs_free(rtxs); 502 } 503 503 } else if (entities) { 504 504 txs->text = expand_entities(txs->text, entities); 505 505 } 506 506 507 return txs->text && txs->user && txs->id; 507 if (txs->text && txs->user && txs->id) 508 return txs; 509 510 txs_free(txs); 511 return NULL; 508 512 } 509 513 … … 585 589 { 586 590 struct twitter_xml_status *txs; 587 bee_user_t *bu;588 591 int i; 589 592 … … 597 600 // Walk over the nodes children. 598 601 for (i = 0; i < node->u.array.length; i ++) { 599 txs = g_new0(struct twitter_xml_status, 1); 600 twitter_xt_get_status(node->u.array.values[i], txs); 601 // Put the item in the front of the list. 602 txs = twitter_xt_get_status(node->u.array.values[i]); 603 if (!txs) 604 continue; 605 602 606 txl->list = g_slist_prepend(txl->list, txs); 603 604 if (txs->user && txs->user->screen_name &&605 (bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name))) {606 struct twitter_user_data *tud = bu->data;607 608 if (txs->id > tud->last_id) {609 tud->last_id = txs->id;610 tud->last_time = txs->created_at;611 }612 }613 607 } 614 608 … … 616 610 } 617 611 612 /* Will log messages either way. Need to keep track of IDs for stream deduping. 613 Plus, show_ids is on by default and I don't see why anyone would disable it. */ 618 614 static char *twitter_msg_add_id(struct im_connection *ic, 619 615 struct twitter_xml_status *txs, const char *prefix) 620 616 { 621 617 struct twitter_data *td = ic->proto_data; 622 char *ret = NULL; 623 624 if (!set_getbool(&ic->acc->set, "show_ids")) { 618 int reply_to = -1; 619 bee_user_t *bu; 620 621 if (txs->reply_to) { 622 int i; 623 for (i = 0; i < TWITTER_LOG_LENGTH; i++) 624 if (td->log[i].id == txs->reply_to) { 625 reply_to = i; 626 break; 627 } 628 } 629 630 if (txs->user && txs->user->screen_name && 631 (bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name))) { 632 struct twitter_user_data *tud = bu->data; 633 634 if (txs->id > tud->last_id) { 635 tud->last_id = txs->id; 636 tud->last_time = txs->created_at; 637 } 638 } 639 640 td->log_id = (td->log_id + 1) % TWITTER_LOG_LENGTH; 641 td->log[td->log_id].id = txs->id; 642 td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name); 643 644 if (set_getbool(&ic->acc->set, "show_ids")) { 645 if (reply_to != -1) 646 return g_strdup_printf("\002[\002%02d->%02d\002]\002 %s%s", 647 td->log_id, reply_to, prefix, txs->text); 648 else 649 return g_strdup_printf("\002[\002%02d\002]\002 %s%s", 650 td->log_id, prefix, txs->text); 651 } else { 625 652 if (*prefix) 626 653 return g_strconcat(prefix, txs->text, NULL); … … 628 655 return NULL; 629 656 } 630 631 td->log[td->log_id].id = txs->id;632 td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name);633 if (txs->reply_to) {634 int i;635 for (i = 0; i < TWITTER_LOG_LENGTH; i++)636 if (td->log[i].id == txs->reply_to) {637 ret = g_strdup_printf("\002[\002%02d->%02d\002]\002 %s%s",638 td->log_id, i, prefix, txs->text);639 break;640 }641 }642 if (ret == NULL)643 ret = g_strdup_printf("\002[\002%02d\002]\002 %s%s", td->log_id, prefix, txs->text);644 td->log_id = (td->log_id + 1) % TWITTER_LOG_LENGTH;645 646 return ret;647 657 } 648 658 … … 826 836 827 837 static gboolean twitter_stream_handle_event(struct im_connection *ic, json_value *o); 838 static gboolean twitter_stream_handle_status(struct im_connection *ic, struct twitter_xml_status *txs); 828 839 829 840 static gboolean twitter_stream_handle_object(struct im_connection *ic, json_value *o) 830 841 { 831 842 struct twitter_data *td = ic->proto_data; 832 struct twitter_xml_status *txs = g_new0(struct twitter_xml_status, 1);843 struct twitter_xml_status *txs; 833 844 json_value *c; 834 845 835 if (twitter_xt_get_status(o, txs)) { 836 GSList *output = g_slist_append(NULL, txs); 837 twitter_groupchat(ic, output); 838 txs_free(txs); 839 g_slist_free(output); 840 return TRUE; 846 if ((txs = twitter_xt_get_status(o))) { 847 return twitter_stream_handle_status(ic, txs); 841 848 } else if ((c = json_o_get(o, "direct_message")) && 842 849 twitter_xt_get_dm(c, txs)) { … … 860 867 return TRUE; 861 868 } 869 return FALSE; 870 } 871 872 static gboolean twitter_stream_handle_status(struct im_connection *ic, struct twitter_xml_status *txs) 873 { 874 struct twitter_data *td = ic->proto_data; 875 int i; 876 877 for (i = 0; i < TWITTER_LOG_LENGTH; i++) { 878 if (td->log[i].id == txs->id) { 879 /* Got a duplicate (RT, surely). Drop it. */ 880 txs_free(txs); 881 return TRUE; 882 } 883 } 884 885 if (!(set_getbool(&ic->acc->set, "fetch_mentions") || 886 bee_user_by_handle(ic->bee, ic, txs->user->screen_name))) { 887 /* Tweet is from an unknown person and the user does not want 888 to see @mentions, so drop it. twitter_stream_handle_event() 889 picks up new follows so this simple filter should be safe. */ 890 /* TODO: The streaming API seems to do poor @mention matching. 891 I.e. I'm getting mentions for @WilmerSomething, not just for 892 @Wilmer. But meh. You want spam, you get spam. */ 893 return TRUE; 894 } 895 896 GSList *output = g_slist_append(NULL, txs); 897 twitter_groupchat(ic, output); 862 898 txs_free(txs); 863 return FALSE; 899 g_slist_free(output); 900 return TRUE; 864 901 } 865 902
Note: See TracChangeset
for help on using the changeset viewer.