Bug 1592422 - Fixed chat-tooltips no longer show avatars. r=mkmelin
authorKhushil Mistry <khushil324@gmail.com>
Wed, 18 Dec 2019 07:42:41 +0200
changeset 37770 2e35cc63542c54351208c96013e7bbd3cfa7342b
parent 37769 13f0d32f30288b96cd7dd7c79dc844675e4e8fcb
child 37771 52d423a8101275328230384a5c5158203b285c79
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
reviewersmkmelin
bugs1592422
Bug 1592422 - Fixed chat-tooltips no longer show avatars. r=mkmelin
chat/content/chat-tooltip.js
--- a/chat/content/chat-tooltip.js
+++ b/chat/content/chat-tooltip.js
@@ -184,17 +184,17 @@
       if (this.delayConnectedCallback()) {
         return;
       }
       this.textContent = "";
       this.appendChild(
         MozXULElement.parseXULToFragment(`
           <vbox class="largeTooltip">
             <hbox align="start" crop="end" flex="1">
-              <vbox flex="1">
+              <vbox>
                 <stack>
                   <!-- The box around the user icon is a workaround for bug 955673. -->
                   <box class="userIconHolder">
                     <image class="userIcon"></image>
                   </box>
                   <image class="statusTypeIcon status"></image>
                 </stack>
                 <spacer flex="1"></spacer>
@@ -202,17 +202,17 @@
               <stack class="displayNameMessageBox" flex="1">
                 <vbox flex="1">
                   <hbox align="start" flex="1">
                     <description class="tooltipDisplayName" flex="1" crop="end"></description>
                     <image class="tooltipProtoIcon status"></image>
                   </hbox>
                   <spacer flex="1"></spacer>
                 </vbox>
-                <description class="tooltipMessage"></description>
+                <description class="tooltipMessage" crop="end"></description>
               </stack>
             </hbox>
             <html:table class="tooltipTable">
             </html:table>
           </vbox>
         `)
       );
       this.initializeAttributeInheritance();
@@ -247,29 +247,19 @@
 
     get table() {
       if (!("_table" in this)) {
         this._table = this.querySelector(".tooltipTable");
       }
       return this._table;
     }
 
-    setBuddyIcon(aSrc) {
-      let img = this.querySelector(".userIcon");
-      if (aSrc) {
-        img.setAttribute("userIcon", aSrc);
-      } else {
-        img.removeAttribute("userIcon");
-      }
-    }
-
     setMessage(aMessage) {
-      // Setting the textContent directly allows text wrapping.
       let msg = this.querySelector(".tooltipMessage");
-      msg.textContent = aMessage;
+      msg.value = aMessage;
     }
 
     reset() {
       while (this.table.hasChildNodes()) {
         this.table.lastChild.remove();
       }
     }
 
@@ -308,34 +298,38 @@
 
     requestBuddyInfo(aAccount, aObservedName) {
       // Libpurple prpls don't necessarily return data in response to
       // requestBuddyInfo that is suitable for displaying inside a
       // tooltip (e.g. too many objects, or <img> and <a> tags),
       // so we only use it for JavaScript prpls.
       // This is a terrible, terrible hack to work around the fact that
       // ClassInfo.implementationLanguage has gone.
-      if (!aAccount.prplAccount.wrappedJSObject) {
+      if (!aAccount.prplAccount || !aAccount.prplAccount.wrappedJSObject) {
         return;
       }
       this.observedUserInfo = aObservedName;
       Services.obs.addObserver(this.observer, "user-info-received");
       aAccount.requestBuddyInfo(aObservedName);
     }
 
     updateTooltipFromBuddy(aBuddy) {
       this.buddy = aBuddy;
 
       this.reset();
       let name = aBuddy.userName;
       let displayName = aBuddy.displayName;
       this.setAttribute("displayname", displayName);
       let account = aBuddy.account;
       this.setAttribute("iconPrpl", account.protocol.iconBaseURI + "icon.png");
-      this.setBuddyIcon(aBuddy.buddyIconFilename);
+      if (aBuddy.buddyIconFilename || aBuddy.buddyIconFilename == "") {
+        this.setAttribute("userIcon", aBuddy.buddyIconFilename);
+      } else {
+        this.removeAttribute("userIcon");
+      }
 
       let statusType = aBuddy.statusType;
       this.setAttribute("status", Status.toAttribute(statusType));
       this.setMessage(Status.toLabel(statusType, aBuddy.statusText));
 
       if (displayName != name) {
         this.addRow(this.bundle.GetStringFromName("buddy.username"), name);
       }
@@ -363,32 +357,32 @@
             this.addSeparator();
             break;
           case Ci.prplITooltipInfo.status:
             let statusType = parseInt(elt.label);
             this.setAttribute("status", Status.toAttribute(statusType));
             this.setMessage(Status.toLabel(statusType, elt.value));
             break;
           case Ci.prplITooltipInfo.icon:
-            this.setBuddyIcon(elt.value);
+            this.setAttribute("userIcon", elt.value);
             break;
         }
       }
     }
 
     updateTooltipFromConversation(aConv) {
       if (!aConv.isChat && aConv.buddy) {
         return this.updateTooltipFromBuddy(aConv.buddy);
       }
 
       this.reset();
       this.setAttribute("displayname", aConv.name);
       let account = aConv.account;
       this.setAttribute("iconPrpl", account.protocol.iconBaseURI + "icon.png");
-      this.setBuddyIcon(null);
+      this.removeAttribute("userIcon");
       if (aConv.isChat) {
         this.setAttribute("status", "chat");
         if (!aConv.account.connected || aConv.left) {
           this.setAttribute("left", true);
         }
         let topic = aConv.topic;
         if (!topic) {
           this.setAttribute("noTopic", true);
@@ -430,15 +424,23 @@
         }
       }
 
       this.reset();
       this.setAttribute("displayname", aNick);
       this.setAttribute("iconPrpl", account.protocol.iconBaseURI + "icon.png");
       this.setAttribute("status", "unknown");
       this.setMessage(Status.toLabel("unknown"));
-      this.setBuddyIcon(aParticipant ? aParticipant.buddyIconFilename : null);
+      if (
+        aParticipant.buddyIconFilename ||
+        aParticipant.buddyIconFilename == ""
+      ) {
+        this.setAttribute("userIcon", aParticipant.buddyIconFilename);
+      } else {
+        this.removeAttribute("userIcon");
+      }
+
       this.requestBuddyInfo(account, normalizedNick);
       return true;
     }
   }
   customElements.define("chat-tooltip", MozChatTooltip, { extends: "tooltip" });
 }