aboutsummaryrefslogtreecommitdiffstats
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/twitter/twitter_lib.c93
1 files changed, 25 insertions, 68 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index 2a527cd5..0750e135 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -382,9 +382,9 @@ static void twitter_http_get_friends_ids(struct http_request *req)
}
/**
- * Callback for getting the mutes ids.
+ * Callback for getting the blocks and mutes ids.
*/
-static void twitter_http_get_mutes_ids(struct http_request *req)
+static void twitter_http_get_mutes_blocks_ids(struct http_request *req, int blocks)
{
struct im_connection *ic = req->data;
json_value *parsed;
@@ -417,59 +417,35 @@ static void twitter_http_get_mutes_ids(struct http_request *req)
json_value_free(parsed);
for (elem = txl->list; elem; elem = elem->next) {
- g_hash_table_add(td->mutes_ids, elem->data);
+ g_hash_table_add(blocks ? td->blocks_ids : td->mutes_ids, elem->data);
}
if (txl->next_cursor) {
/* Recurse while there are still more pages */
- twitter_get_mutes_ids(ic, txl->next_cursor);
+ if (blocks) {
+ twitter_get_blocks_ids(ic, txl->next_cursor);
+ } else {
+ twitter_get_mutes_ids(ic, txl->next_cursor);
+ }
}
txl_free(txl);
}
/**
+ * Callback for getting the mutes ids.
+ */
+static void twitter_http_get_mutes_ids(struct http_request *req)
+{
+ twitter_http_get_mutes_blocks_ids(req, 0);
+}
+
+/**
* Callback for getting the blocks ids.
*/
static void twitter_http_get_blocks_ids(struct http_request *req)
{
- struct im_connection *ic = req->data;
- 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)) {
- return;
- }
-
- td = ic->proto_data;
-
- if (req->status_code != 200) {
- /* Fail silently */
- return;
- }
-
- // Parse the data.
- if (!(parsed = twitter_parse_response(ic, req))) {
- return;
- }
-
- txl = g_new0(struct twitter_xml_list, 1);
-
- twitter_xt_get_friends_id_list(parsed, txl);
- json_value_free(parsed);
-
- 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_free(txl);
+ twitter_http_get_mutes_blocks_ids(req, 1);
}
/**
@@ -1244,44 +1220,25 @@ static gboolean twitter_stream_handle_event(struct im_connection *ic, json_value
if (g_strcasecmp(us->screen_name, td->user) == 0) {
twitter_add_buddy(ic, ut->screen_name, ut->name);
}
- } else if (strcmp(type, "block") == 0) {
- char *uid_str;
- ut = twitter_xt_get_user(target);
- uid_str = g_strdup_printf("%" PRIu64, ut->uid);
- 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) {
- char *uid_str;
- ut = twitter_xt_get_user(target);
- uid_str = g_strdup_printf("%" PRIu64, ut->uid);
- 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")) {
- fprintf(stderr, "New unblock: %s %"PRIu64"\n",
- ut->screen_name, ut->uid);
- }
- } else if (strcmp(type, "mute") == 0) {
+ } else if (strcmp(type, "mute") == 0 || strcmp(type, "block") == 0) {
char *uid_str;
+ int mute = strcmp(type, "mute") == 0;
ut = twitter_xt_get_user(target);
uid_str = g_strdup_printf("%" PRIu64, ut->uid);
- g_hash_table_add(td->mutes_ids, uid_str);
- twitter_log(ic, "Muted user %s", ut->screen_name);
+ g_hash_table_add(mute ? td->mutes_ids : td->blocks_ids, uid_str);
+ twitter_log(ic, "%s user %s", mute ? "Muted" : "Blocked", 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) {
+ } else if (strcmp(type, "unmute") == 0 || strcmp(type, "unblock") == 0) {
char *uid_str;
+ int unmute = strcmp(type, "unmute") == 0;
ut = twitter_xt_get_user(target);
uid_str = g_strdup_printf("%" PRIu64, ut->uid);
- g_hash_table_remove(td->mutes_ids, uid_str);
+ g_hash_table_remove(unmute ? td->mutes_ids : td->blocks_ids, uid_str);
g_free(uid_str);
- twitter_log(ic, "Unmuted user %s", ut->screen_name);
+ twitter_log(ic, "%s user %s", unmute ? "Unmuted" : "Blocked", ut->screen_name);
if (getenv("BITLBEE_DEBUG")) {
fprintf(stderr, "New unmute: %s %"PRIu64"\n",
ut->screen_name, ut->uid);