diff --git a/package.json b/package.json index 2a7575b3b5..56a606d617 100644 --- a/package.json +++ b/package.json @@ -66,9 +66,9 @@ "nodebb-plugin-spam-be-gone": "0.5.1", "nodebb-rewards-essentials": "0.0.9", "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-vanilla": "6.0.22", + "nodebb-theme-vanilla": "6.0.23", "nodebb-widget-essentials": "3.0.1", "nodemailer": "2.6.4", "nodemailer-sendmail-transport": "1.0.0", diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index ea78918c1b..f99e1b8de4 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -20,23 +20,19 @@ define('notifications', ['sounds', 'translator', 'components', 'navigator'], fun Notifications.loadNotifications(notifList); }); - notifList.on('click', '[data-nid]', function (e) { - // Scroll to index if already in topic (gh#5873) - var index = $(this).attr('data-index'); - var tid = $(this).attr('data-tid'); - if (index && ajaxify.data.template.topic && parseInt(ajaxify.data.tid, 10) === parseInt(tid, 10)) { - e.stopPropagation(); - e.preventDefault(); - - navigator.scrollToIndex(index, true); + notifList.on('click', '[data-nid]', function (ev) { + var notifEl = $(this); + if (scrollToPostIndexIfOnPage(notifEl)) { + ev.stopPropagation(); + ev.preventDefault(); notifTrigger.dropdown('toggle'); } - var unread = $(this).hasClass('unread'); + var unread = notifEl.hasClass('unread'); if (!unread) { return; } - var nid = $(this).attr('data-nid'); + var nid = notifEl.attr('data-nid'); socket.emit('notifications.markRead', nid, function (err) { if (err) { 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) { socket.emit('notifications.get', null, function (err, data) { if (err) { diff --git a/src/notifications.js b/src/notifications.js index 715f4cf264..098efe5d9f 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -13,7 +13,6 @@ var groups = require('./groups'); var meta = require('./meta'); var batch = require('./batch'); var plugins = require('./plugins'); -var posts = require('./posts'); var utils = require('./utils'); var Notifications = module.exports; @@ -23,19 +22,13 @@ Notifications.startJobs = function () { new cron('*/30 * * * *', Notifications.prune, null, true); }; -Notifications.get = function (nid, uid, callback) { - Notifications.getMultiple([nid], uid, function (err, notifications) { +Notifications.get = function (nid, callback) { + Notifications.getMultiple([nid], function (err, notifications) { callback(err, Array.isArray(notifications) && notifications.length ? notifications[0] : null); }); }; -Notifications.getMultiple = function (nids, uid, callback) { - if (typeof uid === 'function' && !callback) { - // no uid passed in - callback = uid; - uid = undefined; - } - +Notifications.getMultiple = function (nids, callback) { if (!Array.isArray(nids) || !nids.length) { return setImmediate(callback, null, []); } @@ -44,19 +37,8 @@ Notifications.getMultiple = function (nids, uid, callback) { }); var notifications; - var userSettings; async.waterfall([ - function (next) { - if (!uid) { - return setImmediate(next); - } - - User.getSettings(uid, function (err, settings) { - userSettings = settings; - next(err); - }); - }, function (next) { db.getObjects(keys, next); }, @@ -69,7 +51,7 @@ Notifications.getMultiple = function (nids, uid, callback) { User.getUsersFields(userKeys, ['username', 'userslug', 'picture'], next); }, function (usersData, next) { - async.eachOf(notifications, function (notification, index, next) { + notifications.forEach(function (notification, index) { if (notification) { notification.datetimeISO = utils.toISOString(notification.datetime); @@ -86,19 +68,9 @@ Notifications.getMultiple = function (nids, uid, callback) { } else if (notification.image === 'brand:logo' || !notification.image) { 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); }; diff --git a/src/user/notifications.js b/src/user/notifications.js index cb3f208e0f..4e2dcba7e8 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -140,7 +140,7 @@ UserNotifications.getNotifications = function (nids, uid, callback) { function (next) { async.parallel({ notifications: function (next) { - notifications.getMultiple(nids, uid, next); + notifications.getMultiple(nids, next); }, hasRead: function (next) { db.isSortedSetMembers('uid:' + uid + ':notifications:read', nids, next);