diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/twitter/twitter.c | 16 | ||||
-rw-r--r-- | protocols/twitter/twitter.h | 6 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.c | 60 |
3 files changed, 34 insertions, 48 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index c1f54681..468f9eaa 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -350,6 +350,7 @@ void twitter_login_finish(struct im_connection *ic) } else if (!(td->flags & TWITTER_MODE_ONE) && !(td->flags & TWITTER_HAVE_FRIENDS)) { imcb_log(ic, "Getting contact list"); + twitter_get_friends_ids(ic, -1); twitter_get_mutes_ids(ic, -1); twitter_get_blocks_ids(ic, -1); @@ -711,6 +712,10 @@ static void twitter_login(account_t * acc) td->flags |= TWITTER_MODE_CHAT; } + td->mutes_ids = g_hash_table_new_full(g_str_hash, (GEqualFunc)strcmp, (GDestroyNotify)g_free, NULL); + td->blocks_ids = g_hash_table_new_full(g_str_hash, (GEqualFunc)strcmp, (GDestroyNotify)g_free, NULL); + td->noretweets_ids = g_hash_table_new_full(g_str_hash, (GEqualFunc)strcmp, (GDestroyNotify)g_free, NULL); + twitter_login_finish(ic); } @@ -736,14 +741,9 @@ static void twitter_logout(struct im_connection *ic) b_event_remove(td->filter_update_id); } - g_slist_foreach(td->mutes_ids, (GFunc) g_free, NULL); - g_slist_free(td->mutes_ids); - - g_slist_foreach(td->blocks_ids, (GFunc) g_free, NULL); - g_slist_free(td->blocks_ids); - - g_slist_foreach(td->noretweets_ids, (GFunc) g_free, NULL); - g_slist_free(td->noretweets_ids); + g_hash_table_unref(td->mutes_ids); + g_hash_table_unref(td->blocks_ids); + g_hash_table_unref(td->noretweets_ids); http_close(td->stream); twitter_filter_remove_all(ic); diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h index 8d17da58..bf47d4fc 100644 --- a/protocols/twitter/twitter.h +++ b/protocols/twitter/twitter.h @@ -60,10 +60,10 @@ struct twitter_data { guint64 timeline_id; GSList *follow_ids; - GSList *mutes_ids; - GSList *blocks_ids; - GSList *noretweets_ids; GSList *filters; + GHashTable *mutes_ids; + GHashTable *blocks_ids; + GHashTable *noretweets_ids; guint64 last_status_id; /* For undo */ gint main_loop_id; diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index e4cb7257..2a527cd5 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -390,6 +390,7 @@ static void twitter_http_get_mutes_ids(struct http_request *req) json_value *parsed; struct twitter_xml_list *txl; struct twitter_data *td; + GSList *elem; // Check if the connection is stil active if (!g_slist_find(twitter_connections, ic)) { @@ -409,20 +410,21 @@ static void twitter_http_get_mutes_ids(struct http_request *req) } txl = g_new0(struct twitter_xml_list, 1); - txl->list = td->mutes_ids; /* mute ids API response is similar enough to friends response to reuse this method */ twitter_xt_get_friends_id_list(parsed, txl); json_value_free(parsed); - td->mutes_ids = txl->list; + for (elem = txl->list; elem; elem = elem->next) { + g_hash_table_add(td->mutes_ids, elem->data); + } + if (txl->next_cursor) { /* Recurse while there are still more pages */ twitter_get_mutes_ids(ic, txl->next_cursor); } - txl->list = NULL; txl_free(txl); } @@ -435,6 +437,7 @@ static void twitter_http_get_blocks_ids(struct http_request *req) json_value *parsed; struct twitter_xml_list *txl; struct twitter_data *td; + GSList *elem; // Check if the connection is still active if (!g_slist_find(twitter_connections, ic)) { @@ -454,17 +457,18 @@ static void twitter_http_get_blocks_ids(struct http_request *req) } txl = g_new0(struct twitter_xml_list, 1); - txl->list = td->blocks_ids; twitter_xt_get_friends_id_list(parsed, txl); json_value_free(parsed); - td->blocks_ids = txl->list; + for (elem = txl->list; elem; elem = elem->next) { + g_hash_table_add(td->blocks_ids, elem->data); + } + if (txl->next_cursor) { twitter_get_blocks_ids(ic, txl->next_cursor); } - txl->list = NULL; txl_free(txl); } @@ -477,6 +481,7 @@ static void twitter_http_get_noretweets_ids(struct http_request *req) json_value *parsed; struct twitter_xml_list *txl; struct twitter_data *td; + GSList *elem; // Check if the connection is stil active if (!g_slist_find(twitter_connections, ic)) { @@ -496,7 +501,6 @@ static void twitter_http_get_noretweets_ids(struct http_request *req) } txl = g_new0(struct twitter_xml_list, 1); - txl->list = td->noretweets_ids; // Process the retweet ids txl->type = TXL_ID; @@ -512,10 +516,12 @@ static void twitter_http_get_noretweets_ids(struct http_request *req) } } + for (elem = txl->list; elem; elem = elem->next) { + g_hash_table_add(td->noretweets_ids, elem->data); + } + json_value_free(parsed); - td->noretweets_ids = txl->list; - txl->list = NULL; txl_free(txl); } @@ -1035,12 +1041,12 @@ static void twitter_status_show(struct im_connection *ic, struct twitter_xml_sta /* Check this is not a tweet that should be muted */ uid_str = g_strdup_printf("%" PRIu64, status->user->uid); - if (g_slist_find_custom(td->mutes_ids, uid_str, (GCompareFunc)strcmp) || - g_slist_find_custom(td->blocks_ids, uid_str, (GCompareFunc)strcmp)) { + if (g_hash_table_lookup(td->mutes_ids, uid_str) || + g_hash_table_lookup(td->blocks_ids, uid_str)) { g_free(uid_str); return; } - if (status->id != status->rt_id && g_slist_find_custom(td->noretweets_ids, uid_str, (GCompareFunc)strcmp)) { + if (status->id != status->rt_id && g_hash_table_lookup(td->noretweets_ids, uid_str)) { g_free(uid_str); return; } @@ -1162,7 +1168,7 @@ static gboolean twitter_stream_handle_object(struct im_connection *ic, json_valu (txs = twitter_xt_get_dm(c))) { if (g_strcasecmp(txs->user->screen_name, td->user) != 0) { char *uid_str = g_strdup_printf("%" PRIu64, txs->user->uid); - if (!g_slist_find_custom(td->blocks_ids, uid_str, (GCompareFunc)strcmp)) { + if (!g_hash_table_lookup(td->blocks_ids, uid_str)) { imcb_buddy_msg(ic, txs->user->screen_name, txs->text, 0, txs->created_at); } @@ -1239,30 +1245,20 @@ static gboolean twitter_stream_handle_event(struct im_connection *ic, json_value twitter_add_buddy(ic, ut->screen_name, ut->name); } } else if (strcmp(type, "block") == 0) { - GSList *found; char *uid_str; ut = twitter_xt_get_user(target); uid_str = g_strdup_printf("%" PRIu64, ut->uid); - if (!(found = g_slist_find_custom(td->blocks_ids, uid_str, - (GCompareFunc)strcmp))) { - td->blocks_ids = g_slist_prepend(td->blocks_ids, uid_str); - } + g_hash_table_add(td->blocks_ids, uid_str); twitter_log(ic, "Blocked user %s", ut->screen_name); if (getenv("BITLBEE_DEBUG")) { fprintf(stderr, "New block: %s %"PRIu64"\n", ut->screen_name, ut->uid); } } else if (strcmp(type, "unblock") == 0) { - GSList *found; char *uid_str; ut = twitter_xt_get_user(target); uid_str = g_strdup_printf("%" PRIu64, ut->uid); - if ((found = g_slist_find_custom(td->blocks_ids, uid_str, - (GCompareFunc)strcmp))) { - char *found_str = found->data; - td->blocks_ids = g_slist_delete_link(td->blocks_ids, found); - g_free(found_str); - } + g_hash_table_remove(td->blocks_ids, uid_str); g_free(uid_str); twitter_log(ic, "Unblocked user %s", ut->screen_name); if (getenv("BITLBEE_DEBUG")) { @@ -1270,30 +1266,20 @@ static gboolean twitter_stream_handle_event(struct im_connection *ic, json_value ut->screen_name, ut->uid); } } else if (strcmp(type, "mute") == 0) { - GSList *found; char *uid_str; ut = twitter_xt_get_user(target); uid_str = g_strdup_printf("%" PRIu64, ut->uid); - if (!(found = g_slist_find_custom(td->mutes_ids, uid_str, - (GCompareFunc)strcmp))) { - td->mutes_ids = g_slist_prepend(td->mutes_ids, uid_str); - } + g_hash_table_add(td->mutes_ids, uid_str); twitter_log(ic, "Muted user %s", ut->screen_name); if (getenv("BITLBEE_DEBUG")) { fprintf(stderr, "New mute: %s %"PRIu64"\n", ut->screen_name, ut->uid); } } else if (strcmp(type, "unmute") == 0) { - GSList *found; char *uid_str; ut = twitter_xt_get_user(target); uid_str = g_strdup_printf("%" PRIu64, ut->uid); - if ((found = g_slist_find_custom(td->mutes_ids, uid_str, - (GCompareFunc)strcmp))) { - char *found_str = found->data; - td->mutes_ids = g_slist_delete_link(td->mutes_ids, found); - g_free(found_str); - } + g_hash_table_remove(td->mutes_ids, uid_str); g_free(uid_str); twitter_log(ic, "Unmuted user %s", ut->screen_name); if (getenv("BITLBEE_DEBUG")) { |