From 276cd51836fbba54187f948fab31ec18279e3f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 17 Feb 2015 15:13:58 -0500 Subject: [PATCH] closes #2467 --- public/language/en_GB/notifications.json | 1 + public/src/client/notifications.js | 2 +- public/src/modules/notifications.js | 79 ++++++++++-------------- src/controllers/templates.js | 1 - src/socket.io/modules.js | 10 --- src/socket.io/notifications.js | 10 ++- 6 files changed, 45 insertions(+), 58 deletions(-) diff --git a/public/language/en_GB/notifications.json b/public/language/en_GB/notifications.json index 54c926a597..96aef60183 100644 --- a/public/language/en_GB/notifications.json +++ b/public/language/en_GB/notifications.json @@ -2,6 +2,7 @@ "title": "Notifications", "no_notifs": "You have no new notifications", "see_all": "See all Notifications", + "mark_all_read": "Mark all notifications read", "back_to_home": "Back to %1", "outgoing_link": "Outgoing Link", diff --git a/public/src/client/notifications.js b/public/src/client/notifications.js index b0fbb4619f..024fe6715c 100644 --- a/public/src/client/notifications.js +++ b/public/src/client/notifications.js @@ -10,7 +10,7 @@ define('forum/notifications', function() { $('span.timeago').timeago(); $('.notifications .delete').on('click', function() { - socket.emit('notifications.deleteAll', function(err) { + socket.emit('notifications.markAllRead', function(err) { if (err) { return app.alertError(err.message); } diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index 319d88041f..8ce107f20a 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -2,7 +2,6 @@ /* globals define, socket, translator, utils, config, app, ajaxify, Tinycon*/ - define('notifications', ['sounds'], function(sound) { var Notifications = {}; @@ -14,54 +13,44 @@ define('notifications', ['sounds'], function(sound) { notifTrigger.on('click', function(e) { e.preventDefault(); - if (!notifContainer.hasClass('open')) { - - socket.emit('notifications.get', null, function(err, data) { - - function createNotification(notification, callback) { - if (notification.image) { - image = ''; - } else { - image = ''; - } - - return '
  • ' + image + '' + $.timeago(new Date(parseInt(notification.datetime, 10))) + '' + notification.bodyShort + '
  • '; - } - - var x, html = ''; - - // Switch to shorthand - translator.toggleTimeagoShorthand(); - - if (!err && (data.read.length + data.unread.length) > 0) { - var image = ''; - for (x = 0; x < data.unread.length; x++) { - html += createNotification(data.unread[x]); - } - - for (x = 0; x < data.read.length; x++) { - html += createNotification(data.read[x]); - } - } else { - html += '
  • [[notifications:no_notifs]]
  • '; - } - - // Switch back to original timeago strings - translator.toggleTimeagoShorthand(); - - html += ''; + if (notifContainer.hasClass('open')) { + return; + } + socket.emit('notifications.get', null, function(err, data) { + if (err) { + return app.alertError(err.message); + } + + var notifs = data.unread.concat(data.read); + + translator.toggleTimeagoShorthand(); + for(var i=0; i