Changes in protocols/twitter/twitter_lib.c [58d285a:bbff22d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter_lib.c
r58d285a rbbff22d 240 240 241 241 static void twitter_http_get_friends_ids(struct http_request *req); 242 static void twitter_http_get_mutes_ids(struct http_request *req);243 static void twitter_http_get_noretweets_ids(struct http_request *req);244 242 245 243 /** … … 254 252 args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor); 255 253 twitter_http(ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2); 256 257 g_free(args[1]);258 }259 260 /**261 * Get the muted users ids.262 */263 void twitter_get_mutes_ids(struct im_connection *ic, gint64 next_cursor)264 {265 char *args[2];266 267 args[0] = "cursor";268 args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor);269 twitter_http(ic, TWITTER_MUTES_IDS_URL, twitter_http_get_mutes_ids, ic, 0, args, 2);270 271 g_free(args[1]);272 }273 274 /**275 * Get the ids for users from whom we should ignore retweets.276 */277 void twitter_get_noretweets_ids(struct im_connection *ic, gint64 next_cursor)278 {279 char *args[2];280 281 args[0] = "cursor";282 args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor);283 twitter_http(ic, TWITTER_NORETWEETS_IDS_URL, twitter_http_get_noretweets_ids, ic, 0, args, 2);284 254 285 255 g_free(args[1]); … … 367 337 } 368 338 369 /**370 * Callback for getting the mutes ids.371 */372 static void twitter_http_get_mutes_ids(struct http_request *req)373 {374 struct im_connection *ic = req->data;375 json_value *parsed;376 struct twitter_xml_list *txl;377 struct twitter_data *td;378 379 // Check if the connection is stil active380 if (!g_slist_find(twitter_connections, ic)) {381 return;382 }383 384 td = ic->proto_data;385 386 if (req->status_code != 200) {387 /* Fail silently */388 return;389 }390 391 // Parse the data.392 if (!(parsed = twitter_parse_response(ic, req))) {393 return;394 }395 396 txl = g_new0(struct twitter_xml_list, 1);397 txl->list = td->mutes_ids;398 399 /* mute ids API response is similar enough to friends response400 to reuse this method */401 twitter_xt_get_friends_id_list(parsed, txl);402 json_value_free(parsed);403 404 td->mutes_ids = txl->list;405 if (txl->next_cursor) {406 /* Recurse while there are still more pages */407 twitter_get_mutes_ids(ic, txl->next_cursor);408 }409 410 txl->list = NULL;411 txl_free(txl);412 }413 414 /**415 * Callback for getting the no-retweets ids.416 */417 static void twitter_http_get_noretweets_ids(struct http_request *req)418 {419 struct im_connection *ic = req->data;420 json_value *parsed;421 struct twitter_xml_list *txl;422 struct twitter_data *td;423 424 // Check if the connection is stil active425 if (!g_slist_find(twitter_connections, ic)) {426 return;427 }428 429 if (req->status_code != 200) {430 /* Fail silently */431 return;432 }433 434 td = ic->proto_data;435 436 // Parse the data.437 if (!(parsed = twitter_parse_response(ic, req))) {438 return;439 }440 441 txl = g_new0(struct twitter_xml_list, 1);442 txl->list = td->noretweets_ids;443 444 // Process the retweet ids445 txl->type = TXL_ID;446 if (parsed->type == json_array) {447 unsigned int i;448 for (i = 0; i < parsed->u.array.length; i++) {449 json_value *c = parsed->u.array.values[i];450 if (c->type != json_integer) {451 continue;452 }453 txl->list = g_slist_prepend(txl->list,454 g_strdup_printf("%"PRIu64, c->u.integer));455 }456 }457 458 json_value_free(parsed);459 td->noretweets_ids = txl->list;460 461 txl->list = NULL;462 txl_free(txl);463 }464 465 339 static gboolean twitter_xt_get_users(json_value *node, struct twitter_xml_list *txl); 466 340 static void twitter_http_get_users_lookup(struct http_request *req); … … 587 461 #endif 588 462 589 static void expand_entities(char **text, const json_value *node , const json_value *extended_node);463 static void expand_entities(char **text, const json_value *node); 590 464 591 465 /** … … 599 473 static struct twitter_xml_status *twitter_xt_get_status(const json_value *node) 600 474 { 601 struct twitter_xml_status *txs = {0};475 struct twitter_xml_status *txs; 602 476 const json_value *rt = NULL; 603 const json_value *text_value = NULL;604 const json_value *extended_node = NULL;605 477 606 478 if (node->type != json_object) { … … 610 482 611 483 JSON_O_FOREACH(node, k, v) { 612 if (strcmp("text", k) == 0 && v->type == json_string && text_value == NULL) { 613 text_value = v; 614 } else if (strcmp("full_text", k) == 0 && v->type == json_string) { 615 text_value = v; 616 } else if (strcmp("extended_tweet", k) == 0 && v->type == json_object) { 617 text_value = json_o_get(v, "full_text"); 618 extended_node = v; 484 if (strcmp("text", k) == 0 && v->type == json_string) { 485 txs->text = g_memdup(v->u.string.ptr, v->u.string.length + 1); 486 strip_html(txs->text); 619 487 } else if (strcmp("retweeted_status", k) == 0 && v->type == json_object) { 620 488 rt = v; … … 642 510 struct twitter_xml_status *rtxs = twitter_xt_get_status(rt); 643 511 if (rtxs) { 512 g_free(txs->text); 644 513 txs->text = g_strdup_printf("RT @%s: %s", rtxs->user->screen_name, rtxs->text); 645 514 txs->id = rtxs->id; 646 515 txs_free(rtxs); 647 516 } 648 } else if (text_value && text_value->type == json_string) { 649 txs->text = g_memdup(text_value->u.string.ptr, text_value->u.string.length + 1); 650 strip_html(txs->text); 651 expand_entities(&txs->text, node, extended_node); 517 } else { 518 expand_entities(&txs->text, node); 652 519 } 653 520 … … 692 559 } 693 560 694 expand_entities(&txs->text, node , NULL);561 expand_entities(&txs->text, node); 695 562 696 563 if (txs->text && txs->user && txs->id) { … … 702 569 } 703 570 704 static void expand_entities(char **text, const json_value *node , const json_value *extended_node)705 { 706 json_value *entities, * extended_entities, *quoted;571 static void expand_entities(char **text, const json_value *node) 572 { 573 json_value *entities, *quoted; 707 574 char *quote_url = NULL, *quote_text = NULL; 708 575 … … 722 589 } 723 590 724 if (extended_node) {725 extended_entities = json_o_get(extended_node, "entities");726 if (extended_entities && extended_entities->type == json_object) {727 entities = extended_entities;728 }729 }730 731 591 JSON_O_FOREACH(entities, k, v) { 732 592 int i; … … 971 831 struct twitter_data *td = ic->proto_data; 972 832 char *last_id_str; 973 char *uid_str;974 833 975 834 if (status->user == NULL || status->text == NULL) { 976 return;977 }978 979 /* Check this is not a tweet that should be muted */980 uid_str = g_strdup_printf("%" PRIu64, status->user->uid);981 982 if (g_slist_find_custom(td->mutes_ids, uid_str, (GCompareFunc)strcmp)) {983 g_free(uid_str);984 return;985 }986 if (status->id != status->rt_id && g_slist_find_custom(td->noretweets_ids, uid_str, (GCompareFunc)strcmp)) {987 g_free(uid_str);988 835 return; 989 836 } … … 1010 857 set_setstr(&ic->acc->set, "_last_tweet", last_id_str); 1011 858 g_free(last_id_str); 1012 g_free(uid_str);1013 859 } 1014 860 … … 1028 874 } 1029 875 876 ic->flags |= OPT_PONGED; 1030 877 td = ic->proto_data; 1031 878 … … 1043 890 imc_logout(ic, TRUE); 1044 891 return; 1045 }1046 1047 if (req == td->stream) {1048 ic->flags |= OPT_PONGED;1049 892 } 1050 893 … … 1150 993 json_value *target = json_o_get(o, "target"); 1151 994 const char *type = json_o_str(o, "event"); 1152 struct twitter_xml_user *us = NULL;1153 struct twitter_xml_user *ut = NULL;1154 995 1155 996 if (!type || !source || source->type != json_object … … 1159 1000 1160 1001 if (strcmp(type, "follow") == 0) { 1161 us = twitter_xt_get_user(source);1162 ut = twitter_xt_get_user(target);1002 struct twitter_xml_user *us = twitter_xt_get_user(source); 1003 struct twitter_xml_user *ut = twitter_xt_get_user(target); 1163 1004 if (g_strcasecmp(us->screen_name, td->user) == 0) { 1164 1005 twitter_add_buddy(ic, ut->screen_name, ut->name); 1165 1006 } 1166 } else if (strcmp(type, "mute") == 0) { 1167 GSList *found; 1168 char *uid_str; 1169 ut = twitter_xt_get_user(target); 1170 uid_str = g_strdup_printf("%" PRIu64, ut->uid); 1171 if (!(found = g_slist_find_custom(td->mutes_ids, uid_str, 1172 (GCompareFunc)strcmp))) { 1173 td->mutes_ids = g_slist_prepend(td->mutes_ids, uid_str); 1174 } 1175 twitter_log(ic, "Muted user %s", ut->screen_name); 1176 if (getenv("BITLBEE_DEBUG")) { 1177 fprintf(stderr, "New mute: %s %"PRIu64"\n", 1178 ut->screen_name, ut->uid); 1179 } 1180 } else if (strcmp(type, "unmute") == 0) { 1181 GSList *found; 1182 char *uid_str; 1183 ut = twitter_xt_get_user(target); 1184 uid_str = g_strdup_printf("%" PRIu64, ut->uid); 1185 if ((found = g_slist_find_custom(td->mutes_ids, uid_str, 1186 (GCompareFunc)strcmp))) { 1187 char *found_str = found->data; 1188 td->mutes_ids = g_slist_delete_link(td->mutes_ids, found); 1189 g_free(found_str); 1190 } 1191 g_free(uid_str); 1192 twitter_log(ic, "Unmuted user %s", ut->screen_name); 1193 if (getenv("BITLBEE_DEBUG")) { 1194 fprintf(stderr, "New unmute: %s %"PRIu64"\n", 1195 ut->screen_name, ut->uid); 1196 } 1197 } 1198 1199 txu_free(us); 1200 txu_free(ut); 1007 txu_free(us); 1008 txu_free(ut); 1009 } 1201 1010 1202 1011 return TRUE; … … 1496 1305 td->flags &= ~TWITTER_GOT_TIMELINE; 1497 1306 1498 char *args[ 8];1307 char *args[6]; 1499 1308 args[0] = "cursor"; 1500 1309 args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor); 1501 1310 args[2] = "include_entities"; 1502 1311 args[3] = "true"; 1503 args[4] = "tweet_mode";1504 args[5] = "extended";1505 1312 if (td->timeline_id) { 1506 args[ 6] = "since_id";1507 args[ 7] = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id);1313 args[4] = "since_id"; 1314 args[5] = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id); 1508 1315 } 1509 1316 1510 1317 if (twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args, 1511 td->timeline_id ? 8 : 6) == NULL) {1318 td->timeline_id ? 6 : 4) == NULL) { 1512 1319 if (++td->http_fails >= 5) { 1513 1320 imcb_error(ic, "Could not retrieve %s: %s", … … 1520 1327 g_free(args[1]); 1521 1328 if (td->timeline_id) { 1522 g_free(args[ 7]);1329 g_free(args[5]); 1523 1330 } 1524 1331 } … … 1535 1342 td->flags &= ~TWITTER_GOT_MENTIONS; 1536 1343 1537 char *args[ 8];1344 char *args[6]; 1538 1345 args[0] = "cursor"; 1539 1346 args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor); … … 1547 1354 args[5] = g_strdup_printf("%d", set_getint(&ic->acc->set, "show_old_mentions")); 1548 1355 } 1549 args[6] = "tweet_mode";1550 args[7] = "extended";1551 1356 1552 1357 if (twitter_http(ic, TWITTER_MENTIONS_URL, twitter_http_get_mentions, 1553 ic, 0, args, 8) == NULL) {1358 ic, 0, args, 6) == NULL) { 1554 1359 if (++td->http_fails >= 5) { 1555 1360 imcb_error(ic, "Could not retrieve %s: %s", … … 1719 1524 } 1720 1525 1721 /**1722 * Mute or unmute a user1723 */1724 void twitter_mute_create_destroy(struct im_connection *ic, char *who, int create)1725 {1726 char *args[2];1727 1728 args[0] = "screen_name";1729 args[1] = who;1730 twitter_http(ic, create ? TWITTER_MUTES_CREATE_URL : TWITTER_MUTES_DESTROY_URL,1731 twitter_http_post, ic, 1, args, 2);1732 }1733 1734 1526 void twitter_status_destroy(struct im_connection *ic, guint64 id) 1735 1527 {
Note: See TracChangeset
for help on using the changeset viewer.