From ea2dadac3efe30814560208a0bb002d76b7a21e6 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sun, 31 Jan 2010 23:56:44 -0700 Subject: [PATCH] FlagMessages action now catches mailbox changes and updates cacheid only if browser cache is up-to-date --- imp/js/DimpBase.js | 2 +- imp/lib/Ajax/Application.php | 33 +++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/imp/js/DimpBase.js b/imp/js/DimpBase.js index e8005de03..ca34ad2a6 100644 --- a/imp/js/DimpBase.js +++ b/imp/js/DimpBase.js @@ -2785,7 +2785,7 @@ var DimpBase = { this.updateFlag(vs, flag, set); if (!opts.noserver) { - DimpCore.doAction('FlagMessages', { flags: flags.toJSON(), view: this.folder }, { uids: vs }); + DimpCore.doAction('FlagMessages', this.viewport.addRequestParams({ flags: flags.toJSON(), view: this.folder }), { uids: vs }); } }, diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index d528f33f7..c849cb110 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -594,15 +594,15 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base * AJAX action: Flag messages. * * @param Horde_Variables $vars See the list of variables needed for - * _checkUidvalidity(). Additional variables - * used: + * _changed() and _checkUidvalidity(). + * Additional variables used: *
      * 'flags' - (string) The flags to set (JSON serialized array).
      * 'uid' - (string) Indices of the messages to flag (IMAP sequence
      *         string).
      * 
* - * @return mixed True on success, on failure an object with these + * @return mixed False on failure, or an object with the following * entries: *
      * 'ViewPort' - (object) See _viewPortData().
@@ -615,8 +615,13 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             return false;
         }
 
+        $change = $this->_changed($vars, true);
+
+        if (is_null($change)) {
+            return false;
+        }
+
         $flags = Horde_Serialize::unserialize($vars->flags, Horde_Serialize::JSON);
-        $result = false;
         $set = $notset = array();
 
         foreach ($flags as $val) {
@@ -635,9 +640,19 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             $result = $GLOBALS['injector']->getInstance('IMP_Message')->flag($notset, $indices, false);
         }
 
-        return $result
-            ? true
-            : $this->_checkUidvalidity($vars);
+        if ($result) {
+            $result = new stdClass;
+            if ($change) {
+                $result->ViewPort = $this->_viewPortData($vars, true);
+            } else {
+                $result->ViewPort = new stdClass;
+                $result->ViewPort->updatecacheid = IMP_Mailbox::singleton($vars->view)->getCacheID($vars->view);
+                $result->ViewPort->view = $vars->view;
+            }
+            return $result;
+        }
+
+        return $this->_checkUidvalidity($vars);
     }
 
     /**
@@ -1625,8 +1640,6 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
     protected function _generateDeleteResult($vars, $indices, $change,
                                              $nothread = false)
     {
-        $imp_mailbox = IMP_Mailbox::singleton($vars->view);
-
         $del = new stdClass;
         $del->folder = $vars->view;
         $del->uids = $GLOBALS['imp_imap']->ob()->utils->toSequenceString($indices, array('mailbox' => true));
@@ -1646,7 +1659,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
             $result->ViewPort = $this->_viewPortData($vars, true);
         } else {
             $result->ViewPort = new stdClass;
-            $result->ViewPort->updatecacheid = $imp_mailbox->getCacheID($vars->view);
+            $result->ViewPort->updatecacheid = IMP_Mailbox::singleton($vars->view)->getCacheID($vars->view);
             $result->ViewPort->view = $vars->view;
         }
 
-- 
2.11.0