* 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,31 +474,29 @@
/** /**
* 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 = [];
for (var i=0; i < _rawData.length; i++)
{
var data = this.getData(_rawData[i]['message']);
// Prevent the same thing popping up multiple times // Prevent the same thing popping up multiple times
notifymessages[_id] = { notifymessages[_rawData[i]['id']] = {
message:_message, message:_rawData[i]['message'],
data: data, data: data,
status: _status, status: _rawData[i]['status'],
created: _created, created: _rawData[i]['created'],
current: _current current: _rawData[i]['current']
}; };
if (_actions && _actions.length > 0) notifymessages[_id]['data']['actions'] = _actions; if (_rawData[i]['actions'] && _rawData[i]['actions'].length > 0) notifymessages[_rawData[i]['id']]['data']['actions'] = _rawData[i]['actions'];
// Notification API // Notification API
if(_browser_notify && !_status) if(_browser_notify && !_rawData[i]['status'])
{ {
egw.notification(data.title, { egw.notification(data.title, {
tag: data.app+":"+_id, tag: data.app+":"+_rawData[i]['id'],
body: data.message, body: data.message,
icon: data.icon, icon: data.icon,
onclose:function(e){ onclose:function(e){
@ -529,6 +527,30 @@
} }
}); });
} }
if (!_rawData[i]['status'])
{
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();
}
}; };
/** /**