* Notifications: performance improvements on fetching notifications

This commit is contained in:
Hadi Nategh 2018-06-19 14:58:32 +02:00
parent 17daf70e8a
commit e8cc3d0eb3
2 changed files with 78 additions and 71 deletions

View File

@ -180,7 +180,8 @@ class notifications_ajax {
'account_id' => $this->recipient->account_id, 'account_id' => $this->recipient->account_id,
'notify_type' => self::_type 'notify_type' => self::_type
), ),
__LINE__,__FILE__,false,'',self::_appname); __LINE__,__FILE__,false,'ORDER BY notify_id DESC LIMIT 0,100',self::_appname);
$result = array();
if ($rs->NumRows() > 0) { if ($rs->NumRows() > 0) {
foreach ($rs as $notification) { foreach ($rs as $notification) {
$actions = null; $actions = null;
@ -193,33 +194,17 @@ class notifications_ajax {
), $data['appname'], true); ), $data['appname'], true);
$actions = $_actions[$data['appname']]; $actions = $_actions[$data['appname']];
} }
$this->response->apply('app.notifications.append',array( $result[] = array(
$notification['notify_id'], 'id' => $notification['notify_id'],
$notification['notify_message'], 'message' => $notification['notify_message'],
$browserNotify, 'status' => $notification['notify_status'],
$notification['notify_status'], 'created' => Api\DateTime::to($notification['notify_created']),
Api\DateTime::to($notification['notify_created']), 'current' => new DateTime(),
new DateTime(), 'action' => is_array($actions)?$actions:NULL
is_array($actions)?$actions:NULL)
); );
}
switch($this->preferences[self::_appname]['egwpopup_verbosity']) {
case 'low':
$this->response->apply('app.notifications.bell', array('active'));
break;
case 'high':
if (empty($notification['notify_status']) || $notification['notify_status'] === "UNSEEN")
{
$this->response->alert(lang('EGroupware has notifications for you'));
}
$this->response->apply('app.notifications.display');
break;
case 'medium':
default:
$this->response->apply('app.notifications.display');
break;
} }
$this->response->apply('app.notifications.append', array($result, $browserNotify));
} }
return true; return true;
} }

View File

@ -474,60 +474,82 @@
/** /**
* Add message to internal display-queue * Add message to internal display-queue
* *
* @param _id * @param _rowData
* @param _message
* @param _browser_notify * @param _browser_notify
* @param {string} _status
* @param {string} _created
*
* @return undefined
*/ */
notifications.prototype.append = function(_id, _message, _browser_notify, notifications.prototype.append = function(_rawData, _browser_notify) {
_status, _created, _current, _actions) {
var data = this.getData(_message); var hasUnseen = [];
// Prevent the same thing popping up multiple times for (var i=0; i < _rawData.length; i++)
notifymessages[_id] = {
message:_message,
data: data,
status: _status,
created: _created,
current: _current
};
if (_actions && _actions.length > 0) notifymessages[_id]['data']['actions'] = _actions;
// Notification API
if(_browser_notify && !_status)
{ {
egw.notification(data.title, { var data = this.getData(_rawData[i]['message']);
tag: data.app+":"+_id, // Prevent the same thing popping up multiple times
body: data.message, notifymessages[_rawData[i]['id']] = {
icon: data.icon, message:_rawData[i]['message'],
onclose:function(e){ data: data,
// notification id status: _rawData[i]['status'],
var id = this.tag.split(":"); created: _rawData[i]['created'],
// delete the message current: _rawData[i]['current']
var request = egw.json("notifications.notifications_ajax.update_status", [id[1], 'DISPLAYED']); };
request.sendRequest(); if (_rawData[i]['actions'] && _rawData[i]['actions'].length > 0) notifymessages[_rawData[i]['id']]['data']['actions'] = _rawData[i]['actions'];
}, // Notification API
onclick:function(e){ if(_browser_notify && !_rawData[i]['status'])
// notification id {
var id = this.tag.split(":"); egw.notification(data.title, {
tag: data.app+":"+_rawData[i]['id'],
body: data.message,
icon: data.icon,
onclose:function(e){
// notification id
var id = this.tag.split(":");
// delete the message
var request = egw.json("notifications.notifications_ajax.update_status", [id[1], 'DISPLAYED']);
request.sendRequest();
},
onclick:function(e){
// notification id
var id = this.tag.split(":");
// get the right data from messages object // get the right data from messages object
var notify = notifymessages[id[1]]; var notify = notifymessages[id[1]];
if (!notifymessages[id[1]]) this.close(); if (!notifymessages[id[1]]) this.close();
if (notify && notify.data && notify.data.id) if (notify && notify.data && notify.data.id)
{ {
egw.open(notify.data.id, notify.data.app); egw.open(notify.data.id, notify.data.app);
}
else if (notify && notify.data)
{
egw.open_link(notify.data.url,'_blank',notify.data.popup);
}
this.close();
} }
else if (notify && notify.data) });
{ }
egw.open_link(notify.data.url,'_blank',notify.data.popup); if (!_rawData[i]['status'])
} {
this.close(); egw.json("notifications.notifications_ajax.update_status", [_rawData[i]['id'], 'DISPLAYED']);
hasUnseen.push(_rawData[i]['id']);
}
}
switch(egw.preference('egwpopup_verbosity', 'notifications'))
{
case 'low':
this.bell('active');
break;
case 'high':
if (hasUnseen.length > 0)
{
alert(egw.lang('EGroupware has notifications for you'));
egw.json("notifications.notifications_ajax.update_status", [hasUnseen, 'DISPLAYED']).sendRequest();
} }
}); this.display();
break;
case 'medium':
this.display();
} }
}; };