v1.18.x
Barış Soner Uşaklı 10 years ago
parent 0611b7e1ea
commit 276cd51836

@ -2,6 +2,7 @@
"title": "Notifications", "title": "Notifications",
"no_notifs": "You have no new notifications", "no_notifs": "You have no new notifications",
"see_all": "See all Notifications", "see_all": "See all Notifications",
"mark_all_read": "Mark all notifications read",
"back_to_home": "Back to %1", "back_to_home": "Back to %1",
"outgoing_link": "Outgoing Link", "outgoing_link": "Outgoing Link",

@ -10,7 +10,7 @@ define('forum/notifications', function() {
$('span.timeago').timeago(); $('span.timeago').timeago();
$('.notifications .delete').on('click', function() { $('.notifications .delete').on('click', function() {
socket.emit('notifications.deleteAll', function(err) { socket.emit('notifications.markAllRead', function(err) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }

@ -2,7 +2,6 @@
/* globals define, socket, translator, utils, config, app, ajaxify, Tinycon*/ /* globals define, socket, translator, utils, config, app, ajaxify, Tinycon*/
define('notifications', ['sounds'], function(sound) { define('notifications', ['sounds'], function(sound) {
var Notifications = {}; var Notifications = {};
@ -14,54 +13,44 @@ define('notifications', ['sounds'], function(sound) {
notifTrigger.on('click', function(e) { notifTrigger.on('click', function(e) {
e.preventDefault(); e.preventDefault();
if (!notifContainer.hasClass('open')) { if (notifContainer.hasClass('open')) {
return;
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>';
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.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) { notifList.on('click', '.mark-all-read', function() {
if (!err) { socket.emit('notifications.markAllRead', function(err) {
updateNotifCount(0); if (err) {
} app.alertError(err.message);
}); }
}); updateNotifCount(0);
} });
}); });
function updateNotifCount(count) { function updateNotifCount(count) {

@ -24,7 +24,6 @@ templatesController.getTemplatesListing = function(req, res, next) {
readConfigFile(next); readConfigFile(next);
}, },
function(config, next) { function(config, next) {
console.log(meta.config.homePageRoute);
config.custom_mapping['^/?$'] = meta.config.homePageRoute || 'categories'; config.custom_mapping['^/?$'] = meta.config.homePageRoute || 'categories';
plugins.fireHook('filter:templates.get_config', config, next); plugins.fireHook('filter:templates.get_config', config, next);

@ -12,7 +12,6 @@ var nconf = require('nconf'),
meta = require('../meta'), meta = require('../meta'),
Messaging = require('../messaging'), Messaging = require('../messaging'),
user = require('../user'), user = require('../user'),
notifications = require('../notifications'),
plugins = require('../plugins'), plugins = require('../plugins'),
utils = require('../../public/src/utils'), utils = require('../../public/src/utils'),
privileges = require('../privileges'), privileges = require('../privileges'),
@ -23,7 +22,6 @@ var nconf = require('nconf'),
SocketModules = { SocketModules = {
composer: {}, composer: {},
chats: {}, chats: {},
notifications: {},
sounds: {}, sounds: {},
settings: {} settings: {}
}; };
@ -246,14 +244,6 @@ SocketModules.chats.getRecentChats = function(socket, data, callback) {
Messaging.getRecentChats(socket.uid, start, end, 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 */ /* Sounds */
SocketModules.sounds.getSounds = function(socket, data, callback) { SocketModules.sounds.getSounds = function(socket, data, callback) {

@ -1,7 +1,7 @@
"use strict"; "use strict";
var user = require('../user'), var user = require('../user'),
notifications = require('../notifications'),
SocketNotifs = {}; SocketNotifs = {};
SocketNotifs.get = function(socket, data, callback) { SocketNotifs.get = function(socket, data, callback) {
@ -20,4 +20,12 @@ SocketNotifs.deleteAll = function(socket, data, callback) {
user.notifications.deleteAll(socket.uid, 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; module.exports = SocketNotifs;

Loading…
Cancel
Save