Bug 1275284 - Display extended tweets. r=clokep
authoraleth <aleth@instantbird.org>
Wed, 28 Sep 2016 00:15:09 +0200
changeset 25690 d4134a1be965e2c002454d4341f2a89098c7dc43
parent 25689 cba8e63b8bd77be765549d52ef0a3b0a956b5e37
child 25691 75e7b63716981dfdb764f36dc83fd2fbb28ff3ee
push id1744
push useraleth@instantbird.org
push dateSun, 16 Oct 2016 20:14:08 +0000
treeherdercomm-beta@88269bbc6b03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
bugs1275284
Bug 1275284 - Display extended tweets. r=clokep
chat/protocols/twitter/twitter.js
--- a/chat/protocols/twitter/twitter.js
+++ b/chat/protocols/twitter/twitter.js
@@ -229,60 +229,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;
     }
 
     if (Object.keys(entities).length) {
       /* entArray is an array of entities ready to be replaced in the tweet,