From 9e1789dc5873221a69b9e98601b080056e2e7583 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 5 Nov 2014 20:41:31 -0500 Subject: [PATCH] closes #2297 --- public/language/en_GB/global.json | 4 +++- public/src/client/notifications.js | 19 +++++++++++++++---- src/socket.io/notifications.js | 8 ++++++++ src/user/notifications.js | 17 +++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) 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'); - - $('span.timeago').timeago(); - - // Allow the user to click anywhere in the LI listEl.on('click', 'li', function(e) { this.querySelector('a').click(); }); + + $('span.timeago').timeago(); + + $('.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) {