up themes, fix notif test

v1.18.x
Barış Soner Uşaklı
parent 31ae8c7fd5
commit 5dfb2fb83a

@ -66,9 +66,9 @@
"nodebb-plugin-spam-be-gone": "0.5.1", "nodebb-plugin-spam-be-gone": "0.5.1",
"nodebb-rewards-essentials": "0.0.9", "nodebb-rewards-essentials": "0.0.9",
"nodebb-theme-lavender": "4.0.5", "nodebb-theme-lavender": "4.0.5",
"nodebb-theme-persona": "5.0.28", "nodebb-theme-persona": "5.0.29",
"nodebb-theme-slick": "1.1.0", "nodebb-theme-slick": "1.1.0",
"nodebb-theme-vanilla": "6.0.22", "nodebb-theme-vanilla": "6.0.23",
"nodebb-widget-essentials": "3.0.1", "nodebb-widget-essentials": "3.0.1",
"nodemailer": "2.6.4", "nodemailer": "2.6.4",
"nodemailer-sendmail-transport": "1.0.0", "nodemailer-sendmail-transport": "1.0.0",

@ -20,23 +20,19 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator'], fun
Notifications.loadNotifications(notifList); Notifications.loadNotifications(notifList);
}); });
notifList.on('click', '[data-nid]', function (e) { notifList.on('click', '[data-nid]', function (ev) {
// Scroll to index if already in topic (gh#5873) var notifEl = $(this);
var index = $(this).attr('data-index'); if (scrollToPostIndexIfOnPage(notifEl)) {
var tid = $(this).attr('data-tid'); ev.stopPropagation();
if (index && ajaxify.data.template.topic && parseInt(ajaxify.data.tid, 10) === parseInt(tid, 10)) { ev.preventDefault();
e.stopPropagation();
e.preventDefault();
navigator.scrollToIndex(index, true);
notifTrigger.dropdown('toggle'); notifTrigger.dropdown('toggle');
} }
var unread = $(this).hasClass('unread'); var unread = notifEl.hasClass('unread');
if (!unread) { if (!unread) {
return; return;
} }
var nid = $(this).attr('data-nid'); var nid = notifEl.attr('data-nid');
socket.emit('notifications.markRead', nid, function (err) { socket.emit('notifications.markRead', nid, function (err) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
@ -118,6 +114,19 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator'], fun
}); });
}; };
function scrollToPostIndexIfOnPage(notifEl) {
// Scroll to index if already in topic (gh#5873)
var pid = notifEl.attr('data-pid');
var tid = notifEl.attr('data-tid');
var path = notifEl.attr('data-path');
var postEl = components.get('post', 'pid', pid);
if (path.startsWith(config.relative_path + '/post/') && pid && postEl.length && ajaxify.data.template.topic && parseInt(ajaxify.data.tid, 10) === parseInt(tid, 10)) {
navigator.scrollToIndex(postEl.attr('data-index'), true);
return true;
}
return false;
}
Notifications.loadNotifications = function (notifList) { Notifications.loadNotifications = function (notifList) {
socket.emit('notifications.get', null, function (err, data) { socket.emit('notifications.get', null, function (err, data) {
if (err) { if (err) {

@ -13,7 +13,6 @@ var groups = require('./groups');
var meta = require('./meta'); var meta = require('./meta');
var batch = require('./batch'); var batch = require('./batch');
var plugins = require('./plugins'); var plugins = require('./plugins');
var posts = require('./posts');
var utils = require('./utils'); var utils = require('./utils');
var Notifications = module.exports; var Notifications = module.exports;
@ -23,19 +22,13 @@ Notifications.startJobs = function () {
new cron('*/30 * * * *', Notifications.prune, null, true); new cron('*/30 * * * *', Notifications.prune, null, true);
}; };
Notifications.get = function (nid, uid, callback) { Notifications.get = function (nid, callback) {
Notifications.getMultiple([nid], uid, function (err, notifications) { Notifications.getMultiple([nid], function (err, notifications) {
callback(err, Array.isArray(notifications) && notifications.length ? notifications[0] : null); callback(err, Array.isArray(notifications) && notifications.length ? notifications[0] : null);
}); });
}; };
Notifications.getMultiple = function (nids, uid, callback) { Notifications.getMultiple = function (nids, callback) {
if (typeof uid === 'function' && !callback) {
// no uid passed in
callback = uid;
uid = undefined;
}
if (!Array.isArray(nids) || !nids.length) { if (!Array.isArray(nids) || !nids.length) {
return setImmediate(callback, null, []); return setImmediate(callback, null, []);
} }
@ -44,19 +37,8 @@ Notifications.getMultiple = function (nids, uid, callback) {
}); });
var notifications; var notifications;
var userSettings;
async.waterfall([ async.waterfall([
function (next) {
if (!uid) {
return setImmediate(next);
}
User.getSettings(uid, function (err, settings) {
userSettings = settings;
next(err);
});
},
function (next) { function (next) {
db.getObjects(keys, next); db.getObjects(keys, next);
}, },
@ -69,7 +51,7 @@ Notifications.getMultiple = function (nids, uid, callback) {
User.getUsersFields(userKeys, ['username', 'userslug', 'picture'], next); User.getUsersFields(userKeys, ['username', 'userslug', 'picture'], next);
}, },
function (usersData, next) { function (usersData, next) {
async.eachOf(notifications, function (notification, index, next) { notifications.forEach(function (notification, index) {
if (notification) { if (notification) {
notification.datetimeISO = utils.toISOString(notification.datetime); notification.datetimeISO = utils.toISOString(notification.datetime);
@ -86,19 +68,9 @@ Notifications.getMultiple = function (nids, uid, callback) {
} else if (notification.image === 'brand:logo' || !notification.image) { } else if (notification.image === 'brand:logo' || !notification.image) {
notification.image = meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png'; notification.image = meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png';
} }
if (notification.path.startsWith('/post/')) {
posts.getPidIndex(notification.pid, notification.tid, userSettings.topicPostSort, function (err, index) {
notification.index = index;
next(err);
});
} else {
next();
}
} }
}, function (err) {
next(err, notifications);
}); });
next(null, notifications);
}, },
], callback); ], callback);
}; };

@ -140,7 +140,7 @@ UserNotifications.getNotifications = function (nids, uid, callback) {
function (next) { function (next) {
async.parallel({ async.parallel({
notifications: function (next) { notifications: function (next) {
notifications.getMultiple(nids, uid, next); notifications.getMultiple(nids, next);
}, },
hasRead: function (next) { hasRead: function (next) {
db.isSortedSetMembers('uid:' + uid + ':notifications:read', nids, next); db.isSortedSetMembers('uid:' + uid + ':notifications:read', nids, next);

Loading…
Cancel
Save