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.c104
1 files changed, 103 insertions, 1 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index 011c31ab..0201aff2 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -240,6 +240,7 @@ static json_value *twitter_parse_response(struct im_connection *ic, struct http_
static void twitter_http_get_friends_ids(struct http_request *req);
static void twitter_http_get_mutes_ids(struct http_request *req);
+static void twitter_http_get_blocks_ids(struct http_request *req);
static void twitter_http_get_noretweets_ids(struct http_request *req);
/**
@@ -272,6 +273,20 @@ void twitter_get_mutes_ids(struct im_connection *ic, gint64 next_cursor)
}
/**
+ * Get the blocked users ids.
+ */
+void twitter_get_blocks_ids(struct im_connection *ic, gint64 next_cursor)
+{
+ char *args[2];
+
+ args[0] = "cursor";
+ args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor);
+ twitter_http(ic, TWITTER_BLOCKS_IDS_URL, twitter_http_get_blocks_ids, ic, 0, args, 2);
+
+ g_free(args[1]);
+}
+
+/**
* Get the ids for users from whom we should ignore retweets.
*/
void twitter_get_noretweets_ids(struct im_connection *ic, gint64 next_cursor)
@@ -412,6 +427,48 @@ static void twitter_http_get_mutes_ids(struct http_request *req)
}
/**
+ * 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;
+
+ // 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);
+ txl->list = td->blocks_ids;
+
+ twitter_xt_get_friends_id_list(parsed, txl);
+ json_value_free(parsed);
+
+ td->blocks_ids = txl->list;
+ if (txl->next_cursor) {
+ twitter_get_blocks_ids(ic, txl->next_cursor);
+ }
+
+ txl->list = NULL;
+ txl_free(txl);
+}
+
+/**
* Callback for getting the no-retweets ids.
*/
static void twitter_http_get_noretweets_ids(struct http_request *req)
@@ -978,7 +1035,8 @@ 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)) {
+ if (g_slist_find_custom(td->mutes_ids, uid_str, (GCompareFunc)strcmp) ||
+ g_slist_find_custom(td->blocks_ids, uid_str, (GCompareFunc)strcmp)) {
g_free(uid_str);
return;
}
@@ -1176,6 +1234,37 @@ 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) {
+ 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);
+ }
+ 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_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) {
GSList *found;
char *uid_str;
@@ -1743,6 +1832,19 @@ void twitter_mute_create_destroy(struct im_connection *ic, char *who, int create
}
/**
+ * Block or unblock a user
+ */
+void twitter_block_create_destroy(struct im_connection *ic, char *who, int create)
+{
+ char *args[2];
+
+ args[0] = "screen_name";
+ args[1] = who;
+ twitter_http(ic, create ? TWITTER_BLOCKS_CREATE_URL : TWITTER_BLOCKS_DESTROY_URL,
+ twitter_http_post, ic, 1, args, 2);
+}
+
+/**
* Enable or disable retweets for user
*/
void twitter_retweet_enable_disable(struct im_connection *ic, char *who, int enable)