Node.js based forum software built for the modern web
closes #2467
Barış Soner Uşaklı276cd51836fb
diff --git a/public/language/en_GB/notifications.json b/public/language/en_GB/notifications.jsonindex 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.jsindex 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.jsindex 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 = '<img class="image" src="' + notification.image + '" />';- } else {- image = '';- }-- return '<li class="' + (notification.readClass || '') + '"><a href="' + (notification.path || '#') + '">' + image + '<span class="pull-right relTime">' + $.timeago(new Date(parseInt(notification.datetime, 10))) + '</span><span class="text">' + notification.bodyShort + '</span></a></li>';- }-- 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 += '<li class="no-notifs"><a>[[notifications:no_notifs]]</a></li>';- }-- // Switch back to original timeago strings- translator.toggleTimeagoShorthand();-- html += '<li class="pagelink"><a href="' + config.relative_path + '/notifications">[[notifications:see_all]]</a></li>';+ 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<notifs.length; ++i) {+ notifs[i].timeago = $.timeago(new Date(parseInt(notifs[i].datetime, 10)));+ }+ translator.toggleTimeagoShorthand();++ templates.parse('partials/notifications_list', {notifications: notifs}, function(html) {notifList.translateHtml(html);+ });+ });+ });- updateNotifCount(data.unread.length);+ notifList.on('click', '[data-nid]', function() {+ socket.emit('notifications.markRead', nid, function(err) {+ if (err) {+ app.alertError(err.message);+ }+ });+ });- socket.emit('modules.notifications.markAllRead', null, function(err) {- if (!err) {- updateNotifCount(0);- }- });- });- }+ notifList.on('click', '.mark-all-read', function() {+ socket.emit('notifications.markAllRead', function(err) {+ if (err) {+ app.alertError(err.message);+ }+ updateNotifCount(0);+ });});function updateNotifCount(count) {diff --git a/src/controllers/templates.js b/src/controllers/templates.jsindex 7cbe6728e9..dbf0be4870 100644--- a/src/controllers/templates.js+++ b/src/controllers/templates.js@@ -24,7 +24,6 @@ templatesController.getTemplatesListing = function(req, res, next) {readConfigFile(next);},function(config, next) {- console.log(meta.config.homePageRoute);config.custom_mapping['^/?$'] = meta.config.homePageRoute || 'categories';plugins.fireHook('filter:templates.get_config', config, next);diff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex 71a44f36bd..00fdeaf433 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -12,7 +12,6 @@ var nconf = require('nconf'),meta = require('../meta'),Messaging = require('../messaging'),user = require('../user'),- notifications = require('../notifications'),plugins = require('../plugins'),utils = require('../../public/src/utils'),privileges = require('../privileges'),@@ -23,7 +22,6 @@ var nconf = require('nconf'),SocketModules = {composer: {},chats: {},- notifications: {},sounds: {},settings: {}};@@ -246,14 +244,6 @@ SocketModules.chats.getRecentChats = function(socket, data, callback) {Messaging.getRecentChats(socket.uid, start, end, callback);};-/* Notifications */-SocketModules.notifications.markRead = function(socket, nid) {- notifications.markRead(nid, socket.uid);-};--SocketModules.notifications.markAllRead = function(socket, data, callback) {- notifications.markAllRead(socket.uid, callback);-};/* Sounds */SocketModules.sounds.getSounds = function(socket, data, callback) {diff --git a/src/socket.io/notifications.js b/src/socket.io/notifications.jsindex 657e46db52..ebd633b080 100644--- a/src/socket.io/notifications.js+++ b/src/socket.io/notifications.js@@ -1,7 +1,7 @@"use strict";var user = require('../user'),-+ notifications = require('../notifications'),SocketNotifs = {};SocketNotifs.get = function(socket, data, callback) {@@ -20,4 +20,12 @@ SocketNotifs.deleteAll = function(socket, data, callback) {user.notifications.deleteAll(socket.uid, callback);};+SocketNotifs.markRead = function(socket, nid, callback) {+ notifications.markRead(nid, socket.uid, callback);+};++SocketNotifs.markAllRead = function(socket, data, callback) {+ notifications.markAllRead(socket.uid, callback);+};+module.exports = SocketNotifs;