Bug 1275284 - Display extended tweets. r=clokep, a=rkent
--- a/chat/protocols/twitter/twitter.js
+++ b/chat/protocols/twitter/twitter.js
@@ -225,60 +225,81 @@ Conversation.prototype = {
if (error)
error = "(" + error + ")";
} catch(e) {}
return error;
},
parseTweet: function(aTweet) {
let text = aTweet.text;
let entities = {};
+
// Handle retweets: retweeted_status contains the object for the original
// tweet that is being retweeted.
// If the retweet prefix ("RT @<username>: ") causes the tweet to be over
// 140 characters, ellipses will be added. In this case, we want to get
// the FULL text from the original tweet and update the entities to match.
// Note: the truncated flag is not always set correctly by twitter, so we
// always make use of the original tweet.
if ("retweeted_status" in aTweet) {
let retweet = aTweet["retweeted_status"];
+ let retweetText, retweetEntities = {};
+
+ if ("extended_tweet" in retweet) {
+ // Note that if an extended tweet is retweeted, only the
+ // retweeted_status part will be extended, not the tweet itself.
+ let extended = retweet.extended_tweet;
+ retweetText = extended.full_text;
+ if ("entities" in extended)
+ retweetEntities = extended.entities;
+ }
+ else {
+ retweetText = retweet.text;
+ if ("entities" in retweet)
+ retweetEntities = retweet.entities;
+ }
+
// We're going to take portions of the retweeted status and replace parts
// of the original tweet, the retweeted status prepends the original
// status with "RT @<username>: ", we need to keep the prefix.
let offset = text.indexOf(": ") + 2;
- text = text.slice(0, offset) + retweet.text;
+ text = text.slice(0, offset) + retweetText;
// Keep any entities that refer to the prefix (we can refer directly to
// aTweet for these since they are not edited).
if ("entities" in aTweet) {
for (let type in aTweet.entities) {
let filteredEntities =
aTweet.entities[type].filter(e => e.indices[0] < offset);
if (filteredEntities.length)
entities[type] = filteredEntities;
}
}
// Add the entities from the retweet (a copy of these must be made since
// they will be edited and we do not wish to change aTweet).
- if ("entities" in retweet) {
- for (let type in retweet.entities) {
- if (!(type in entities))
- entities[type] = [];
+ for (let type in retweetEntities) {
+ if (!(type in entities))
+ entities[type] = [];
- // Append the entities from the original status.
- entities[type] = entities[type].concat(
- retweet.entities[type].map(function(aEntity) {
- let entity = Object.create(aEntity);
- // Add the offset to the indices to account for the prefix.
- entity.indices = entity.indices.map(i => i + offset);
- return entity;
- })
- );
- }
- }
+ // Append the entities from the original status.
+ entities[type] = entities[type].concat(
+ retweetEntities[type].map(function(aEntity) {
+ let entity = Object.create(aEntity);
+ // Add the offset to the indices to account for the prefix.
+ entity.indices = entity.indices.map(i => i + offset);
+ return entity;
+ })
+ );
+ }
+ } else if ("extended_tweet" in aTweet) {
+ // Bare bones extended tweet handling.
+ let extended = aTweet.extended_tweet;
+ text = extended.full_text;
+ if ("entities" in extended)
+ entities = extended.entities;
} else {
// For non-retweets, we just want to use the entities that are given.
if ("entities" in aTweet)
entities = aTweet.entities;
}
this._account.LOG("Tweet: " + text);