Commit 30e9882c authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Don't change unread message count when deleting read messages; decrement it when reading messages

parent c2eeb5cc
......@@ -72,8 +72,14 @@ else if ($delete) {
json_reply('local', get_string('failedtodeletenotifications', 'activity') . ': ' . $e->getMessage());
}
db_commit();
json_reply(false, array('message' => get_string('deletednotifications', 'activity', $count),
'count' => $count));
safe_require('notification', 'internal');
json_reply(false, array(
'message' => get_string('deletednotifications', 'activity', $count),
'count' => $count,
'newunreadcount' => call_static_method(generate_class_name('notification', 'internal'), 'unread_count', $USER->get('id'))
));
}
// normal processing
......
......@@ -115,19 +115,11 @@ function markread(form, action) {
if (!data.error) {
if (data.count > 0) {
activitylist.doupdate();
forEach(getElementsByTagAndClassName('span', 'unreadmessagescontainer'), function(message) {
var countnode = message.firstChild;
var oldcount = parseInt(countnode.innerHTML);
var newcount = (oldcount - data.count);
var messagenode = message.lastChild;
if (newcount == 1) { // jump through hoops to change between plural and singular
messagenode.innerHTML = get_string('unreadmessage');
}
else {
messagenode.innerHTML = get_string('unreadmessages');
}
countnode.innerHTML = newcount;
});
if (data.newunreadcount && typeof(data.newunreadcount) != 'undefined') {
updateUnreadCount(data.newunreadcount, 'reset');
} else {
updateUnreadCount(data.count, 'decrement');
}
}
}
}, function () {
......@@ -135,6 +127,27 @@ function markread(form, action) {
});
}
function updateUnreadCount(n, decrement) {
forEach(getElementsByTagAndClassName('span', 'unreadmessagescontainer'), function(message) {
var countnode = message.firstChild;
if (decrement == 'decrement') {
var oldcount = parseInt(countnode.innerHTML);
var newcount = (oldcount - n);
}
else {
var newcount = n;
}
var messagenode = message.lastChild;
if (newcount == 1) { // jump through hoops to change between plural and singular
messagenode.innerHTML = get_string('unreadmessage');
}
else {
messagenode.innerHTML = get_string('unreadmessages');
}
countnode.innerHTML = newcount;
});
}
function showHideMessage(id) {
if (getStyle('message-' + id, 'display') == 'none') {
var unread = getFirstElementByTagAndClassName('input', 'tocheckread',
......@@ -146,6 +159,7 @@ function showHideMessage(id) {
return !!data.error;
});
swapDOM(unread, IMG({'src' : {$star}, 'alt' : {$unread}}));
updateUnreadCount(1, 'decrement');
}
showElement('message-' + id);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment