mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 06:30:59 +01:00
* Notifications: fix notification sub messages (grouped entries) would still show up even though their parent message once been deleted
This commit is contained in:
parent
19bd3a03b0
commit
6b3cc6f7b5
@ -145,11 +145,12 @@ class notifications_ajax {
|
||||
/**
|
||||
* Remove given notification id(s) from the table
|
||||
*
|
||||
* @param array|int $notify_ids one or multiple notify_id(s)
|
||||
* @param array $notifymessages one or multiple notify_id(s)
|
||||
*/
|
||||
public function delete_message($notify_ids)
|
||||
public function delete_message($notifymessages)
|
||||
{
|
||||
if ($notify_ids)
|
||||
$notify_ids = $this->fetch_notify_ids($notifymessages);
|
||||
if (!empty($notify_ids))
|
||||
{
|
||||
$this->db->delete(self::_notification_table,array(
|
||||
'notify_id' => $notify_ids,
|
||||
@ -162,7 +163,7 @@ class notifications_ajax {
|
||||
/**
|
||||
* Method to update message(s) status
|
||||
*
|
||||
* @param int|array $notify_ids one or more notify_id(s)
|
||||
* @param array $notifymessages one or more notify_id(s)
|
||||
* @param string $status = SEEN, status of message:
|
||||
* - SEEN: message has been seen
|
||||
* - UNSEEN: message has not been seen
|
||||
@ -170,9 +171,10 @@ class notifications_ajax {
|
||||
* this status has been used more specifically for browser type
|
||||
* of notifications.
|
||||
*/
|
||||
public function update_status($notify_ids,$status = "SEEN")
|
||||
public function update_status($notifymessages, $status = "SEEN")
|
||||
{
|
||||
if ($notify_ids)
|
||||
$notify_ids = $this->fetch_notify_ids($notifymessages);
|
||||
if (!empty($notify_ids))
|
||||
{
|
||||
$this->db->update(self::_notification_table,array('notify_status' => $status),array(
|
||||
'notify_id' => $notify_ids,
|
||||
@ -182,6 +184,67 @@ class notifications_ajax {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all relevant notify ids based on given notify message data
|
||||
* @param $notifymessages
|
||||
* @return array
|
||||
*/
|
||||
public function fetch_notify_ids ($notifymessages)
|
||||
{
|
||||
$notify_ids = [];
|
||||
|
||||
foreach ($notifymessages as $data)
|
||||
{
|
||||
if (is_array($data) && $data['id'])
|
||||
{
|
||||
array_push($notify_ids, (string)$data['id']);
|
||||
if (is_array($data['data'])) $notify_ids = array_unique(array_merge($notify_ids, $this->search_in_notify_data($data['data']['id'], $data['data']['app'])));
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($notify_ids, (string)$data);
|
||||
}
|
||||
|
||||
}
|
||||
return $notify_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches all notify_ids relevant to the entry
|
||||
* @param $_id
|
||||
* @param $_appname
|
||||
* @return array
|
||||
*/
|
||||
public function search_in_notify_data($_id, $_appname)
|
||||
{
|
||||
$ret = [];
|
||||
if ($_id && $_appname)
|
||||
{
|
||||
try {
|
||||
// mariaDB supported query
|
||||
$ret = $this->db->select(self::_notification_table, 'notify_id', array(
|
||||
'account_id' => $this->recipient->account_id,
|
||||
'notify_type' => self::_type,
|
||||
'notify_data->"$.appname"' => $_appname,
|
||||
'notify_data->"$.data.id"' => $_id
|
||||
),
|
||||
__LINE__,__FILE__,0 ,'ORDER BY notify_id DESC',self::_appname);
|
||||
}
|
||||
catch (Api\Db\Exception $e) {
|
||||
// do it manual for all other DB
|
||||
foreach($this->db->select(self::_notification_table, '*', array(
|
||||
'account_id' => $this->recipient->account_id,
|
||||
'notify_type' => self::_type
|
||||
),
|
||||
__LINE__,__FILE__,0 ,'ORDER BY notify_id DESC',self::_appname) as $row)
|
||||
{
|
||||
$data = json_decode($row['notify_data'], true);
|
||||
if ($data['appname'] == $_appname && $data['data']['id'] == $_id) $ret[] = $row['notify_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* gets all egwpopup notifications for calling user
|
||||
*
|
||||
|
@ -516,14 +516,9 @@
|
||||
_event.stopPropagation();
|
||||
var egwpopup_message = _node[0];
|
||||
var id = egwpopup_message[0].id.replace(/egwpopup_message_/ig,'');
|
||||
var ids = [id];
|
||||
if (notifymessages[id]['children'])
|
||||
{
|
||||
ids = ids.concat(Object.keys(notifymessages[id]['children']));
|
||||
}
|
||||
if (notifymessages[id]['status'] !='SEEN')
|
||||
{
|
||||
var request = egw.json("notifications.notifications_ajax.update_status", [ids, "SEEN"]);
|
||||
var request = egw.json("notifications.notifications_ajax.update_status", [[notifymessages[id]], "SEEN"]);
|
||||
request.sendRequest(true);
|
||||
this.update_message_status(id, "SEEN");
|
||||
if (notifymessages[id]['extra_data']['onSeenAction'])
|
||||
@ -537,9 +532,7 @@
|
||||
notifications.prototype.mark_all_seen = function()
|
||||
{
|
||||
if (!notifymessages || Object.keys(notifymessages).length == 0) return false;
|
||||
var ids = Object.keys(notifymessages);
|
||||
ids = ids.concat(this.findAllChildrenIds());
|
||||
egw.json("notifications.notifications_ajax.update_status", [ids, "SEEN"]).sendRequest(true);
|
||||
egw.json("notifications.notifications_ajax.update_status", [notifymessages, "SEEN"]).sendRequest(true);
|
||||
for (var id in notifymessages)
|
||||
{
|
||||
this.update_message_status(id, "SEEN");
|
||||
@ -568,9 +561,7 @@
|
||||
|
||||
notifications.prototype.delete_all = function () {
|
||||
if (!notifymessages || Object.entries(notifymessages).length == 0) return false;
|
||||
var ids = Object.keys(notifymessages);
|
||||
ids = ids.concat(this.findAllChildrenIds());
|
||||
egw.json("notifications.notifications_ajax.delete_message", [ids]).sendRequest(true);
|
||||
egw.json("notifications.notifications_ajax.delete_message", [notifymessages]).sendRequest(true);
|
||||
notifymessages = {};
|
||||
jQuery("#egwpopup_list").empty();
|
||||
this.counterUpdate();
|
||||
@ -584,12 +575,7 @@
|
||||
_event.stopPropagation();
|
||||
var egwpopup_message = _node[0];
|
||||
var id = egwpopup_message[0].id.replace(/egwpopup_message_/ig,'');
|
||||
var ids = [id];
|
||||
if (notifymessages[id]['children'])
|
||||
{
|
||||
ids = ids.concat(Object.keys(notifymessages[id]['children']));
|
||||
}
|
||||
var request = egw.json("notifications.notifications_ajax.delete_message", [ids]);
|
||||
var request = egw.json("notifications.notifications_ajax.delete_message", [[notifymessages[id]]]);
|
||||
request.sendRequest(true);
|
||||
var nextNode = egwpopup_message.next();
|
||||
var keepLoadingPrompt = false;
|
||||
@ -699,7 +685,8 @@
|
||||
status: _rawData[i]['status'],
|
||||
created: _rawData[i]['created'],
|
||||
current: _rawData[i]['current'],
|
||||
extra_data: _rawData[i]['extra_data']
|
||||
extra_data: _rawData[i]['extra_data'],
|
||||
id: _rawData[i]['id']
|
||||
};
|
||||
if (_rawData[i]['actions'] && _rawData[i]['actions'].length > 0) notifymessages[_rawData[i]['id']]['data']['actions'] = _rawData[i]['actions'];
|
||||
// Notification API
|
||||
@ -714,7 +701,7 @@
|
||||
// notification id
|
||||
var id = this.tag.split(":");
|
||||
// delete the message
|
||||
var request = egw.json("notifications.notifications_ajax.update_status", [id[1], 'DISPLAYED']);
|
||||
var request = egw.json("notifications.notifications_ajax.update_status", [[id[1]], 'DISPLAYED']);
|
||||
request.sendRequest();
|
||||
},
|
||||
onclick:function(e){
|
||||
@ -740,7 +727,7 @@
|
||||
}
|
||||
if (!_rawData[i]['status'])
|
||||
{
|
||||
egw.json("notifications.notifications_ajax.update_status", [_rawData[i]['id'], 'DISPLAYED']);
|
||||
egw.json("notifications.notifications_ajax.update_status", [[_rawData[i]['id']], 'DISPLAYED']);
|
||||
hasUnseen.push(_rawData[i]['id']);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user