Changeset 29f72b7 for protocols/twitter
- Timestamp:
- 2012-11-25T17:43:13Z (12 years ago)
- Branches:
- master
- Children:
- 9ed0081
- Parents:
- 7f557d5
- Location:
- protocols/twitter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r7f557d5 r29f72b7 99 99 bee_user_t *bu = l->data; 100 100 if (bu->ic == ic) 101 imcb_chat_add_buddy( td->timeline_gc, bu->handle);101 imcb_chat_add_buddy(gc, bu->handle); 102 102 } 103 103 imcb_chat_add_buddy(gc, ic->acc->user); -
protocols/twitter/twitter_lib.c
r7f557d5 r29f72b7 463 463 if (strcmp("text", k) == 0 && v->type == json_string) { 464 464 txs->text = g_memdup(v->u.string.ptr, v->u.string.length + 1); 465 strip_html(txs->text); 465 466 } else if (strcmp("retweeted_status", k) == 0 && v->type == json_object) { 466 467 rt = v; … … 520 521 if (strcmp("text", k) == 0 && v->type == json_string) { 521 522 txs->text = g_memdup(v->u.string.ptr, v->u.string.length + 1); 523 strip_html(txs->text); 522 524 } else if (strcmp("created_at", k) == 0 && v->type == json_string) { 523 525 struct tm parsed; … … 567 569 568 570 *pos = '\0'; 569 new = g_strdup_printf("%s%s <%s>%s", text, kort,571 new = g_strdup_printf("%s%s <%s>%s", text, kort, 570 572 disp, pos + strlen(kort)); 571 573 … … 659 661 * Function that is called to see the statuses in a groupchat window. 660 662 */ 661 static void twitter_groupchat(struct im_connection *ic, GSList * list) 662 { 663 struct twitter_data *td = ic->proto_data; 664 GSList *l = NULL; 665 struct twitter_xml_status *status; 663 static void twitter_status_show_chat(struct im_connection *ic, struct twitter_xml_status *status) 664 { 665 struct twitter_data *td = ic->proto_data; 666 666 struct groupchat *gc; 667 guint64 last_id = 0; 667 gboolean me = g_strcasecmp(td->user, status->user->screen_name) == 0; 668 char *msg; 668 669 669 670 // Create a new groupchat if it does not exsist. 670 671 gc = twitter_groupchat_init(ic); 671 672 672 for (l = list; l; l = g_slist_next(l)) { 673 char *msg; 674 675 status = l->data; 676 if (status->user == NULL || status->text == NULL || last_id == status->id) 677 continue; 678 679 last_id = status->id; 680 681 strip_html(status->text); 682 683 if (set_getbool(&ic->acc->set, "strip_newlines")) 684 strip_newlines(status->text); 685 686 msg = twitter_msg_add_id(ic, status, ""); 687 688 // Say it! 689 if (g_strcasecmp(td->user, status->user->screen_name) == 0) { 690 imcb_chat_log(gc, "You: %s", msg ? msg : status->text); 691 } else { 692 twitter_add_buddy(ic, status->user->screen_name, status->user->name); 693 694 imcb_chat_msg(gc, status->user->screen_name, 695 msg ? msg : status->text, 0, status->created_at); 696 } 697 698 g_free(msg); 699 700 // Update the timeline_id to hold the highest id, so that by the next request 701 // we won't pick up the updates already in the list. 702 td->timeline_id = MAX(td->timeline_id, status->id); 703 } 673 if (!me) 674 /* MUST be done before twitter_msg_add_id() to avoid #872. */ 675 twitter_add_buddy(ic, status->user->screen_name, status->user->name); 676 msg = twitter_msg_add_id(ic, status, ""); 677 678 // Say it! 679 if (me) { 680 imcb_chat_log(gc, "You: %s", msg ? msg : status->text); 681 } else { 682 imcb_chat_msg(gc, status->user->screen_name, 683 msg ? msg : status->text, 0, status->created_at); 684 } 685 686 g_free(msg); 704 687 } 705 688 … … 707 690 * Function that is called to see statuses as private messages. 708 691 */ 709 static void twitter_private_message_chat(struct im_connection *ic, GSList * list) 710 { 711 struct twitter_data *td = ic->proto_data; 712 GSList *l = NULL; 713 struct twitter_xml_status *status; 692 static void twitter_status_show_msg(struct im_connection *ic, struct twitter_xml_status *status) 693 { 694 struct twitter_data *td = ic->proto_data; 714 695 char from[MAX_STRING] = ""; 715 guint64 last_id = 0; 696 char *prefix = NULL, *text = NULL; 697 gboolean me = g_strcasecmp(td->user, status->user->screen_name) == 0; 716 698 717 699 if (td->flags & TWITTER_MODE_ONE) { … … 720 702 } 721 703 722 for (l = list; l; l = g_slist_next(l)) { 723 char *prefix = NULL, *text = NULL; 724 725 status = l->data; 726 if (status->user == NULL || status->text == NULL || last_id == status->id) 727 continue; 728 729 last_id = status->id; 730 731 strip_html(status->text); 732 if (td->flags & TWITTER_MODE_ONE) 733 prefix = g_strdup_printf("\002<\002%s\002>\002 ", 734 status->user->screen_name); 735 else 736 twitter_add_buddy(ic, status->user->screen_name, status->user->name); 737 738 text = twitter_msg_add_id(ic, status, prefix ? prefix : ""); 739 740 imcb_buddy_msg(ic, 741 *from ? from : status->user->screen_name, 742 text ? text : status->text, 0, status->created_at); 743 744 // Update the timeline_id to hold the highest id, so that by the next request 745 // we won't pick up the updates already in the list. 746 td->timeline_id = MAX(td->timeline_id, status->id); 747 748 g_free(text); 749 g_free(prefix); 750 } 704 if (td->flags & TWITTER_MODE_ONE) 705 prefix = g_strdup_printf("\002<\002%s\002>\002 ", 706 status->user->screen_name); 707 else if (!me) 708 twitter_add_buddy(ic, status->user->screen_name, status->user->name); 709 else 710 prefix = g_strdup("You: "); 711 712 text = twitter_msg_add_id(ic, status, prefix ? prefix : ""); 713 714 imcb_buddy_msg(ic, 715 *from ? from : status->user->screen_name, 716 text ? text : status->text, 0, status->created_at); 717 718 g_free(text); 719 g_free(prefix); 720 } 721 722 static void twitter_status_show(struct im_connection *ic, struct twitter_xml_status *status) 723 { 724 struct twitter_data *td = ic->proto_data; 725 726 if (status->user == NULL || status->text == NULL) 727 return; 728 729 /* Grrrr. Would like to do this during parsing, but can't access 730 settings from there. */ 731 if (set_getbool(&ic->acc->set, "strip_newlines")) 732 strip_newlines(status->text); 733 734 if (td->flags & TWITTER_MODE_CHAT) 735 twitter_status_show_chat(ic, status); 736 else 737 twitter_status_show_msg(ic, status); 738 739 // Update the timeline_id to hold the highest id, so that by the next request 740 // we won't pick up the updates already in the list. 741 td->timeline_id = MAX(td->timeline_id, status->id); 751 742 } 752 743 … … 848 839 for (i = 0; i < TWITTER_LOG_LENGTH; i++) { 849 840 if (td->log[i].id == txs->id) { 850 /* Got a duplicate (RT, surely). Drop it. */841 /* Got a duplicate (RT, probably). Drop it. */ 851 842 txs_free(txs); 852 843 return TRUE; … … 865 856 } 866 857 867 GSList *output = g_slist_append(NULL, txs); 868 twitter_groupchat(ic, output); 858 twitter_status_show(ic, txs); 869 859 txs_free(txs); 870 g_slist_free(output);860 871 861 return TRUE; 872 862 } … … 951 941 struct twitter_xml_list *home_timeline = td->home_timeline_obj; 952 942 struct twitter_xml_list *mentions = td->mentions_obj; 943 guint64 last_id = 0; 953 944 GSList *output = NULL; 954 945 GSList *l; 955 946 947 imcb_connected(ic); 948 956 949 if (!(td->flags & TWITTER_GOT_TIMELINE)) { 957 950 return; … … 977 970 } 978 971 } 979 980 if (!(ic->flags & OPT_LOGGED_IN))981 imcb_connected(ic);982 972 983 973 // See if the user wants to see the messages in a groupchat window or as private messages. 984 if (td->flags & TWITTER_MODE_CHAT) 985 twitter_groupchat(ic, output); 986 else 987 twitter_private_message_chat(ic, output); 988 989 g_slist_free(output); 974 while (output) { 975 struct twitter_xml_status *txs = output->data; 976 if (txs->id != last_id) 977 twitter_status_show(ic, txs); 978 last_id = txs->id; 979 output = g_slist_remove(output, txs); 980 } 990 981 991 982 txl_free(home_timeline);
Note: See TracChangeset
for help on using the changeset viewer.