mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 13:46:34 +02:00
closes #2467
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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>';
|
||||
|
||||
notifList.translateHtml(html);
|
||||
|
||||
updateNotifCount(data.unread.length);
|
||||
|
||||
socket.emit('modules.notifications.markAllRead', null, function(err) {
|
||||
if (!err) {
|
||||
updateNotifCount(0);
|
||||
}
|
||||
});
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
notifList.on('click', '[data-nid]', function() {
|
||||
socket.emit('notifications.markRead', nid, function(err) {
|
||||
if (err) {
|
||||
app.alertError(err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
notifList.on('click', '.mark-all-read', function() {
|
||||
socket.emit('notifications.markAllRead', function(err) {
|
||||
if (err) {
|
||||
app.alertError(err.message);
|
||||
}
|
||||
updateNotifCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
function updateNotifCount(count) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user