Changeset fb62f132
- Timestamp:
- 2016-03-23T20:23:36Z (9 years ago)
- Branches:
- master
- Children:
- 9cf63ac
- Parents:
- d701547
- git-author:
- Flexo <nick@…> (15-03-16 21:39:36)
- git-committer:
- Flexo <nick@…> (23-03-16 20:23:36)
- Location:
- protocols/twitter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
rd701547 rfb62f132 345 345 imcb_log(ic, "Getting contact list"); 346 346 twitter_get_friends_ids(ic, -1); 347 twitter_get_mutes_ids(ic, -1); 348 twitter_get_noretweets_ids(ic, -1); 347 349 } else { 348 350 twitter_main_loop_start(ic); -
protocols/twitter/twitter.h
rd701547 rfb62f132 61 61 62 62 GSList *follow_ids; 63 GSList *mutes_ids; 64 GSList *noretweets_ids; 63 65 GSList *filters; 64 66 -
protocols/twitter/twitter_lib.c
rd701547 rfb62f132 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); 242 244 243 245 /** … … 252 254 args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor); 253 255 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); 254 284 255 285 g_free(args[1]); … … 332 362 twitter_get_users_lookup(ic); 333 363 } 364 365 txl->list = NULL; 366 txl_free(txl); 367 } 368 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 active 380 if (!g_slist_find(twitter_connections, ic)) { 381 return; 382 } 383 384 td = ic->proto_data; 385 386 // Parse the data. 387 if (!(parsed = twitter_parse_response(ic, req))) { 388 return; 389 } 390 391 txl = g_new0(struct twitter_xml_list, 1); 392 txl->list = td->mutes_ids; 393 394 /* mute ids API response is similar enough to friends response 395 to reuse this method */ 396 twitter_xt_get_friends_id_list(parsed, txl); 397 json_value_free(parsed); 398 399 td->mutes_ids = txl->list; 400 if (txl->next_cursor) { 401 /* Recurse while there are still more pages */ 402 twitter_get_mutes_ids(ic, txl->next_cursor); 403 } 404 405 txl->list = NULL; 406 txl_free(txl); 407 } 408 409 /** 410 * Callback for getting the no-retweets ids. 411 */ 412 static void twitter_http_get_noretweets_ids(struct http_request *req) 413 { 414 struct im_connection *ic = req->data; 415 json_value *parsed; 416 struct twitter_xml_list *txl; 417 struct twitter_data *td; 418 419 // Check if the connection is stil active 420 if (!g_slist_find(twitter_connections, ic)) { 421 return; 422 } 423 424 td = ic->proto_data; 425 426 // Parse the data. 427 if (!(parsed = twitter_parse_response(ic, req))) { 428 return; 429 } 430 431 txl = g_new0(struct twitter_xml_list, 1); 432 txl->list = td->noretweets_ids; 433 434 // Process the retweet ids 435 txl->type = TXL_ID; 436 if (parsed->type == json_array) { 437 unsigned int i; 438 for (i = 0; i < parsed->u.array.length; i++) { 439 json_value *c = parsed->u.array.values[i]; 440 if (c->type != json_integer) { 441 continue; 442 } 443 txl->list = g_slist_prepend(txl->list, 444 g_strdup_printf("%"PRIu64, c->u.integer)); 445 } 446 } 447 448 json_value_free(parsed); 449 td->noretweets_ids = txl->list; 334 450 335 451 txl->list = NULL; … … 831 947 struct twitter_data *td = ic->proto_data; 832 948 char *last_id_str; 949 char *uid_str; 833 950 834 951 if (status->user == NULL || status->text == NULL) { 952 return; 953 } 954 955 /* Check this is not a tweet that should be muted */ 956 uid_str = g_strdup_printf("%" PRIu64, status->user->uid); 957 if (g_slist_find_custom(td->mutes_ids, uid_str, (GCompareFunc)strcmp)) { 958 g_free(uid_str); 959 return; 960 } 961 if (status->id != status->rt_id && g_slist_find_custom(td->noretweets_ids, uid_str, (GCompareFunc)strcmp)) { 962 g_free(uid_str); 835 963 return; 836 964 } … … 857 985 set_setstr(&ic->acc->set, "_last_tweet", last_id_str); 858 986 g_free(last_id_str); 987 g_free(uid_str); 859 988 } 860 989 -
protocols/twitter/twitter_lib.h
rd701547 rfb62f132 63 63 #define TWITTER_FRIENDS_IDS_URL "/friends/ids.json" 64 64 #define TWITTER_FOLLOWERS_IDS_URL "/followers/ids.json" 65 #define TWITTER_MUTES_IDS_URL "/mutes/users/ids.json" 66 #define TWITTER_NORETWEETS_IDS_URL "/friendships/no_retweets/ids.json" 65 67 66 68 /* Account URLs */ … … 87 89 gboolean twitter_get_timeline(struct im_connection *ic, gint64 next_cursor); 88 90 void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor); 91 void twitter_get_mutes_ids(struct im_connection *ic, gint64 next_cursor); 92 void twitter_get_noretweets_ids(struct im_connection *ic, gint64 next_cursor); 89 93 void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor); 90 94
Note: See TracChangeset
for help on using the changeset viewer.