mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +01:00
closes #5754
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
define('forum/notifications', ['components', 'notifications'], function (components, notifs) {
|
define('forum/notifications', ['components'], function (components) {
|
||||||
var Notifications = {};
|
var Notifications = {};
|
||||||
|
|
||||||
Notifications.init = function () {
|
Notifications.init = function () {
|
||||||
@@ -12,14 +12,6 @@ define('forum/notifications', ['components', 'notifications'], function (compone
|
|||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err);
|
return app.alertError(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit('notifications.getCount', function (err, count) {
|
|
||||||
if (err) {
|
|
||||||
return app.alertError(err.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
notifs.updateNotifCount(count);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,7 +24,6 @@ define('forum/notifications', ['components', 'notifications'], function (compone
|
|||||||
}
|
}
|
||||||
|
|
||||||
components.get('notifications/item').removeClass('unread');
|
components.get('notifications/item').removeClass('unread');
|
||||||
notifs.updateNotifCount(0);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ define('notifications', ['sounds', 'translator', 'components'], function (sounds
|
|||||||
var notifContainer = components.get('notifications');
|
var notifContainer = components.get('notifications');
|
||||||
var notifTrigger = notifContainer.children('a');
|
var notifTrigger = notifContainer.children('a');
|
||||||
var notifList = components.get('notifications/list');
|
var notifList = components.get('notifications/list');
|
||||||
var notifIcon = components.get('notifications/icon');
|
|
||||||
|
|
||||||
notifTrigger
|
notifTrigger.on('click', function (e) {
|
||||||
.on('click', function (e) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (notifContainer.hasClass('open')) {
|
if (notifContainer.hasClass('open')) {
|
||||||
return;
|
return;
|
||||||
@@ -24,15 +22,15 @@ define('notifications', ['sounds', 'translator', 'components'], function (sounds
|
|||||||
|
|
||||||
notifList.on('click', '[data-nid]', function () {
|
notifList.on('click', '[data-nid]', function () {
|
||||||
var unread = $(this).hasClass('unread');
|
var unread = $(this).hasClass('unread');
|
||||||
var nid = $(this).attr('data-nid');
|
|
||||||
if (!unread) {
|
if (!unread) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var nid = $(this).attr('data-nid');
|
||||||
socket.emit('notifications.markRead', nid, function (err) {
|
socket.emit('notifications.markRead', nid, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
incrementNotifCount(-1);
|
|
||||||
if (unreadNotifs[nid]) {
|
if (unreadNotifs[nid]) {
|
||||||
delete unreadNotifs[nid];
|
delete unreadNotifs[nid];
|
||||||
}
|
}
|
||||||
@@ -52,7 +50,7 @@ define('notifications', ['sounds', 'translator', 'components'], function (sounds
|
|||||||
}
|
}
|
||||||
|
|
||||||
liEl.toggleClass('unread');
|
liEl.toggleClass('unread');
|
||||||
incrementNotifCount(unread ? -1 : 1);
|
|
||||||
if (unread && unreadNotifs[nid]) {
|
if (unread && unreadNotifs[nid]) {
|
||||||
delete unreadNotifs[nid];
|
delete unreadNotifs[nid];
|
||||||
}
|
}
|
||||||
@@ -60,11 +58,6 @@ define('notifications', ['sounds', 'translator', 'components'], function (sounds
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
function incrementNotifCount(delta) {
|
|
||||||
var count = parseInt(notifIcon.attr('data-content'), 10) + delta;
|
|
||||||
Notifications.updateNotifCount(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.on('event:new_notification', function (notifData) {
|
socket.on('event:new_notification', function (notifData) {
|
||||||
// If a path is defined, show notif data, otherwise show generic data
|
// If a path is defined, show notif data, otherwise show generic data
|
||||||
var payload = {
|
var payload = {
|
||||||
@@ -164,7 +157,6 @@ define('notifications', ['sounds', 'translator', 'components'], function (sounds
|
|||||||
if (err) {
|
if (err) {
|
||||||
app.alertError(err.message);
|
app.alertError(err.message);
|
||||||
}
|
}
|
||||||
Notifications.updateNotifCount(0);
|
|
||||||
unreadNotifs = {};
|
unreadNotifs = {};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -292,7 +292,9 @@ Notifications.markUnread = function (nid, uid, callback) {
|
|||||||
async.apply(db.sortedSetAdd, 'uid:' + uid + ':notifications:unread', notification.datetime, nid),
|
async.apply(db.sortedSetAdd, 'uid:' + uid + ':notifications:unread', notification.datetime, nid),
|
||||||
], next);
|
], next);
|
||||||
},
|
},
|
||||||
], callback);
|
], function (err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Notifications.markReadMultiple = function (nids, uid, callback) {
|
Notifications.markReadMultiple = function (nids, uid, callback) {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
var notifications = require('../notifications');
|
var notifications = require('../notifications');
|
||||||
var SocketNotifs = module.exports;
|
var SocketNotifs = module.exports;
|
||||||
@@ -25,13 +27,37 @@ SocketNotifs.deleteAll = function (socket, data, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketNotifs.markRead = function (socket, nid, callback) {
|
SocketNotifs.markRead = function (socket, nid, callback) {
|
||||||
notifications.markRead(nid, socket.uid, callback);
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
notifications.markRead(nid, socket.uid, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
user.notifications.pushCount(socket.uid);
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketNotifs.markUnread = function (socket, nid, callback) {
|
SocketNotifs.markUnread = function (socket, nid, callback) {
|
||||||
notifications.markUnread(nid, socket.uid, callback);
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
notifications.markUnread(nid, socket.uid, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
user.notifications.pushCount(socket.uid);
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketNotifs.markAllRead = function (socket, data, callback) {
|
SocketNotifs.markAllRead = function (socket, data, callback) {
|
||||||
notifications.markAllRead(socket.uid, callback);
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
notifications.markAllRead(socket.uid, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
user.notifications.pushCount(socket.uid);
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user