Skip to content

Node.js based forum software built for the modern web

closes #2297

barisusakli9e1789dc5873
diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.json
index 3536cb67f9..eab8e045a9 100644
--- a/public/language/en_GB/global.json
+++ b/public/language/en_GB/global.json
@@ -96,5 +96,7 @@
"updated.title": "Forum Updated",
"updated.message": "This forum has just been updated to the latest version. Click here to refresh the page.",
- "privacy": "Privacy"
+ "privacy": "Privacy",
+
+ "delete_all": "Delete All"
}
diff --git a/public/src/client/notifications.js b/public/src/client/notifications.js
index aed18cf315..b0fbb4619f 100644
--- a/public/src/client/notifications.js
+++ b/public/src/client/notifications.js
@@ -3,13 +3,24 @@ define('forum/notifications', function() {
Notifications.init = function() {
var listEl = $('.notifications-list');
+ listEl.on('click', 'li', function(e) {
+ this.querySelector('a').click();
+ });
$('span.timeago').timeago();
- // Allow the user to click anywhere in the LI
- listEl.on('click', 'li', function(e) {
- this.querySelector('a').click();
+ $('.notifications .delete').on('click', function() {
+ socket.emit('notifications.deleteAll', function(err) {
+ if (err) {
+ return app.alertError(err.message);
+ }
+
+ $('.notifications .delete').addClass('hidden');
+ $('.notifications .alert-info').removeClass('hidden');
+ listEl.empty();
+ });
});
+
}
return Notifications;
diff --git a/src/socket.io/notifications.js b/src/socket.io/notifications.js
index fd9204f08f..657e46db52 100644
--- a/src/socket.io/notifications.js
+++ b/src/socket.io/notifications.js
@@ -12,4 +12,12 @@ SocketNotifs.getCount = function(socket, data, callback) {
user.notifications.getUnreadCount(socket.uid, callback);
};
+SocketNotifs.deleteAll = function(socket, data, callback) {
+ if (!socket.uid) {
+ return;
+ }
+
+ user.notifications.deleteAll(socket.uid, callback);
+};
+
module.exports = SocketNotifs;
diff --git a/src/user/notifications.js b/src/user/notifications.js
index 7b356b8f88..7be91bf168 100644
--- a/src/user/notifications.js
+++ b/src/user/notifications.js
@@ -20,6 +20,9 @@ var async = require('async'),
(function(UserNotifications) {
UserNotifications.get = function(uid, callback) {
+ if (!parseInt(uid, 10)) {
+ return callback(null , {read: [], unread: []});
+ }
getNotifications(uid, 10, function(err, notifications) {
if (err) {
return callback(err);
@@ -230,6 +233,20 @@ var async = require('async'),
});
};
+ UserNotifications.deleteAll = function(uid, callback) {
+ if (!parseInt(uid, 10)) {
+ return callback();
+ }
+ async.parallel([
+ function(next) {
+ db.delete('uid:' + uid + ':notifications:unread', next);
+ },
+ function(next) {
+ db.delete('uid:' + uid + ':notifications:read', next);
+ }
+ ], callback);
+ };
+
UserNotifications.sendTopicNotificationToFollowers = function(uid, topicData, postData) {
db.getSetMembers('followers:' + uid, function(err, followers) {
if (err || !Array.isArray(followers) || !followers.length) {