diff options
-rw-r--r-- | protocols/twitter/twitter.c | 2 | ||||
-rw-r--r-- | protocols/twitter/twitter.h | 2 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.c | 129 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.h | 4 |
4 files changed, 137 insertions, 0 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 7c96e9c3..94c88b71 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -344,6 +344,8 @@ void twitter_login_finish(struct im_connection *ic) !(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_noretweets_ids(ic, -1); } else { twitter_main_loop_start(ic); } diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h index 5a1a4f63..86c88262 100644 --- a/protocols/twitter/twitter.h +++ b/protocols/twitter/twitter.h @@ -60,6 +60,8 @@ struct twitter_data { guint64 timeline_id; GSList *follow_ids; + GSList *mutes_ids; + GSList *noretweets_ids; GSList *filters; guint64 last_status_id; /* For undo */ diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index 80747015..288e0207 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -239,6 +239,8 @@ 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_noretweets_ids(struct http_request *req); /** * Get the friends ids. @@ -256,6 +258,34 @@ void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor) } /** + * Get the muted users ids. + */ +void twitter_get_mutes_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_MUTES_IDS_URL, twitter_http_get_mutes_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) +{ + char *args[2]; + + args[0] = "cursor"; + args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor); + twitter_http(ic, TWITTER_NORETWEETS_IDS_URL, twitter_http_get_noretweets_ids, ic, 0, args, 2); + + g_free(args[1]); +} + +/** * Fill a list of ids. */ static gboolean twitter_xt_get_friends_id_list(json_value *node, struct twitter_xml_list *txl) @@ -336,6 +366,92 @@ static void twitter_http_get_friends_ids(struct http_request *req) txl_free(txl); } +/** + * Callback for getting the mutes ids. + */ +static void twitter_http_get_mutes_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 stil active + if (!g_slist_find(twitter_connections, ic)) { + return; + } + + td = ic->proto_data; + + // Parse the data. + if (!(parsed = twitter_parse_response(ic, req))) { + return; + } + + 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; + 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); +} + +/** + * Callback for getting the no-retweets ids. + */ +static void twitter_http_get_noretweets_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 stil active + if (!g_slist_find(twitter_connections, ic)) { + return; + } + + td = ic->proto_data; + + // Parse the data. + if (!(parsed = twitter_parse_response(ic, req))) { + return; + } + + txl = g_new0(struct twitter_xml_list, 1); + txl->list = td->noretweets_ids; + + // Process the retweet ids + txl->type = TXL_ID; + if (parsed->type == json_array) { + unsigned int i; + for (i = 0; i < parsed->u.array.length; i++) { + json_value *c = parsed->u.array.values[i]; + if (c->type != json_integer) { + continue; + } + txl->list = g_slist_prepend(txl->list, + g_strdup_printf("%"PRIu64, c->u.integer)); + } + } + + json_value_free(parsed); + td->noretweets_ids = txl->list; + + txl->list = NULL; + txl_free(txl); +} + static gboolean twitter_xt_get_users(json_value *node, struct twitter_xml_list *txl); static void twitter_http_get_users_lookup(struct http_request *req); @@ -830,10 +946,22 @@ static void twitter_status_show(struct im_connection *ic, struct twitter_xml_sta { struct twitter_data *td = ic->proto_data; char *last_id_str; + char *uid_str; if (status->user == NULL || status->text == NULL) { return; } + + /* 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_free(uid_str); + return; + } + if (status->id != status->rt_id && g_slist_find_custom(td->noretweets_ids, uid_str, (GCompareFunc)strcmp)) { + g_free(uid_str); + return; + } /* Grrrr. Would like to do this during parsing, but can't access settings from there. */ @@ -856,6 +984,7 @@ static void twitter_status_show(struct im_connection *ic, struct twitter_xml_sta last_id_str = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id); set_setstr(&ic->acc->set, "_last_tweet", last_id_str); g_free(last_id_str); + g_free(uid_str); } static gboolean twitter_stream_handle_object(struct im_connection *ic, json_value *o, gboolean from_filter); diff --git a/protocols/twitter/twitter_lib.h b/protocols/twitter/twitter_lib.h index 002376b1..44f20cbc 100644 --- a/protocols/twitter/twitter_lib.h +++ b/protocols/twitter/twitter_lib.h @@ -62,6 +62,8 @@ /* Social graphs URLs */ #define TWITTER_FRIENDS_IDS_URL "/friends/ids.json" #define TWITTER_FOLLOWERS_IDS_URL "/followers/ids.json" +#define TWITTER_MUTES_IDS_URL "/mutes/users/ids.json" +#define TWITTER_NORETWEETS_IDS_URL "/friendships/no_retweets/ids.json" /* Account URLs */ #define TWITTER_ACCOUNT_RATE_LIMIT_URL "/account/rate_limit_status.json" @@ -86,6 +88,8 @@ gboolean twitter_open_stream(struct im_connection *ic); gboolean twitter_open_filter_stream(struct im_connection *ic); gboolean twitter_get_timeline(struct im_connection *ic, gint64 next_cursor); void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor); +void twitter_get_mutes_ids(struct im_connection *ic, gint64 next_cursor); +void twitter_get_noretweets_ids(struct im_connection *ic, gint64 next_cursor); void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor); void twitter_post_status(struct im_connection *ic, char *msg, guint64 in_reply_to); |