Changeset ad54149


Ignore:
Timestamp:
2016-09-21T03:03:15Z (8 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
524e931
Parents:
35401cd
git-author:
dequis <dx@…> (21-09-16 00:53:40)
git-committer:
dequis <dx@…> (21-09-16 03:03:15)
Message:

twitter: extended tweet support (AKA avoid showing truncated ones)

Documentation over here:

https://dev.twitter.com/overview/api/upcoming-changes-to-tweets

This is already live in twitter, can be tested by including an
attachment from twitter web and then fill 140 characters.

Should be sanely backwards compatible with twitter clones - i'd expect
them to ignore the tweet_mode=extended parameter in REST queries, and
just not deliver extended_tweet objects / full_text strings at all.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    r35401cd rad54149  
    599599static struct twitter_xml_status *twitter_xt_get_status(const json_value *node)
    600600{
    601         struct twitter_xml_status *txs;
     601        struct twitter_xml_status *txs = {0};
    602602        const json_value *rt = NULL;
     603        const json_value *text_value = NULL;
    603604
    604605        if (node->type != json_object) {
     
    608609
    609610        JSON_O_FOREACH(node, k, v) {
    610                 if (strcmp("text", k) == 0 && v->type == json_string) {
    611                         txs->text = g_memdup(v->u.string.ptr, v->u.string.length + 1);
    612                         strip_html(txs->text);
     611                if (strcmp("text", k) == 0 && v->type == json_string && text_value == NULL) {
     612                        text_value = v;
     613                } else if (strcmp("full_text", k) == 0 && v->type == json_string) {
     614                        text_value = v;
     615                } else if (strcmp("extended_tweet", k) == 0 && v->type == json_object) {
     616                        text_value = json_o_get(v, "full_text");
    613617                } else if (strcmp("retweeted_status", k) == 0 && v->type == json_object) {
    614618                        rt = v;
     
    636640                struct twitter_xml_status *rtxs = twitter_xt_get_status(rt);
    637641                if (rtxs) {
    638                         g_free(txs->text);
    639642                        txs->text = g_strdup_printf("RT @%s: %s", rtxs->user->screen_name, rtxs->text);
    640643                        txs->id = rtxs->id;
    641644                        txs_free(rtxs);
    642645                }
    643         } else {
     646        } else if (text_value && text_value->type == json_string) {
     647                txs->text = g_memdup(text_value->u.string.ptr, text_value->u.string.length + 1);
     648                strip_html(txs->text);
    644649                expand_entities(&txs->text, node);
    645650        }
     
    14791484        td->flags &= ~TWITTER_GOT_TIMELINE;
    14801485
    1481         char *args[6];
     1486        char *args[8];
    14821487        args[0] = "cursor";
    14831488        args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor);
    14841489        args[2] = "include_entities";
    14851490        args[3] = "true";
     1491        args[4] = "tweet_mode";
     1492        args[5] = "extended";
    14861493        if (td->timeline_id) {
    1487                 args[4] = "since_id";
    1488                 args[5] = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id);
     1494                args[6] = "since_id";
     1495                args[7] = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id);
    14891496        }
    14901497
    14911498        if (twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args,
    1492                          td->timeline_id ? 6 : 4) == NULL) {
     1499                         td->timeline_id ? 8 : 6) == NULL) {
    14931500                if (++td->http_fails >= 5) {
    14941501                        imcb_error(ic, "Could not retrieve %s: %s",
     
    15011508        g_free(args[1]);
    15021509        if (td->timeline_id) {
    1503                 g_free(args[5]);
     1510                g_free(args[7]);
    15041511        }
    15051512}
     
    15161523        td->flags &= ~TWITTER_GOT_MENTIONS;
    15171524
    1518         char *args[6];
     1525        char *args[8];
    15191526        args[0] = "cursor";
    15201527        args[1] = g_strdup_printf("%" G_GINT64_FORMAT, next_cursor);
     
    15281535                args[5] = g_strdup_printf("%d", set_getint(&ic->acc->set, "show_old_mentions"));
    15291536        }
     1537        args[6] = "tweet_mode";
     1538        args[7] = "extended";
    15301539
    15311540        if (twitter_http(ic, TWITTER_MENTIONS_URL, twitter_http_get_mentions,
    1532                          ic, 0, args, 6) == NULL) {
     1541                         ic, 0, args, 8) == NULL) {
    15331542                if (++td->http_fails >= 5) {
    15341543                        imcb_error(ic, "Could not retrieve %s: %s",
Note: See TracChangeset for help on using the changeset viewer.