aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/twitter/twitter_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/twitter/twitter_lib.c')
-rw-r--r--protocols/twitter/twitter_lib.c60
1 files changed, 23 insertions, 37 deletions
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")) {