From 5d97acbb3c5f80d36331e9ef1356ff52e4223b59 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 04 Apr 2008 02:59:07 -0400
Subject: [PATCH] improved r1213 change: removed redundant code  and used mark_message() instead of toggle_read_status()  (which should be used only inside mark_message() function)

---
 program/js/app.js |   37 +++++++++++++++++++++----------------
 1 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 94b329d..4359e59 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -892,7 +892,7 @@
           {
             setTimeout(function(){ ref.printwin.focus(); }, 20);
             if (this.env.action != 'show')
-              this.toggle_read_status('read', [uid]);
+              this.mark_message('read', uid);
           }
         }
         break;
@@ -1486,6 +1486,7 @@
   this.mark_message = function(flag, uid)
     {
     var a_uids = new Array();
+    var r_uids = new Array();
     var selection = this.message_list ? this.message_list.get_selection() : new Array();
     
     if (uid)
@@ -1496,26 +1497,35 @@
       {
       for (var id, n=0; n<selection.length; n++)
         {
-        id = selection[n];
-        if ((flag=='read' && this.message_list.rows[id].unread) || (flag=='unread' && !this.message_list.rows[id].unread)
-            || (flag=='delete' && !this.message_list.rows[id].deleted) || (flag=='undelete' && this.message_list.rows[id].deleted))
-          a_uids[a_uids.length] = id;
+    	  a_uids[a_uids.length] = selection[n];
         }
+      }
+
+    for (var id, n=0; n<a_uids.length; n++)
+      {
+        id = a_uids[n];
+        if ((flag=='read' && this.message_list.rows[id].unread) 
+	    || (flag=='unread' && !this.message_list.rows[id].unread)
+            || (flag=='delete' && !this.message_list.rows[id].deleted)
+	    || (flag=='undelete' && this.message_list.rows[id].deleted))
+	  {
+	    r_uids[r_uids.length] = id;
+	  }
       }
     
     // nothing to do
-    if (!a_uids.length)
+    if (!r_uids.length)
       return;
       
     switch (flag)
       {
         case 'read':
         case 'unread':
-          this.toggle_read_status(flag, a_uids);
+          this.toggle_read_status(flag, r_uids);
           break;
         case 'delete':
         case 'undelete':
-          this.toggle_delete_status(a_uids);
+          this.toggle_delete_status(r_uids);
           break;
       }
     };
@@ -1525,16 +1535,12 @@
   {
     // mark all message rows as read/unread
     var icn_src;
-    var res_uids = new Array(); 
     var rows = this.message_list.rows;
     for (var i=0; i<a_uids.length; i++)
       {
       uid = a_uids[i];
-      // check if flag isn't set yet 
-      if (rows[uid] && ((flag=='unread' && !rows[uid].unread) || (flag=='read' && rows[uid].unread)))
+      if (rows[uid])
         {
-        res_uids[res_uids.length] = uid;
-
         rows[uid].unread = (flag=='unread' ? true : false);
         
         if (rows[uid].classname.indexOf('unread')<0 && rows[uid].unread)
@@ -1561,15 +1567,14 @@
         }
       }
 
-    if (res_uids.length)
-      this.http_post('mark', '_uid='+res_uids.join(',')+'&_flag='+flag);
+    this.http_post('mark', '_uid='+a_uids.join(',')+'&_flag='+flag);
   };
   
   // mark all message rows as deleted/undeleted
   this.toggle_delete_status = function(a_uids)
   {
     if (this.env.read_when_deleted)
-      this.toggle_read_status('read',a_uids);
+      this.mark_message('read',a_uids);
 
     // if deleting message from "view message" don't bother with delete icon
     if (this.env.action == "show")

--
Gitblit v1.9.1