Author: jaytraxx
New Revision: 26745
URL: http://www.egroupware.org/viewvc/egroupware?rev=3D26745&view=3Drev
Log:
created ONE single AJAX request to improve performance again
Modified:
trunk/notifications/inc/class.ajaxnotifications.inc.php
trunk/notifications/js/notificationajaxpopup.js
Modified: trunk/notifications/inc/class.ajaxnotifications.inc.php
URL: http://www.egroupware.org/viewvc/egroupware/trunk/notifications/inc/cl=
ass.ajaxnotifications.inc.php?rev=3D26745&r1=3D26744&r2=3D26745&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
— trunk/notifications/inc/class.ajaxnotifications.inc.php (original)
+++ trunk/notifications/inc/class.ajaxnotifications.inc.php Fri Apr 3 22:1=
7:22 2009
@@ -104,12 +104,108 @@
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() {
-
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 boolean true or false
-
*/
-
private function check_mailbox() {
-
if(!isset($this->preferences[self::_mailappname]['notify_folders'])) { -
return true; //no pref set for notifying - exit -
} -
$notify_folders =3D explode(',', $this->preferences[self::_mailappname][=
‘notify_folders’]);
-
if(count($notify_folders) =3D=3D 0) { -
return true; //no folders configured for notifying - exit -
} -
= -
$bofelamimail =3D 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.'): c=
annot connect to mailbox. Please check your prefs!’);
-
return false; // cannot connect to mailbox -
} -
= -
$this->restore_session_data(); -
= -
$recent_messages =3D array(); -
$folder_status =3D array(); -
foreach($notify_folders as $id=3D>$notify_folder) { -
if(!is_array($this->session_data['notified_mail_uids'][$notify_folder])=
) {
-
$this->session_data['notified_mail_uids'][$notify_folder] =3D array(); -
} -
$folder_status[$notify_folder] =3D $bofelamimail->getFolderStatus($noti=
fy_folder);
-
$headers =3D $bofelamimail->getHeaders($notify_folder, 1, false, 0, tru=
e, array(‘status’=3D>‘UNSEEN’));
-
if(is_array($headers['header']) && count($headers['header']) > 0) { -
foreach($headers['header'] as $id=3D>$header) { -
// check if unseen mail has already been notified -
if(!in_array($header['uid'], $this->session_data['notified_mail_uids=
'][$notify_folder])) {
-
// got a REAL recent message -
$header['folder'] =3D $notify_folder; -
$header['folder_display_name'] =3D $folder_status[$notify_folder]['=
displayName’];
-
$header['folder_base64'] =3D base64_encode($notify_folder); -
$recent_messages[] =3D $header; -
} -
} -
} -
} -
= -
if(count($recent_messages) > 0) { -
// create notify message -
$notification_subject =3D lang("You've got new mail"); -
$values =3D array(); -
$values[] =3D array(); // content array starts at index 1 -
foreach($recent_messages as $id=3D>$recent_message) { -
$values[] =3D array( -
'mail_uid' =3D> $recent_message['uid'], -
'mail_folder' =3D> $recent_message['folder_display_name'], -
'mail_folder_base64' =3D> $recent_message['folder_base64'], -
'mail_subject' =3D> $recent_message['subject'], -
'mail_from' =3D> !empty($recent_message['sender_name']) ? $recent_=
message[‘sender_name’] : $recent_message[‘sender_address’],
-
'mail_received' =3D> $recent_message['date'], -
); -
// save notification status -
$this->session_data['notified_mail_uids'][$recent_message['folder']][]=
=3D $recent_message[‘uid’];
-
} -
= -
// create etemplate -
$tpl =3D new etemplate(); -
$tpl->read('notifications.checkmailbox'); -
$notification_message =3D $tpl->exec(false, $values, false, false, fals=
e, 1);
-
= -
// send notification -
$notification =3D new notifications(); -
$notification->set_receivers(array($this->recipient->account_id)); -
$notification->set_message($notification_message); -
$notification->set_sender($this->recipient->account_id); -
$notification->set_subject($notification_subject); -
$notification->set_skip_backends(array('email')); -
$notification->send(); -
} -
= -
$this->save_session_data(); -
return true; -
}
-
=
-
/**
-
- gets all egwpopup notifications for calling user
-
- =
-
- @return boolean true or false
-
*/
-
private function get_egwpopup() {
$session_id =3D $GLOBALS[‘egw_info’][‘user’][‘sessionid’];
$message =3D ‘’;
$rs =3D $this->db->select(self::_notification_table, =
@@ -141,89 +237,7 @@
break;
}
}
-
return $this->response->getXML(); -
}
-
=
-
/**
-
- checks users mailbox and sends a notification if new mails have arrived
-
- =
-
- @return xajax response
-
*/
-
public function check_mailbox() {
-
if(!isset($this->preferences[self::_mailappname]['notify_folders'])) { -
return $this->response->getXML(); //no pref set for notifying - exit -
} -
$notify_folders =3D explode(',', $this->preferences[self::_mailappname][=
‘notify_folders’]);
-
if (count($notify_folders) =3D=3D 0) { -
return $this->response->getXML(); //no folders configured for notifying= -
exit
-
} -
= -
$bofelamimail =3D 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.'): c=
annot connect to mailbox. Please check your prefs!’);
-
return $this->response->getXML(); // cannot connect to mailbox -
} -
= -
$this->restore_session_data(); -
= -
$recent_messages =3D array(); -
$folder_status =3D array(); -
foreach($notify_folders as $id=3D>$notify_folder) { -
if(!is_array($this->session_data['notified_mail_uids'][$notify_folder])=
) {
-
$this->session_data['notified_mail_uids'][$notify_folder] =3D array(); -
} -
$folder_status[$notify_folder] =3D $bofelamimail->getFolderStatus($noti=
fy_folder);
-
$headers =3D $bofelamimail->getHeaders($notify_folder, 1, false, 0, tru=
e, array(‘status’=3D>‘UNSEEN’));
-
if(is_array($headers['header']) && count($headers['header']) > 0) { -
foreach($headers['header'] as $id=3D>$header) { -
// check if unseen mail has already been notified -
if(!in_array($header['uid'], $this->session_data['notified_mail_uids=
'][$notify_folder])) {
-
// got a REAL recent message -
$header['folder'] =3D $notify_folder; -
$header['folder_display_name'] =3D $folder_status[$notify_folder]['=
displayName’];
-
$header['folder_base64'] =3D base64_encode($notify_folder); -
$recent_messages[] =3D $header; -
} -
} -
} -
} -
= -
if(count($recent_messages) > 0) { -
// create notify message -
$notification_subject =3D lang("You've got new mail"); -
$values =3D array(); -
$values[] =3D array(); // content array starts at index 1 -
foreach($recent_messages as $id=3D>$recent_message) { -
$values[] =3D array( -
'mail_uid' =3D> $recent_message['uid'], -
'mail_folder' =3D> $recent_message['folder_display_name'], -
'mail_folder_base64' =3D> $recent_message['folder_base64'], -
'mail_subject' =3D> $recent_message['subject'], -
'mail_from' =3D> !empty($recent_message['sender_name']) ? $recent_=
message[‘sender_name’] : $recent_message[‘sender_address’],
-
'mail_received' =3D> $recent_message['date'], -
); -
// save notification status -
$this->session_data['notified_mail_uids'][$recent_message['folder']][]=
=3D $recent_message[‘uid’];
-
} -
= -
// create etemplate -
$tpl =3D new etemplate(); -
$tpl->read('notifications.checkmailbox'); -
$notification_message =3D $tpl->exec(false, $values, false, false, fals=
e, 1);
-
= -
// send notification -
$notification =3D new notifications(); -
$notification->set_receivers(array($this->recipient->account_id)); -
$notification->set_message($notification_message); -
$notification->set_sender($this->recipient->account_id); -
$notification->set_subject($notification_subject); -
$notification->set_skip_backends(array('email')); -
$notification->send(); -
} -
= -
$this->save_session_data(); -
return $this->response->getXML();
-
return true;}
/**
Modified: trunk/notifications/js/notificationajaxpopup.js
URL: http://www.egroupware.org/viewvc/egroupware/trunk/notifications/js/not=
ificationajaxpopup.js?rev=3D26745&r1=3D26744&r2=3D26745&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
— trunk/notifications/js/notificationajaxpopup.js (original)
+++ trunk/notifications/js/notificationajaxpopup.js Fri Apr 3 22:17:22 2009
@@ -4,7 +4,7 @@
- @package notifications
- @subpackage ajaxpoup
- @link http://www.egroupware.org
-
- @author Cornelius Weiss nelius@cwtech.de
-
-
@author Cornelius Weiss nelius@cwtech.de, Christian Binder <christian=
@jaytraxx.de> -
@version $Id$
*/
=
-
@author Cornelius Weiss nelius@cwtech.de, Christian Binder <christian=
@@ -18,8 +18,7 @@
window.setTimeout(“egwpopup_refresh();”, 60000);
}
function egwpopup_refresh() {
- xajax_doXMLHTTP(“notifications.ajaxnotifications.check_mailbox”);
- xajax_doXMLHTTP(“notifications.ajaxnotifications.get_egwpopup_notificatio=
ns”);
- xajax_doXMLHTTP(“notifications.ajaxnotifications.get_notifications”);
egwpopup_setTimeout();
}
=
eGroupWare-cvs mailing list
eGroupWare-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/egroupware-cvs