From 612f7be6d9c03fb5c975d7bffd9526e7b8949681 Mon Sep 17 00:00:00 2001 From: Christian Binder Date: Fri, 3 Apr 2009 20:17:22 +0000 Subject: [PATCH] created ONE single AJAX request to improve performance again --- .../inc/class.ajaxnotifications.inc.php | 96 +++++++++++-------- notifications/js/notificationajaxpopup.js | 5 +- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/notifications/inc/class.ajaxnotifications.inc.php b/notifications/inc/class.ajaxnotifications.inc.php index f78ed059cd..9638a7e4d0 100644 --- a/notifications/inc/class.ajaxnotifications.inc.php +++ b/notifications/inc/class.ajaxnotifications.inc.php @@ -104,65 +104,39 @@ class ajaxnotifications { public function __destruct() {} /** - * Gets all egwpopup notification for calling user. - * Requests and response is done via xajax + * public AJAX trigger function to be called by the JavaScript client + * + * this function calls all other recurring AJAX notifications methods + * to have ONE single recurring AJAX call per user * * @return xajax response */ - public function get_egwpopup_notifications() { - $session_id = $GLOBALS['egw_info']['user']['sessionid']; - $message = ''; - $rs = $this->db->select(self::_notification_table, - '*', array( - 'account_id' => $this->recipient->account_id, - 'session_id' => $session_id, - ), - __LINE__,__FILE__,false,'',self::_appname); - if ($rs->NumRows() > 0) { - foreach ($rs as $notification) { - $this->response->addScriptCall('append_notification_message',$notification['message']); - } - $myval=$this->db->delete(self::_notification_table,array( - 'account_id' => $this->recipient->account_id, - 'session_id' => $session_id, - ),__LINE__,__FILE__,self::_appname); - - switch($this->preferences[self::_appname]['egwpopup_verbosity']) { - case 'low': - $this->response->addScript('notificationbell_switch("active");'); - break; - case 'high': - $this->response->addAlert(lang('eGroupWare has notifications for you')); - $this->response->addScript('egwpopup_display();'); - break; - case 'medium': - default: - $this->response->addScript('egwpopup_display();'); - break; - } - } + public function get_notifications() { + $this->check_mailbox(); + $this->get_egwpopup(); + return $this->response->getXML(); } /** * checks users mailbox and sends a notification if new mails have arrived * - * @return xajax response + * @return boolean true or false */ - public function check_mailbox() { + private function check_mailbox() { if(!isset($this->preferences[self::_mailappname]['notify_folders'])) { - return $this->response->getXML(); //no pref set for notifying - exit + return true; //no pref set for notifying - exit } $notify_folders = explode(',', $this->preferences[self::_mailappname]['notify_folders']); - if (count($notify_folders) == 0) { - return $this->response->getXML(); //no folders configured for notifying - exit + if(count($notify_folders) == 0) { + return true; //no folders configured for notifying - exit } $bofelamimail = new bofelamimail($GLOBALS['egw']->translation->charset()); if(!$bofelamimail->openConnection()) { // TODO: This is ugly. Log a bit nicer! error_log(self::_appname.' (user: '.$this->recipient->account_lid.'): cannot connect to mailbox. Please check your prefs!'); - return $this->response->getXML(); // cannot connect to mailbox + return false; // cannot connect to mailbox } $this->restore_session_data(); @@ -223,7 +197,47 @@ class ajaxnotifications { } $this->save_session_data(); - return $this->response->getXML(); + return true; + } + + /** + * gets all egwpopup notifications for calling user + * + * @return boolean true or false + */ + private function get_egwpopup() { + $session_id = $GLOBALS['egw_info']['user']['sessionid']; + $message = ''; + $rs = $this->db->select(self::_notification_table, + '*', array( + 'account_id' => $this->recipient->account_id, + 'session_id' => $session_id, + ), + __LINE__,__FILE__,false,'',self::_appname); + if ($rs->NumRows() > 0) { + foreach ($rs as $notification) { + $this->response->addScriptCall('append_notification_message',$notification['message']); + } + $myval=$this->db->delete(self::_notification_table,array( + 'account_id' => $this->recipient->account_id, + 'session_id' => $session_id, + ),__LINE__,__FILE__,self::_appname); + + switch($this->preferences[self::_appname]['egwpopup_verbosity']) { + case 'low': + $this->response->addScript('notificationbell_switch("active");'); + break; + case 'high': + $this->response->addAlert(lang('eGroupWare has notifications for you')); + $this->response->addScript('egwpopup_display();'); + break; + case 'medium': + default: + $this->response->addScript('egwpopup_display();'); + break; + } + } + return true; } /** diff --git a/notifications/js/notificationajaxpopup.js b/notifications/js/notificationajaxpopup.js index 360f589da6..b056f795f8 100644 --- a/notifications/js/notificationajaxpopup.js +++ b/notifications/js/notificationajaxpopup.js @@ -4,7 +4,7 @@ * @package notifications * @subpackage ajaxpoup * @link http://www.egroupware.org - * @author Cornelius Weiss + * @author Cornelius Weiss , Christian Binder * @version $Id$ */ @@ -18,8 +18,7 @@ function egwpopup_setTimeout() { window.setTimeout("egwpopup_refresh();", 60000); } function egwpopup_refresh() { - xajax_doXMLHTTP("notifications.ajaxnotifications.check_mailbox"); - xajax_doXMLHTTP("notifications.ajaxnotifications.get_egwpopup_notifications"); + xajax_doXMLHTTP("notifications.ajaxnotifications.get_notifications"); egwpopup_setTimeout(); }