aboutsummaryrefslogtreecommitdiffstats
path: root/protocols
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2011-08-26 22:16:17 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2011-08-26 22:16:17 +0200
commit429a9b17fb256e5fc750104f4c5ffb2dc7fba74b (patch)
treed1e55eb2f3b17d32899c8982e832acb5fb5565e4 /protocols
parent2322a9f38a2f6c9bf86eb62c2cd68fd3848b694f (diff)
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.
Diffstat (limited to 'protocols')
-rw-r--r--protocols/twitter/twitter_lib.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index 805ff5aa..7f2fb811 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -498,6 +498,27 @@ static xt_status twitter_xt_get_status(struct xt_node *node, struct twitter_xml_
g_free(txs->text);
txs->text = g_strdup_printf("RT @%s: %s", rtxs->user->screen_name, rtxs->text);
txs_free(rtxs);
+ } else {
+ struct xt_node *urls, *url;
+
+ urls = xt_find_path(node, "entities/urls");
+ for (url = urls ? urls->children : NULL; url; url = url->next) {
+ /* "short" is a reserved word. :-P */
+ struct xt_node *kort = xt_find_node(url->children, "url");
+ struct xt_node *disp = xt_find_node(url->children, "display_url");
+ char *pos, *new;
+
+ if (!kort || !kort->text || !disp || !disp->text ||
+ !(pos = strstr(txs->text, kort->text)))
+ continue;
+
+ *pos = '\0';
+ new = g_strdup_printf("%s%s &lt;%s&gt;%s", txs->text, kort->text,
+ disp->text, pos + strlen(kort->text));
+
+ g_free(txs->text);
+ txs->text = new;
+ }
}
return XT_HANDLED;
@@ -787,20 +808,22 @@ void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
td->home_timeline_obj = NULL;
td->flags &= ~TWITTER_GOT_TIMELINE;
- char *args[4];
+ char *args[6];
args[0] = "cursor";
args[1] = g_strdup_printf("%lld", (long long) next_cursor);
+ args[2] = "include_entities";
+ args[3] = "true";
if (td->timeline_id) {
- args[2] = "since_id";
- args[3] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id);
+ args[4] = "since_id";
+ args[5] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id);
}
twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args,
- td->timeline_id ? 4 : 2);
+ td->timeline_id ? 6 : 4);
g_free(args[1]);
if (td->timeline_id) {
- g_free(args[3]);
+ g_free(args[5]);
}
}
@@ -814,20 +837,22 @@ void twitter_get_mentions(struct im_connection *ic, gint64 next_cursor)
td->mentions_obj = NULL;
td->flags &= ~TWITTER_GOT_MENTIONS;
- char *args[4];
+ char *args[6];
args[0] = "cursor";
args[1] = g_strdup_printf("%lld", (long long) next_cursor);
+ args[2] = "include_entities";
+ args[3] = "true";
if (td->timeline_id) {
- args[2] = "since_id";
- args[3] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id);
+ args[4] = "since_id";
+ args[5] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id);
}
twitter_http(ic, TWITTER_MENTIONS_URL, twitter_http_get_mentions, ic, 0, args,
- td->timeline_id ? 4 : 2);
+ td->timeline_id ? 6 : 4);
g_free(args[1]);
if (td->timeline_id) {
- g_free(args[3]);
+ g_free(args[5]);
}
}