Bug 1552161 - Show OTR notification box per contact. r=kaie
authorAlessandro Castellani <alessandro@thunderbird.net>
Mon, 27 May 2019 14:02:51 -0700
changeset 35695 2249b3ca338c6c3e0bc1643240ba28cd80e81f6c
parent 35694 19ec36793dc973a57edaa762922b204647467855
child 35696 2e120efeddbfdcbc2912c80c97b80472a055f175
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewerskaie
bugs1552161
Bug 1552161 - Show OTR notification box per contact. r=kaie
chat/modules/OTRUI.jsm
chat/themes/otr.css
--- a/chat/modules/OTRUI.jsm
+++ b/chat/modules/OTRUI.jsm
@@ -20,17 +20,17 @@ function _str(id) {
 function _strArgs(id, args) {
   return syncL10n.formatValue(id, args);
 }
 
 const privDialog = "chrome://chat/content/otr-generate-key.xul";
 const authDialog = "chrome://chat/content/otr-auth.xul";
 const addFingerDialog = "chrome://chat/content/otr-add-fingerprint.xul";
 
-const authVerify = "otr-auth-unverified";
+const AuthVerify = "otr-auth-unverified";
 var authLabelMap;
 var authTitleMap;
 var trustMap;
 
 function initStrings() {
   authLabelMap = new Map([
     ["otr:auth-error", _str("auth-error")],
     ["otr:auth-success", _str("auth-success")],
@@ -437,19 +437,23 @@ var OTRUI = {
     let name = uiConv.target.normalizedName;
     OTRUI.openAuth(window, name, "ask", uiConv, aObject);
   },
 
   closeUnverified(context) {
     let uiConv = OTR.getUIConvFromContext(context);
     if (!uiConv) return;
 
-    let notification = this.globalBox.getNotificationWithValue(authVerify);
-    if (notification)
-      notification.close();
+    let notifications = this.globalBox.allNotifications;
+    for (let i = notifications.length - 1; i >= 0; i--) {
+      if (context.username == notifications[i].getAttribute("user") &&
+          notifications[i].getAttribute("value") == AuthVerify) {
+        notifications[i].close();
+      }
+    }
   },
 
   hideUserNotifications(context) {
     let notifications = this.globalBox.allNotifications;
     for (let i = notifications.length - 1; i >= 0; i--) {
       if (context.username == notifications[i].getAttribute("user")) {
         notifications[i].setAttribute("hidden", "true");
       }
@@ -470,43 +474,41 @@ var OTRUI = {
         notifications[i].removeAttribute("hidden");
     }
   },
 
   notifyUnverified(context, seen) {
     let uiConv = OTR.getUIConvFromContext(context);
     if (!uiConv) return;
 
-    if (this.globalBox.getNotificationWithValue(authVerify))
-      return;
-
     let window = this.globalDoc.defaultView;
 
     let msg = _strArgs("finger-" + seen, {name: context.username});
     let buttons = [{
       label: _str("finger-verify"),
       accessKey: _str("finger-verify-accessKey"),
       callback() {
         let name = uiConv.target.normalizedName;
         OTRUI.openAuth(window, name, "start", uiConv);
         // prevent closing of notification bar when the button is hit
         return true;
       },
     }];
 
     let priority = this.globalBox.PRIORITY_WARNING_MEDIUM;
-    this.globalBox.appendNotification(msg, authVerify, null, priority, buttons, null);
+    this.globalBox.appendNotification(msg, context.username, null, priority, buttons, null);
 
     let verifyTitle = syncL10n.formatValue("verify-title");
-    this.updateNotificationUI(context, verifyTitle, authVerify);
+    this.updateNotificationUI(context, verifyTitle, context.username, AuthVerify);
   },
 
-  updateNotificationUI(context, typeTitle, value) {
-    let notification = this.globalBox.getNotificationWithValue(value);
+  updateNotificationUI(context, typeTitle, username, key) {
+    let notification = this.globalBox.getNotificationWithValue(username);
     notification.setAttribute("user", context.username);
+    notification.setAttribute("status", key);
     notification.setAttribute("orient", "vertical");
     notification.messageDetails.setAttribute("orient", "vertical");
     notification.messageDetails.removeAttribute("oncommand");
     notification.messageDetails.removeAttribute("align");
 
     let title = this.globalDoc.createElement("title");
     title.setAttribute("flex", "1");
     title.setAttribute("crop", "end");
@@ -535,21 +537,20 @@ var OTRUI = {
 
     notification.appendChild(bottom);
   },
 
   closeVerification(context) {
     let uiConv = OTR.getUIConvFromContext(context);
     if (!uiConv) return;
 
-    authLabelMap.forEach(function(_, key) {
-      let prevNotification = OTRUI.globalBox.getNotificationWithValue(key);
-      if (prevNotification)
-        prevNotification.close();
-    });
+    let prevNotification = OTRUI.globalBox.getNotificationWithValue(context.username);
+    if (prevNotification) {
+      prevNotification.close();
+    }
   },
 
   notifyVerification(context, key, cancelable) {
     let uiConv = OTR.getUIConvFromContext(context);
     if (!uiConv) return;
 
     // TODO: maybe update the .label property on the notification instead
     // of closing it ... although, buttons need to be updated too.
@@ -567,19 +568,19 @@ var OTRUI = {
           OTR.abortSMP(context);
         },
       }];
     }
 
     // higher priority to overlay the current notifyUnverified
     let priority = this.globalBox.PRIORITY_WARNING_HIGH;
     OTRUI.closeUnverified(context);
-    this.globalBox.appendNotification(msg, key, null, priority, buttons, null);
+    this.globalBox.appendNotification(msg, context.username, null, priority, buttons, null);
 
-    this.updateNotificationUI(context, typeTitle, key);
+    this.updateNotificationUI(context, typeTitle, context.username, key);
   },
 
   updateAuth(aObj) {
     // let uiConv = OTR.getUIConvFromContext(aObj.context);
     if (!aObj.progress) {
       OTRUI.closeAuth(aObj.context);
       OTRUI.notifyVerification(aObj.context, "otr:auth-error", false);
     } else if (aObj.progress === 100) {
--- a/chat/themes/otr.css
+++ b/chat/themes/otr.css
@@ -99,44 +99,44 @@ toolbarbutton.otr-button {
 }
 
 .otr-notification-footer {
   display: flex;
   justify-content: end;
 }
 
 /* waiting */
-#otr-notification-box notification[type="warning"][value="otr:auth-waiting"] >
+#otr-notification-box notification[type="warning"][status="otr:auth-waiting"] >
   hbox > .messageImage {
   list-style-image: url("chrome://global/skin/icons/help.svg") !important;
 }
 
 /* fail */
-#otr-notification-box notification[type="warning"][value="otr:auth-fail"] {
+#otr-notification-box notification[type="warning"][status="otr:auth-fail"] {
   background: #ffc9d5 !important;
 }
 
-#otr-notification-box notification[type="warning"][value="otr:auth-fail"] >
+#otr-notification-box notification[type="warning"][status="otr:auth-fail"] >
   hbox > .messageImage {
   list-style-image: url("chrome://global/skin/icons/error.svg") !important;
   color: #c93434 !important;
 }
 
-#otr-notification-box notification[type="warning"][value="otr:auth-fail"]
+#otr-notification-box notification[type="warning"][status="otr:auth-fail"]
   .otr-notification-header title {
   color: #c93434 !important;
 }
 
 /* success */
-#otr-notification-box notification[type="warning"][value="otr:auth-success"] {
+#otr-notification-box notification[type="warning"][status="otr:auth-success"] {
   background: #D3F4AF !important;
 }
 
-#otr-notification-box notification[type="warning"][value="otr:auth-success"] >
+#otr-notification-box notification[type="warning"][status="otr:auth-success"] >
   hbox > .messageImage {
   list-style-image: url("chrome://global/skin/icons/check.svg") !important;
   color: #407501 !important;
 }
 
-#otr-notification-box notification[type="warning"][value="otr:auth-success"]
+#otr-notification-box notification[type="warning"][status="otr:auth-success"]
   .otr-notification-header title {
   color: #407501 !important;
 }