v1.18.x
Barış Soner Uşaklı 7 years ago
parent 7bdd2144e0
commit b9d410d612

@ -106,14 +106,14 @@ Digest.send = function (data, callback) {
function (next) { function (next) {
async.parallel({ async.parallel({
notifications: async.apply(user.notifications.getDailyUnread, userObj.uid), notifications: async.apply(user.notifications.getDailyUnread, userObj.uid),
popular: async.apply(topics.getPopularTopics, data.interval, userObj.uid, 0, 9), topics: async.apply(getTermTopics, data.interval, userObj.uid, 0, 9),
}, next); }, next);
}, },
function (data, next) { function (data, next) {
var notifications = data.notifications.filter(Boolean); var notifications = data.notifications.filter(Boolean);
// If there are no notifications and no new topics, don't bother sending a digest // If there are no notifications and no new topics, don't bother sending a digest
if (!notifications.length && !data.popular.topics.length) { if (!notifications.length && !data.topics.length) {
return next(); return next();
} }
@ -124,7 +124,7 @@ Digest.send = function (data, callback) {
}); });
// Fix relative paths in topic data // Fix relative paths in topic data
data.popular.topics = data.popular.topics.map(function (topicObj) { data.topics = data.topics.map(function (topicObj) {
var user = topicObj.hasOwnProperty('teaser') && topicObj.teaser !== undefined ? topicObj.teaser.user : topicObj.user; var user = topicObj.hasOwnProperty('teaser') && topicObj.teaser !== undefined ? topicObj.teaser.user : topicObj.user;
if (user && user.picture && utils.isRelativeUrl(user.picture)) { if (user && user.picture && utils.isRelativeUrl(user.picture)) {
user.picture = nconf.get('base_url') + user.picture; user.picture = nconf.get('base_url') + user.picture;
@ -138,7 +138,7 @@ Digest.send = function (data, callback) {
username: userObj.username, username: userObj.username,
userslug: userObj.userslug, userslug: userObj.userslug,
notifications: notifications, notifications: notifications,
recent: data.popular.topics, recent: data.topics,
interval: data.interval, interval: data.interval,
showUnsubscribe: true, showUnsubscribe: true,
}, function (err) { }, function (err) {
@ -154,4 +154,22 @@ Digest.send = function (data, callback) {
], function (err) { ], function (err) {
callback(err, emailsSent); callback(err, emailsSent);
}); });
function getTermTopics(term, uid, start, stop, callback) {
async.waterfall([
function (next) {
topics.getPopularTopics(term, uid, start, stop, next);
},
function (data, next) {
if (!data.topics.length) {
topics.getLatestTopics(uid, start, stop, term, next);
} else {
next(null, data);
}
},
function (data, next) {
next(null, data.topics);
},
], callback);
}
}; };

Loading…
Cancel
Save