Ignore:
Timestamp:
2011-08-26T20:16:17Z (13 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
0fff0b2
Parents:
2322a9f
Message:

Since t.co is all over Twitter now, start parsing and showing entity
information. I'm going for this way of rendering even though full URLs are
also available to me because A) it puts me on the safe side wrt Twitter ToS
and B) some full URLS may really be very long.

Noticed some problem with truncated RT statuses not getting fixed but this
seems to be unrelated. (This is a truncated RT status without the
"truncated" property set.)

Bug #821.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    r2322a9f r429a9b1  
    499499                txs->text = g_strdup_printf("RT @%s: %s", rtxs->user->screen_name, rtxs->text);
    500500                txs_free(rtxs);
     501        } else {
     502                struct xt_node *urls, *url;
     503               
     504                urls = xt_find_path(node, "entities/urls");
     505                for (url = urls ? urls->children : NULL; url; url = url->next) {
     506                        /* "short" is a reserved word. :-P */
     507                        struct xt_node *kort = xt_find_node(url->children, "url");
     508                        struct xt_node *disp = xt_find_node(url->children, "display_url");
     509                        char *pos, *new;
     510                       
     511                        if (!kort || !kort->text || !disp || !disp->text ||
     512                            !(pos = strstr(txs->text, kort->text)))
     513                                continue;
     514                       
     515                        *pos = '\0';
     516                        new = g_strdup_printf("%s%s &lt;%s&gt;%s", txs->text, kort->text,
     517                                              disp->text, pos + strlen(kort->text));
     518                       
     519                        g_free(txs->text);
     520                        txs->text = new;
     521                }
    501522        }
    502523
     
    788809        td->flags &= ~TWITTER_GOT_TIMELINE;
    789810
    790         char *args[4];
     811        char *args[6];
    791812        args[0] = "cursor";
    792813        args[1] = g_strdup_printf("%lld", (long long) next_cursor);
     814        args[2] = "include_entities";
     815        args[3] = "true";
    793816        if (td->timeline_id) {
    794                 args[2] = "since_id";
    795                 args[3] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id);
     817                args[4] = "since_id";
     818                args[5] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id);
    796819        }
    797820
    798821        twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args,
    799                      td->timeline_id ? 4 : 2);
     822                     td->timeline_id ? 6 : 4);
    800823
    801824        g_free(args[1]);
    802825        if (td->timeline_id) {
    803                 g_free(args[3]);
     826                g_free(args[5]);
    804827        }
    805828}
     
    815838        td->flags &= ~TWITTER_GOT_MENTIONS;
    816839
    817         char *args[4];
     840        char *args[6];
    818841        args[0] = "cursor";
    819842        args[1] = g_strdup_printf("%lld", (long long) next_cursor);
     843        args[2] = "include_entities";
     844        args[3] = "true";
    820845        if (td->timeline_id) {
    821                 args[2] = "since_id";
    822                 args[3] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id);
     846                args[4] = "since_id";
     847                args[5] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id);
    823848        }
    824849
    825850        twitter_http(ic, TWITTER_MENTIONS_URL, twitter_http_get_mentions, ic, 0, args,
    826                      td->timeline_id ? 4 : 2);
     851                     td->timeline_id ? 6 : 4);
    827852
    828853        g_free(args[1]);
    829854        if (td->timeline_id) {
    830                 g_free(args[3]);
     855                g_free(args[5]);
    831856        }
    832857}
Note: See TracChangeset for help on using the changeset viewer.