Changes in / [991c75f:c9603a3]
- Location:
- protocols/twitter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
r991c75f rc9603a3 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);349 347 } else { 350 348 twitter_main_loop_start(ic); … … 957 955 } else if (g_strcasecmp(cmd[0], "unfollow") == 0 && cmd[1]) { 958 956 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);965 957 goto eof; 966 958 } else if ((g_strcasecmp(cmd[0], "report") == 0 || -
protocols/twitter/twitter.h
r991c75f rc9603a3 61 61 62 62 GSList *follow_ids; 63 GSList *mutes_ids;64 GSList *noretweets_ids;65 63 GSList *filters; 66 64 -
protocols/twitter/twitter_lib.c
r991c75f rc9603a3 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]); … … 362 332 twitter_get_users_lookup(ic); 363 333 } 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 active380 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 response395 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 active420 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 ids435 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;450 334 451 335 txl->list = NULL; … … 947 831 struct twitter_data *td = ic->proto_data; 948 832 char *last_id_str; 949 char *uid_str;950 833 951 834 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);970 835 return; 971 836 } … … 992 857 set_setstr(&ic->acc->set, "_last_tweet", last_id_str); 993 858 g_free(last_id_str); 994 g_free(uid_str);995 859 } 996 860 … … 1129 993 json_value *target = json_o_get(o, "target"); 1130 994 const char *type = json_o_str(o, "event"); 1131 struct twitter_xml_user *us = NULL;1132 struct twitter_xml_user *ut = NULL;1133 995 1134 996 if (!type || !source || source->type != json_object … … 1138 1000 1139 1001 if (strcmp(type, "follow") == 0) { 1140 us = twitter_xt_get_user(source);1141 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); 1142 1004 if (g_strcasecmp(us->screen_name, td->user) == 0) { 1143 1005 twitter_add_buddy(ic, ut->screen_name, ut->name); 1144 1006 } 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); 1007 txu_free(us); 1008 txu_free(ut); 1009 } 1178 1010 1179 1011 return TRUE; … … 1692 1524 } 1693 1525 1694 /**1695 * Mute or unmute a user1696 */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 1707 1526 void twitter_status_destroy(struct im_connection *ic, guint64 id) 1708 1527 { -
protocols/twitter/twitter_lib.h
r991c75f rc9603a3 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"67 65 68 66 /* Account URLs */ … … 78 76 #define TWITTER_BLOCKS_DESTROY_URL "/blocks/destroy/" 79 77 80 /* Mute URLs */81 #define TWITTER_MUTES_CREATE_URL "/mutes/users/create.json"82 #define TWITTER_MUTES_DESTROY_URL "/mutes/users/destroy.json"83 84 78 /* Report spam */ 85 79 #define TWITTER_REPORT_SPAM_URL "/users/report_spam.json" … … 93 87 gboolean twitter_get_timeline(struct im_connection *ic, gint64 next_cursor); 94 88 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);97 89 void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor); 98 90 … … 100 92 void twitter_direct_messages_new(struct im_connection *ic, char *who, char *message); 101 93 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);103 94 void twitter_status_destroy(struct im_connection *ic, guint64 id); 104 95 void twitter_status_retweet(struct im_connection *ic, guint64 id);
Note: See TracChangeset
for help on using the changeset viewer.