ability to mark a notification read/unread from dropdown list, made styling less bootstrap-locked, using FA icon in theme instead of hardcoded in template

v1.18.x
Julian Lam 10 years ago
parent 8eb45fc80a
commit 350acde379

@ -37,7 +37,8 @@ define('notifications', ['sounds'], function(sound) {
}); });
notifList.on('click', '[data-nid]', function() { notifList.on('click', '[data-nid]', function() {
var nid = $(this).attr('data-nid'); var nid = this.getAttribute('data-nid');
socket.emit('notifications.markRead', nid, function(err) { socket.emit('notifications.markRead', nid, function(err) {
if (err) { if (err) {
app.alertError(err.message); app.alertError(err.message);
@ -54,6 +55,25 @@ define('notifications', ['sounds'], function(sound) {
}); });
}); });
notifList.on('click', '.mark-read', function(e) {
var anchorEl = $(this.parentNode),
parentEl = anchorEl.parent(),
nid = anchorEl.attr('data-nid'),
unread = parentEl.hasClass('unread');
e.preventDefault();
e.stopPropagation();
socket.emit('notifications.mark' + (unread ? 'Read' : 'Unread'), nid, function(err) {
if (err) {
app.alertError(err.message);
}
parentEl.toggleClass('unread');
increaseNotifCount(unread ? -1 : 1);
});
});
function updateNotifCount(count) { function updateNotifCount(count) {
if (count > 0) { if (count > 0) {
notifIcon.removeClass('fa-bell-o').addClass('fa-bell'); notifIcon.removeClass('fa-bell-o').addClass('fa-bell');
@ -67,8 +87,8 @@ define('notifications', ['sounds'], function(sound) {
Tinycon.setBubble(count); Tinycon.setBubble(count);
}; };
function increaseNotifCount() { function increaseNotifCount(delta) {
var count = parseInt(notifIcon.attr('data-content'), 10) + 1; var count = parseInt(notifIcon.attr('data-content'), 10) + delta;
updateNotifCount(count); updateNotifCount(count);
} }
@ -94,7 +114,7 @@ define('notifications', ['sounds'], function(sound) {
ajaxify.refresh(); ajaxify.refresh();
} }
increaseNotifCount(); increaseNotifCount(1);
sound.play('notification'); sound.play('notification');
}); });

@ -223,6 +223,22 @@ var async = require('async'),
Notifications.markReadMultiple([nid], uid, callback); Notifications.markReadMultiple([nid], uid, callback);
}; };
Notifications.markUnread = function(nid, uid, callback) {
callback = callback || function() {};
if (!parseInt(uid, 10) || !nid) {
return callback();
}
db.getObjectField(nid, 'datetime', function(err, datetime) {
datetime = datetime || Date.now();
async.parallel([
async.apply(db.sortedSetRemove, 'uid:' + uid + ':notifications:read', nid),
async.apply(db.sortedSetAdd, 'uid:' + uid + ':notifications:unread', datetime, nid)
], callback);
});
};
Notifications.markReadMultiple = function(nids, uid, callback) { Notifications.markReadMultiple = function(nids, uid, callback) {
callback = callback || function() {}; callback = callback || function() {};
if (!Array.isArray(nids) || !nids.length) { if (!Array.isArray(nids) || !nids.length) {

@ -24,6 +24,10 @@ SocketNotifs.markRead = function(socket, nid, callback) {
notifications.markRead(nid, socket.uid, callback); notifications.markRead(nid, socket.uid, callback);
}; };
SocketNotifs.markUnread = function(socket, nid, callback) {
notifications.markUnread(nid, socket.uid, callback);
};
SocketNotifs.markAllRead = function(socket, data, callback) { SocketNotifs.markAllRead = function(socket, data, callback) {
notifications.markAllRead(socket.uid, callback); notifications.markAllRead(socket.uid, callback);
}; };

@ -76,7 +76,7 @@ var async = require('async'),
deletedNids.push(nids[index]); deletedNids.push(nids[index]);
} else { } else {
notification.read = read; notification.read = read;
notification.readClass = !notification.read ? 'label-warning' : ''; notification.readClass = !notification.read ? 'unread' : '';
} }
}); });

Loading…
Cancel
Save