Bug 1213908 - Add user icons to twitter participants. r=clokep
authoraleth <aleth@instantbird.org>
Fri, 30 Oct 2015 00:11:48 +0100
changeset 18533 29fdfd7d6ee1363a40760fa3f6edfa18fa345401
parent 18532 3231b63d0267c8e5e1a4720157c7dbfcf17e4537
child 18534 ced21c95ce612c7f093de3418afe2a97a301c8ec
push id11347
push useraleth@instantbird.org
push dateThu, 29 Oct 2015 23:19:07 +0000
treeherdercomm-central@ced21c95ce61 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
bugs1213908
Bug 1213908 - Add user icons to twitter participants. r=clokep
chat/protocols/twitter/twitter.js
--- a/chat/protocols/twitter/twitter.js
+++ b/chat/protocols/twitter/twitter.js
@@ -16,20 +16,33 @@ var kMaxMessageLength = 140;
 XPCOMUtils.defineLazyGetter(this, "_", () =>
   l10nHelper("chrome://chat/locale/twitter.properties")
 );
 XPCOMUtils.defineLazyGetter(this, "_lang", () =>
   l10nHelper("chrome://global/locale/languageNames.properties")
 );
 initLogModule("twitter", this);
 
-function ChatBuddy(aName) {
+function ChatBuddy(aName, aAccount) {
   this._name = aName;
+  this._account = aAccount;
 }
-ChatBuddy.prototype = GenericConvChatBuddyPrototype;
+ChatBuddy.prototype = {
+  __proto__: GenericConvChatBuddyPrototype,
+  get buddyIconFilename() {
+    let userInfo = this._account._userInfo.get(this.name);
+    if (userInfo)
+      return userInfo.profile_image_url;
+    return undefined;
+  },
+  set buddyIconFilename(aName) {
+    // Prevent accidental removal of the getter.
+    throw("Don't set chatBuddy.buddyIconFilename directly for Twitter.");
+  }
+}
 
 function Tweet(aTweet, aWho, aMessage, aObject)
 {
   this._tweet = aTweet;
   this._init(aWho, aMessage, aObject);
 }
 Tweet.prototype = {
   __proto__: GenericMessagePrototype,
@@ -341,17 +354,17 @@ Conversation.prototype = {
       flags.containsNick = true;
 
     (new Tweet(aTweet, name, text, flags)).conversation = this;
   },
   _ensureParticipantExists: function(aNick) {
     if (this._participants.has(aNick))
       return;
 
-    let chatBuddy = new ChatBuddy(aNick);
+    let chatBuddy = new ChatBuddy(aNick, this._account);
     this._participants.set(aNick, chatBuddy);
     this.notifyObservers(new nsSimpleEnumerator([chatBuddy]),
                          "chat-buddy-add");
   },
   get name() { return this.nick + " timeline"; },
   get title() { return _("timeline", this.nick); },
   get nick() { return this._account.name; },
   set nick(aNick) {},
@@ -1053,16 +1066,18 @@ Account.prototype = {
       if (Object.prototype.hasOwnProperty.call(userInfo, field) &&
           userInfo[field]) {
         let value = userInfo[field];
         if (kFields[field])
           value = kFields[field](value);
         tooltipInfo.push(new TooltipInfo(_("tooltip." + field), value));
       }
     }
+    tooltipInfo.push(new TooltipInfo(null, userInfo.profile_image_url,
+                                     Ci.prplITooltipInfo.icon));
 
     Services.obs.notifyObservers(new nsSimpleEnumerator(tooltipInfo),
                                  "user-info-received", aBuddyName);
   },
 
   // Handle the full user info for each received friend. Set the user info and
   // create the participant.
   onLookupReceived: function(aData) {