diff options
author | dequis <dx@dxzone.com.ar> | 2016-10-02 21:56:35 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2016-10-02 21:56:35 -0300 |
commit | 58d285a4eec4f921be9de3c51341ef3d8729a999 (patch) | |
tree | c20c52d714ebd75867de4828c81af982132686fa /protocols | |
parent | 82e55d202f8152c25b8daa48d1960eede3eee312 (diff) |
twitter: fix quoted tweet expansion in extended tweets
The outermost entities object only contains the url of the compat tweet,
the one linking to /i/web/status/[...]
The inner entities object, inside the "extended_tweet", is the one that
contains the quoted tweet url that we're supposed to replace.
But expand_entities() assumed that the quoted_status object would be
next to entities, which doesn't apply in the case of extended tweets.
So now it gets an extra parameter to look for entities.
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/twitter/twitter_lib.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index ad019e1d..c66c1d89 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -586,7 +586,7 @@ static gboolean twitter_xt_get_users(json_value *node, struct twitter_xml_list * #define TWITTER_TIME_FORMAT "%a %b %d %H:%M:%S +0000 %Y" #endif -static void expand_entities(char **text, const json_value *node); +static void expand_entities(char **text, const json_value *node, const json_value *extended_node); /** * Function to fill a twitter_xml_status struct. @@ -601,6 +601,7 @@ static struct twitter_xml_status *twitter_xt_get_status(const json_value *node) struct twitter_xml_status *txs = {0}; const json_value *rt = NULL; const json_value *text_value = NULL; + const json_value *extended_node = NULL; if (node->type != json_object) { return FALSE; @@ -614,6 +615,7 @@ static struct twitter_xml_status *twitter_xt_get_status(const json_value *node) text_value = v; } else if (strcmp("extended_tweet", k) == 0 && v->type == json_object) { text_value = json_o_get(v, "full_text"); + extended_node = v; } else if (strcmp("retweeted_status", k) == 0 && v->type == json_object) { rt = v; } else if (strcmp("created_at", k) == 0 && v->type == json_string) { @@ -646,7 +648,7 @@ static struct twitter_xml_status *twitter_xt_get_status(const json_value *node) } else if (text_value && text_value->type == json_string) { txs->text = g_memdup(text_value->u.string.ptr, text_value->u.string.length + 1); strip_html(txs->text); - expand_entities(&txs->text, node); + expand_entities(&txs->text, node, extended_node); } if (txs->text && txs->user && txs->id) { @@ -689,7 +691,7 @@ static struct twitter_xml_status *twitter_xt_get_dm(const json_value *node) } } - expand_entities(&txs->text, node); + expand_entities(&txs->text, node, NULL); if (txs->text && txs->user && txs->id) { return txs; @@ -699,9 +701,9 @@ static struct twitter_xml_status *twitter_xt_get_dm(const json_value *node) return NULL; } -static void expand_entities(char **text, const json_value *node) +static void expand_entities(char **text, const json_value *node, const json_value *extended_node) { - json_value *entities, *quoted; + json_value *entities, *extended_entities, *quoted; char *quote_url = NULL, *quote_text = NULL; if (!((entities = json_o_get(node, "entities")) && entities->type == json_object)) @@ -719,6 +721,13 @@ static void expand_entities(char **text, const json_value *node) quoted = NULL; } + if (extended_node) { + extended_entities = json_o_get(extended_node, "entities"); + if (extended_entities && extended_entities->type == json_object) { + entities = extended_entities; + } + } + JSON_O_FOREACH(entities, k, v) { int i; |