changeset 32:f8b3ac77e951

improved label deletion handling
author Charlie Root
date Tue, 13 Mar 2018 13:01:49 -0400
parents b2d0a9781472
children d41c01c5c933
files plugins/thunderbird_labels/tb_label.js
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/thunderbird_labels/tb_label.js	Tue Mar 13 13:01:26 2018 -0400
+++ b/plugins/thunderbird_labels/tb_label.js	Tue Mar 13 13:01:49 2018 -0400
@@ -128,8 +128,9 @@
 			}
 			
 			var pos = jQuery.inArray(toggle_label_no, tb_labels_for_message);
-			if (pos > -1) {
+			while (pos > -1) {
 				tb_labels_for_message.splice(pos, 1);
+				pos = jQuery.inArray(toggle_label_no, tb_labels_for_message);
 			}
 		}
 		// exit function when in detail mode. when preview is active keep going
@@ -241,9 +242,11 @@
       if (rcmail.env.messages)
 	{
 	  var first_message = rcmail.env.messages[selection[0]];
-	  if (first_message.flags
-	      && jQuery.inArray(toggle_label_no,
-				first_message.flags.tb_labels) >= 0
+	  if ((first_message.flags
+	       && jQuery.inArray(toggle_label_no,
+				 first_message.flags.tb_labels) >= 0) ||
+	      (hasParm && jQuery.grep(first_message.flags.tb_lparms,
+				      function(p) {return p['number'] == toggle_label_no;}).length)
 	      )
 	    first_toggle_mode = 'off';
 	  else
@@ -252,6 +255,7 @@
       else // single message display
 	{
 	  // flag already set?
+	  // Not sure this works if this flag has a parm
 	  if (jQuery.inArray(toggle_label_no,
 			     tb_labels_for_message) >= 0)
 	    first_toggle_mode = 'off';
@@ -281,9 +285,11 @@
 	      return;
 	    }
 	  var message = rcmail.env.messages[uid];
-	  if (message.flags
-	      && jQuery.inArray(toggle_label_no,
-				message.flags.tb_labels) >= 0
+	  if ((message.flags
+	       && jQuery.inArray(toggle_label_no,
+				 message.flags.tb_labels) >= 0) ||
+	      (hasParm && jQuery.grep(message.flags.tb_lparms,
+				      function(p) {return p['number'] == toggle_label_no;}).length)
 	      )
 	    {
 	      if (first_toggle_mode == 'off')