Changeset 991c75f for protocols/twitter
- Timestamp:
- 2016-04-16T17:21:33Z (9 years ago)
- Branches:
- master
- Children:
- a244877
- Parents:
- c9603a3 (diff), 166a571 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- protocols/twitter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
rc9603a3 r991c75f 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); … … 955 957 } else if (g_strcasecmp(cmd[0], "unfollow") == 0 && cmd[1]) { 956 958 twitter_remove_buddy(ic, cmd[1], NULL); 959 goto eof; 960 } else if (g_strcasecmp(cmd[0], "mute") == 0 && cmd[1]) { 961 twitter_mute_create_destroy(ic, cmd[1], 1); 962 goto eof; 963 } else if (g_strcasecmp(cmd[0], "unmute") == 0 && cmd[1]) { 964 twitter_mute_create_destroy(ic, cmd[1], 0); 957 965 goto eof; 958 966 } else if ((g_strcasecmp(cmd[0], "report") == 0 || -
protocols/twitter/twitter.h
rc9603a3 r991c75f 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
rc9603a3 r991c75f 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 (getenv("BITLBEE_DEBUG")) { 958 GSList *item; 959 fprintf(stderr, "Checking mutes; this uid=%s\n", uid_str); 960 for (item = td->mutes_ids; item != NULL; item = item->next) { 961 fprintf(stderr, " id: %s\n", (char *)item->data); 962 } 963 } 964 if (g_slist_find_custom(td->mutes_ids, uid_str, (GCompareFunc)strcmp)) { 965 g_free(uid_str); 966 return; 967 } 968 if (status->id != status->rt_id && g_slist_find_custom(td->noretweets_ids, uid_str, (GCompareFunc)strcmp)) { 969 g_free(uid_str); 835 970 return; 836 971 } … … 857 992 set_setstr(&ic->acc->set, "_last_tweet", last_id_str); 858 993 g_free(last_id_str); 994 g_free(uid_str); 859 995 } 860 996 … … 993 1129 json_value *target = json_o_get(o, "target"); 994 1130 const char *type = json_o_str(o, "event"); 1131 struct twitter_xml_user *us = NULL; 1132 struct twitter_xml_user *ut = NULL; 995 1133 996 1134 if (!type || !source || source->type != json_object … … 1000 1138 1001 1139 if (strcmp(type, "follow") == 0) { 1002 struct twitter_xml_user *us = twitter_xt_get_user(source);1003 struct twitter_xml_user *ut = twitter_xt_get_user(target);1140 us = twitter_xt_get_user(source); 1141 ut = twitter_xt_get_user(target); 1004 1142 if (g_strcasecmp(us->screen_name, td->user) == 0) { 1005 1143 twitter_add_buddy(ic, ut->screen_name, ut->name); 1006 1144 } 1007 txu_free(us); 1008 txu_free(ut); 1009 } 1145 } else if (strcmp(type, "mute") == 0) { 1146 GSList *found; 1147 char *uid_str; 1148 ut = twitter_xt_get_user(target); 1149 uid_str = g_strdup_printf("%" PRIu64, ut->uid); 1150 if (!(found = g_slist_find_custom(td->mutes_ids, uid_str, 1151 (GCompareFunc)strcmp))) { 1152 td->mutes_ids = g_slist_prepend(td->mutes_ids, uid_str); 1153 } 1154 twitter_log(ic, "Muted user %s", ut->screen_name); 1155 if (getenv("BITLBEE_DEBUG")) { 1156 fprintf(stderr, "New mute: %s %"PRIu64"\n", 1157 ut->screen_name, ut->uid); 1158 } 1159 } else if (strcmp(type, "unmute") == 0) { 1160 GSList *found; 1161 char *uid_str; 1162 ut = twitter_xt_get_user(target); 1163 uid_str = g_strdup_printf("%" PRIu64, ut->uid); 1164 if ((found = g_slist_find_custom(td->mutes_ids, uid_str, 1165 (GCompareFunc)strcmp))) { 1166 td->mutes_ids = g_slist_remove(td->mutes_ids, found); 1167 } 1168 g_free(uid_str); 1169 twitter_log(ic, "Unmuted user %s", ut->screen_name); 1170 if (getenv("BITLBEE_DEBUG")) { 1171 fprintf(stderr, "New unmute: %s %"PRIu64"\n", 1172 ut->screen_name, ut->uid); 1173 } 1174 } 1175 1176 txu_free(us); 1177 txu_free(ut); 1010 1178 1011 1179 return TRUE; … … 1524 1692 } 1525 1693 1694 /** 1695 * Mute or unmute a user 1696 */ 1697 void twitter_mute_create_destroy(struct im_connection *ic, char *who, int create) 1698 { 1699 char *args[2]; 1700 1701 args[0] = "screen_name"; 1702 args[1] = who; 1703 twitter_http(ic, create ? TWITTER_MUTES_CREATE_URL : TWITTER_MUTES_DESTROY_URL, 1704 twitter_http_post, ic, 1, args, 2); 1705 } 1706 1526 1707 void twitter_status_destroy(struct im_connection *ic, guint64 id) 1527 1708 { -
protocols/twitter/twitter_lib.h
rc9603a3 r991c75f 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 */ … … 76 78 #define TWITTER_BLOCKS_DESTROY_URL "/blocks/destroy/" 77 79 80 /* Mute URLs */ 81 #define TWITTER_MUTES_CREATE_URL "/mutes/users/create.json" 82 #define TWITTER_MUTES_DESTROY_URL "/mutes/users/destroy.json" 83 78 84 /* Report spam */ 79 85 #define TWITTER_REPORT_SPAM_URL "/users/report_spam.json" … … 87 93 gboolean twitter_get_timeline(struct im_connection *ic, gint64 next_cursor); 88 94 void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor); 95 void twitter_get_mutes_ids(struct im_connection *ic, gint64 next_cursor); 96 void twitter_get_noretweets_ids(struct im_connection *ic, gint64 next_cursor); 89 97 void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor); 90 98 … … 92 100 void twitter_direct_messages_new(struct im_connection *ic, char *who, char *message); 93 101 void twitter_friendships_create_destroy(struct im_connection *ic, char *who, int create); 102 void twitter_mute_create_destroy(struct im_connection *ic, char *who, int create); 94 103 void twitter_status_destroy(struct im_connection *ic, guint64 id); 95 104 void twitter_status_retweet(struct im_connection *ic, guint64 id);
Note: See TracChangeset
for help on using the changeset viewer.