Move IMAP alert notifications to a central location.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 Aug 2009 08:48:30 +0000 (02:48 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 5 Aug 2009 08:51:29 +0000 (02:51 -0600)
imp/ajax.php
imp/lib/IMP.php
imp/lib/Notification/Listener/Status.php
imp/lib/Notification/Listener/StatusMobile.php [new file with mode: 0644]

index 9ed06c5..82a0160 100644 (file)
@@ -783,12 +783,5 @@ if ($errors) {
                       $errors, __FILE__, __LINE__, PEAR_LOG_DEBUG);
 }
 
-/* Display IMAP alerts. */
-if ($notify) {
-    foreach ($GLOBALS['imp_imap']->ob->alerts() as $alert) {
-        $notification->push($alert, 'horde.warning');
-    }
-}
-
 // Send the final result.
 Horde::sendHTTPResponse(Horde::prepareResponse($result, $notify ? $GLOBALS['imp_notify'] : null), 'json');
index bf2ea25..ff1a33e 100644 (file)
@@ -93,7 +93,7 @@ class IMP
         $viewmode = self::getViewMode();
 
         if ($viewmode == 'mimp') {
-            $GLOBALS['imp_notify'] = $GLOBALS['notification']->attach('status', null, 'Horde_Notification_Listener_Mobile');
+            $GLOBALS['imp_notify'] = $GLOBALS['notification']->attach('status', null, 'IMP_Notification_Listener_StatusMobile');
         } else {
             $GLOBALS['imp_notify'] = $GLOBALS['notification']->attach('status', array('viewmode' => $viewmode), 'IMP_Notification_Listener_Status');
             if ($viewmode == 'imp') {
@@ -652,13 +652,7 @@ class IMP
      */
     static public function status()
     {
-        global $notification;
-
-        /* Display IMAP alerts. */
-        foreach ($GLOBALS['imp_imap']->ob->alerts() as $alert) {
-            $notification->push($alert, 'horde.warning');
-        }
-
+        $notification = Horde_Notification::singleton();
         $notification->notify(array('listeners' => array('status', 'audio')));
     }
 
index 825dc08..f516991 100644 (file)
@@ -76,6 +76,11 @@ class IMP_Notification_Listener_Status extends Horde_Notification_Listener_Statu
             $options['store'] = true;
         }
 
+        /* Display IMAP alerts. */
+        foreach ($GLOBALS['imp_imap']->ob->alerts() as $alert) {
+            $this->push($alert, 'horde.warning');
+        }
+
         parent::notify($messageStack, $options);
 
         /* Preferences display. */
diff --git a/imp/lib/Notification/Listener/StatusMobile.php b/imp/lib/Notification/Listener/StatusMobile.php
new file mode 100644 (file)
index 0000000..d777cad
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * The IMP_Notification_Listener_StatusMobile:: class extends the
+ * Horde_Notification_Listener_Mobile:: class to display IMAP alert
+ * notifications.
+ *
+ * Copyright 1999-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package Horde_Notification
+ */
+class IMP_Notification_Listener_StatusMobile extends Horde_Notification_Listener_Mobile
+{
+    /**
+     * Returns all status message if there are any on the 'status' message
+     * stack.
+     *
+     * @param array &$messageStack  The stack of messages.
+     * @param array $options        An array of options.
+     */
+    public function notify(&$messageStack, $options = array())
+    {
+        /* Display IMAP alerts. */
+        foreach ($GLOBALS['imp_imap']->ob->alerts() as $alert) {
+            $this->push($alert, 'horde.warning');
+        }
+
+        parent::notify($messageStack, $options);
+    }
+
+}