Changeset fb62f132 for protocols/twitter


Ignore:
Timestamp:
2016-03-23T20:23:36Z (8 years ago)
Author:
Flexo <nick@…>
Branches:
master
Children:
9cf63ac
Parents:
d701547
git-author:
Flexo <nick@…> (15-03-16 21:39:36)
git-committer:
Flexo <nick@…> (23-03-16 20:23:36)
Message:

Honour twitter's mutes and "hide retweets from this user" settings.

Location:
protocols/twitter
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    rd701547 rfb62f132  
    345345                imcb_log(ic, "Getting contact list");
    346346                twitter_get_friends_ids(ic, -1);
     347                twitter_get_mutes_ids(ic, -1);
     348                twitter_get_noretweets_ids(ic, -1);
    347349        } else {
    348350                twitter_main_loop_start(ic);
  • protocols/twitter/twitter.h

    rd701547 rfb62f132  
    6161
    6262        GSList *follow_ids;
     63        GSList *mutes_ids;
     64        GSList *noretweets_ids;
    6365        GSList *filters;
    6466
  • protocols/twitter/twitter_lib.c

    rd701547 rfb62f132  
    240240
    241241static void twitter_http_get_friends_ids(struct http_request *req);
     242static void twitter_http_get_mutes_ids(struct http_request *req);
     243static void twitter_http_get_noretweets_ids(struct http_request *req);
    242244
    243245/**
     
    252254        args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor);
    253255        twitter_http(ic, TWITTER_FRIENDS_IDS_URL, twitter_http_get_friends_ids, ic, 0, args, 2);
     256
     257        g_free(args[1]);
     258}
     259
     260/**
     261 * Get the muted users ids.
     262 */
     263void twitter_get_mutes_ids(struct im_connection *ic, gint64 next_cursor)
     264{
     265        char *args[2];
     266
     267        args[0] = "cursor";
     268        args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor);
     269        twitter_http(ic, TWITTER_MUTES_IDS_URL, twitter_http_get_mutes_ids, ic, 0, args, 2);
     270
     271        g_free(args[1]);
     272}
     273
     274/**
     275 * Get the ids for users from whom we should ignore retweets.
     276 */
     277void twitter_get_noretweets_ids(struct im_connection *ic, gint64 next_cursor)
     278{
     279        char *args[2];
     280
     281        args[0] = "cursor";
     282        args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor);
     283        twitter_http(ic, TWITTER_NORETWEETS_IDS_URL, twitter_http_get_noretweets_ids, ic, 0, args, 2);
    254284
    255285        g_free(args[1]);
     
    332362                twitter_get_users_lookup(ic);
    333363        }
     364
     365        txl->list = NULL;
     366        txl_free(txl);
     367}
     368
     369/**
     370 * Callback for getting the mutes ids.
     371 */
     372static void twitter_http_get_mutes_ids(struct http_request *req)
     373{
     374        struct im_connection *ic = req->data;
     375        json_value *parsed;
     376        struct twitter_xml_list *txl;
     377        struct twitter_data *td;
     378
     379        // Check if the connection is stil active
     380        if (!g_slist_find(twitter_connections, ic)) {
     381                return;
     382        }
     383
     384        td = ic->proto_data;
     385
     386        // Parse the data.
     387        if (!(parsed = twitter_parse_response(ic, req))) {
     388                return;
     389        }
     390
     391        txl = g_new0(struct twitter_xml_list, 1);
     392        txl->list = td->mutes_ids;
     393
     394        /* mute ids API response is similar enough to friends response
     395           to reuse this method */
     396        twitter_xt_get_friends_id_list(parsed, txl);
     397        json_value_free(parsed);
     398
     399        td->mutes_ids = txl->list;
     400        if (txl->next_cursor) {
     401                /* Recurse while there are still more pages */
     402                twitter_get_mutes_ids(ic, txl->next_cursor);
     403        }
     404
     405        txl->list = NULL;
     406        txl_free(txl);
     407}
     408
     409/**
     410 * Callback for getting the no-retweets ids.
     411 */
     412static void twitter_http_get_noretweets_ids(struct http_request *req)
     413{
     414        struct im_connection *ic = req->data;
     415        json_value *parsed;
     416        struct twitter_xml_list *txl;
     417        struct twitter_data *td;
     418
     419        // Check if the connection is stil active
     420        if (!g_slist_find(twitter_connections, ic)) {
     421                return;
     422        }
     423
     424        td = ic->proto_data;
     425
     426        // Parse the data.
     427        if (!(parsed = twitter_parse_response(ic, req))) {
     428                return;
     429        }
     430
     431        txl = g_new0(struct twitter_xml_list, 1);
     432        txl->list = td->noretweets_ids;
     433       
     434        // Process the retweet ids
     435        txl->type = TXL_ID;
     436        if (parsed->type == json_array) {
     437                unsigned int i;
     438                for (i = 0; i < parsed->u.array.length; i++) {
     439                        json_value *c = parsed->u.array.values[i];
     440                        if (c->type != json_integer) {
     441                                continue;
     442                        }
     443                        txl->list = g_slist_prepend(txl->list,
     444                                                    g_strdup_printf("%"PRIu64, c->u.integer));
     445                }
     446        }
     447
     448        json_value_free(parsed);
     449        td->noretweets_ids = txl->list;
    334450
    335451        txl->list = NULL;
     
    831947        struct twitter_data *td = ic->proto_data;
    832948        char *last_id_str;
     949        char *uid_str;
    833950
    834951        if (status->user == NULL || status->text == NULL) {
     952                return;
     953        }
     954       
     955        /* Check this is not a tweet that should be muted */
     956        uid_str = g_strdup_printf("%" PRIu64, status->user->uid);
     957        if (g_slist_find_custom(td->mutes_ids, uid_str, (GCompareFunc)strcmp)) {
     958                g_free(uid_str);
     959                return;
     960        }
     961        if (status->id != status->rt_id && g_slist_find_custom(td->noretweets_ids, uid_str, (GCompareFunc)strcmp)) {
     962                g_free(uid_str);
    835963                return;
    836964        }
     
    857985        set_setstr(&ic->acc->set, "_last_tweet", last_id_str);
    858986        g_free(last_id_str);
     987        g_free(uid_str);
    859988}
    860989
  • protocols/twitter/twitter_lib.h

    rd701547 rfb62f132  
    6363#define TWITTER_FRIENDS_IDS_URL "/friends/ids.json"
    6464#define TWITTER_FOLLOWERS_IDS_URL "/followers/ids.json"
     65#define TWITTER_MUTES_IDS_URL "/mutes/users/ids.json"
     66#define TWITTER_NORETWEETS_IDS_URL "/friendships/no_retweets/ids.json"
    6567
    6668/* Account URLs */
     
    8789gboolean twitter_get_timeline(struct im_connection *ic, gint64 next_cursor);
    8890void twitter_get_friends_ids(struct im_connection *ic, gint64 next_cursor);
     91void twitter_get_mutes_ids(struct im_connection *ic, gint64 next_cursor);
     92void twitter_get_noretweets_ids(struct im_connection *ic, gint64 next_cursor);
    8993void twitter_get_statuses_friends(struct im_connection *ic, gint64 next_cursor);
    9094
Note: See TracChangeset for help on using the changeset viewer.