Bug 1552256 - Fix "Add Contact's OTR Fingerprint" for contact with open conversation. r=mkmelin
authorAlessandro Castellani <alessandro@thunderbird.net>
Mon, 27 May 2019 14:55:49 -0700
changeset 35696 2e120efeddbfdcbc2912c80c97b80472a055f175
parent 35695 2249b3ca338c6c3e0bc1643240ba28cd80e81f6c
child 35697 6cefc7883cb3f1dd040fc269ddb57bdca65ecb66
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersmkmelin
bugs1552256
Bug 1552256 - Fix "Add Contact's OTR Fingerprint" for contact with open conversation. r=mkmelin
chat/modules/OTRUI.jsm
--- a/chat/modules/OTRUI.jsm
+++ b/chat/modules/OTRUI.jsm
@@ -151,17 +151,17 @@ var OTRUI = {
     if (!buddyContextMenu || !OTR.libLoaded) {
       return;  // Not the buddy list context menu
     }
     OTRUI.removeBuddyContextMenu(doc);
 
     let sep = doc.createXULElement("menuseparator");
     sep.setAttribute("id", "otrsep");
     let menuitem = doc.createXULElement("menuitem");
-    menuitem.setAttribute("label", _str("buddycontextmenu.label"));
+    menuitem.setAttribute("label", _str("buddycontextmenu-label"));
     menuitem.setAttribute("id", "otrcont");
     menuitem.addEventListener("command", () => {
       let target = buddyContextMenu.triggerNode;
       if (target.localName == "richlistitem") {
         let contact = target.contact;
         let args = OTRUI.contactWrapper(contact);
         args.wrappedJSObject = args;
         let features = "chrome,modal,centerscreen,resizable=no,minimizable=no";
@@ -615,22 +615,31 @@ var OTRUI = {
     let account = acc.normalizedName;
     let protocol = acc.protocol.normalizedName;
     Promise.resolve();
     if (OTR.privateKeyFingerprint(account, protocol) === null)
       OTR.generatePrivateKey(account, protocol);
   },
 
   contactWrapper(contact) {
-    let wrapper = {
+    // If the conversation already started.
+    if (contact.buddy) {
+      return {
+        account: contact.buddy.normalizedName,
+        protocol: contact.buddy.buddy.protocol.normalizedName,
+        screenname: contact.buddy.userName,
+      };
+    }
+
+    // For online and offline contacts without an open conversation.
+    return {
       account: contact.preferredBuddy.preferredAccountBuddy.account.normalizedName,
       protocol: contact.preferredBuddy.protocol.normalizedName,
       screenname: contact.preferredBuddy.preferredAccountBuddy.userName,
     };
-    return wrapper;
   },
 
   onContactAdded(contact) {
     let args = OTRUI.contactWrapper(contact);
     if (OTR.getFingerprintsForRecipient(args.account, args.protocol, args.screenname).length > 0)
       return;
     args.wrappedJSObject = args;
     let features = "chrome,modal,centerscreen,resizable=no,minimizable=no";