mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-04 03:21:18 +01:00
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
This commit is contained in:
@@ -37,7 +37,8 @@ define('notifications', ['sounds'], function(sound) {
|
||||
});
|
||||
|
||||
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) {
|
||||
if (err) {
|
||||
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) {
|
||||
if (count > 0) {
|
||||
notifIcon.removeClass('fa-bell-o').addClass('fa-bell');
|
||||
@@ -67,8 +87,8 @@ define('notifications', ['sounds'], function(sound) {
|
||||
Tinycon.setBubble(count);
|
||||
};
|
||||
|
||||
function increaseNotifCount() {
|
||||
var count = parseInt(notifIcon.attr('data-content'), 10) + 1;
|
||||
function increaseNotifCount(delta) {
|
||||
var count = parseInt(notifIcon.attr('data-content'), 10) + delta;
|
||||
updateNotifCount(count);
|
||||
}
|
||||
|
||||
@@ -94,7 +114,7 @@ define('notifications', ['sounds'], function(sound) {
|
||||
ajaxify.refresh();
|
||||
}
|
||||
|
||||
increaseNotifCount();
|
||||
increaseNotifCount(1);
|
||||
|
||||
sound.play('notification');
|
||||
});
|
||||
|
||||
@@ -223,6 +223,22 @@ var async = require('async'),
|
||||
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) {
|
||||
callback = callback || function() {};
|
||||
if (!Array.isArray(nids) || !nids.length) {
|
||||
|
||||
@@ -24,6 +24,10 @@ SocketNotifs.markRead = function(socket, nid, 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) {
|
||||
notifications.markAllRead(socket.uid, callback);
|
||||
};
|
||||
|
||||
@@ -76,7 +76,7 @@ var async = require('async'),
|
||||
deletedNids.push(nids[index]);
|
||||
} else {
|
||||
notification.read = read;
|
||||
notification.readClass = !notification.read ? 'label-warning' : '';
|
||||
notification.readClass = !notification.read ? 'unread' : '';
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user