Changeset dff0e0b for protocols/twitter
- Timestamp:
- 2012-11-11T14:42:20Z (12 years ago)
- Branches:
- master
- Children:
- 62f6b45
- Parents:
- ddc2de5
- Location:
- protocols/twitter
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
rddc2de5 rdff0e0b 5 5 * * 6 6 * Copyright 2009 Geert Mulders <g.c.w.m.mulders@gmail.com> * 7 * Copyright 2010-2012 Wilmer van der Gaast <wilmer@gaast.net> * 7 8 * * 8 9 * This library is free software; you can redistribute it and/or * … … 66 67 // Run this once. After this queue the main loop function. 67 68 twitter_main_loop(ic, -1, 0); 68 69 // Queue the main_loop 70 // Save the return value, so we can remove the timeout on logout. 71 td->main_loop_id = 72 b_timeout_add(set_getint(&ic->acc->set, "fetch_interval") * 1000, twitter_main_loop, ic); 69 70 if (set_getbool(&ic->acc->set, "stream")) { 71 /* That fetch was just to get backlog, the stream will give 72 us the rest. \o/ */ 73 twitter_open_stream(ic); 74 } else { 75 /* Not using the streaming API, so keep polling the old- 76 fashioned way. :-( */ 77 td->main_loop_id = 78 b_timeout_add(set_getint(&ic->acc->set, "fetch_interval") * 1000, 79 twitter_main_loop, ic); 80 } 73 81 } 74 82 … … 279 287 280 288 s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc); 289 290 s = set_add(&acc->set, "stream", "true", set_eval_bool, acc); 291 s->flags |= ACC_SET_OFFLINE_ONLY; 281 292 } 282 293 -
protocols/twitter/twitter_lib.c
rddc2de5 rdff0e0b 176 176 root = json_parse(req->reply_body); 177 177 err = json_o_get(root, "errors"); 178 if (err ->type == json_array && (err = err->u.array.values[0]) &&178 if (err && err->type == json_array && (err = err->u.array.values[0]) && 179 179 err->type == json_object) { 180 180 const char *msg = json_o_str(err, "message"); … … 529 529 } 530 530 531 return TRUE;531 return txs->text && txs->user && txs->id; 532 532 } 533 533 … … 727 727 } 728 728 729 static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor); 730 static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor); 729 static gboolean twitter_stream_handle_object(struct im_connection *ic, json_value *o); 731 730 732 731 static void twitter_http_stream(struct http_request *req) 733 732 { 734 int len; 735 int i; 733 struct im_connection *ic = req->data; 734 //struct twitter_data *td = ic->proto_data; 735 json_value *parsed; 736 int len, i; 736 737 char c; 737 json_value *j; 738 739 if (!g_slist_find(twitter_connections, ic)) 740 return; 741 //td = ic->proto_data;; 738 742 739 743 printf( "%d bytes in stream\n", req->body_size ); … … 763 767 764 768 printf("JSON: %s\n", req->reply_body); 765 printf("parsed: %p\n", (j = json_parse(req->reply_body))); 766 json_value_free(j); 769 printf("parsed: %p\n", (parsed = json_parse(req->reply_body))); 770 if (parsed) { 771 twitter_stream_handle_object(ic, parsed); 772 } 773 json_value_free(parsed); 767 774 req->reply_body[len] = c; 768 775 769 776 http_flush_bytes(req, len); 770 } 777 778 /* One notification might bring multiple events! */ 779 if (req->body_size > 0) 780 twitter_http_stream(req); 781 } 782 783 static gboolean twitter_stream_handle_object(struct im_connection *ic, json_value *o) 784 { 785 struct twitter_xml_status *txs = g_new0(struct twitter_xml_status, 1); 786 787 if (twitter_xt_get_status(o, txs)) { 788 GSList *output = g_slist_append(NULL, txs); 789 twitter_groupchat(ic, output); 790 txs_free(txs); 791 g_slist_free(output); 792 return TRUE; 793 } 794 txs_free(txs); 795 return FALSE; 796 } 797 798 gboolean twitter_open_stream(struct im_connection *ic) 799 { 800 struct twitter_data *td = ic->proto_data; 801 char *args[4] = {"with", "followings", "delimited", "length"}; 802 803 if ((td->stream = twitter_http(ic, TWITTER_USER_STREAM_URL, 804 twitter_http_stream, ic, 0, args, 4))) { 805 /* This flag must be enabled or we'll get no data until EOF 806 (which err, kind of, defeats the purpose of a streaming API). */ 807 td->stream->flags |= HTTPC_STREAMING; 808 return TRUE; 809 } 810 811 return FALSE; 812 } 813 814 static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor); 815 static void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor); 771 816 772 817 /** … … 791 836 if (include_mentions) { 792 837 twitter_get_mentions(ic, next_cursor); 793 }794 795 static int bla = 0;796 797 if (bla)798 return;799 bla = 1;800 801 char *args[4];802 args[0] = "with";803 args[1] = "followings";804 args[2] = "delimited";805 args[3] = "length";806 807 if ((td->stream = twitter_http(ic, "https://userstream.twitter.com/1.1/user.json",808 twitter_http_stream, ic, 0, args, 4))) {809 td->stream->flags |= HTTPC_STREAMING;810 838 } 811 839 } -
protocols/twitter/twitter_lib.h
rddc2de5 rdff0e0b 79 79 #define TWITTER_REPORT_SPAM_URL "/report_spam.json" 80 80 81 #define TWITTER_USER_STREAM_URL "https://userstream.twitter.com/1.1/user.json" 82 83 gboolean twitter_open_stream(struct im_connection *ic); 81 84 void twitter_get_timeline(struct im_connection *ic, gint64 next_cursor); 82 85 void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor);
Note: See TracChangeset
for help on using the changeset viewer.