v1.18.x
Julian Lam 8 years ago
parent 77d6181bd1
commit e309ac5040

@ -90,7 +90,7 @@ module.exports = function (Topics) {
], callback);
}
/* not an orphan method, used in widget-essentials */
Topics.getLatestTopics = function (uid, start, stop, term, callback) {
async.waterfall([
function (next) {

@ -11,7 +11,7 @@ module.exports = {
var progress = this.progress;
batch.processSortedSet('users:joindate', function (uids, next) {
async.eachSeries(uids, function (uid, next) {
async.eachLimit(uids, 500, function (uid, next) {
progress.incr();
db.deleteObjectField('user:' + uid, 'rss_token', next);
}, next);

@ -26,41 +26,29 @@ Digest.execute = function (payload, callback) {
var subscribers;
async.waterfall([
function (next) {
async.parallel({
topics: async.apply(topics.getLatestTopics, 0, 0, 9, payload.interval),
subscribers: function (next) {
if (payload.subscribers) {
setImmediate(next, undefined, payload.subscribers);
} else {
Digest.getSubscribers(payload.interval, next);
}
},
}, next);
},
function (data, next) {
subscribers = data.subscribers;
if (!data.subscribers.length) {
function (subscribers, next) {
if (!subscribers.length) {
return callback();
}
// Fix relative paths in topic data
data.topics.topics = data.topics.topics.map(function (topicObj) {
var user = topicObj.hasOwnProperty('teaser') && topicObj.teaser !== undefined ? topicObj.teaser.user : topicObj.user;
if (user && user.picture && utils.isRelativeUrl(user.picture)) {
user.picture = nconf.get('base_url') + user.picture;
}
return topicObj;
});
var data = {
interval: payload.interval,
subscribers: subscribers,
};
data.interval = payload.interval;
Digest.send(data, next);
},
], function (err) {
], function (err, count) {
if (err) {
winston.error('[user/jobs] Could not send digests (' + payload.interval + '): ' + err.message);
} else {
winston.info('[user/jobs] Digest (' + payload.interval + ') scheduling completed. ' + subscribers.length + ' email(s) sent.');
winston.info('[user/jobs] Digest (' + payload.interval + ') scheduling completed. ' + count + ' email(s) sent.');
}
callback(err);
@ -116,12 +104,16 @@ Digest.send = function (data, callback) {
async.eachLimit(users, 100, function (userObj, next) {
async.waterfall([
function (next) {
user.notifications.getDailyUnread(userObj.uid, next);
async.parallel({
notifications: async.apply(user.notifications.getDailyUnread, userObj.uid),
topics: async.apply(topics.getPopular, data.interval, userObj.uid, 10),
}, next);
},
function (notifications, next) {
notifications = notifications.filter(Boolean);
function (data, next) {
var notifications = data.notifications.filter(Boolean);
// If there are no notifications and no new topics, don't bother sending a digest
if (!notifications.length && !data.topics.topics.length) {
if (!notifications.length && !data.topics.length) {
return next();
}
@ -131,6 +123,16 @@ Digest.send = function (data, callback) {
}
});
// Fix relative paths in topic data
data.topics = data.topics.map(function (topicObj) {
var user = topicObj.hasOwnProperty('teaser') && topicObj.teaser !== undefined ? topicObj.teaser.user : topicObj.user;
if (user && user.picture && utils.isRelativeUrl(user.picture)) {
user.picture = nconf.get('base_url') + user.picture;
}
return topicObj;
});
emailer.send('digest', userObj.uid, {
subject: '[' + meta.config.title + '] [[email:digest.subject, ' + (now.getFullYear() + '/' + (now.getMonth() + 1) + '/' + now.getDate()) + ']]',
username: userObj.username,
@ -138,7 +140,7 @@ Digest.send = function (data, callback) {
url: nconf.get('url'),
site_title: meta.config.title || meta.config.browserTitle || 'NodeBB',
notifications: notifications,
recent: data.topics.topics,
recent: data.topics,
interval: data.interval,
});
next();
@ -147,6 +149,6 @@ Digest.send = function (data, callback) {
}, next);
},
], function (err) {
callback(err);
callback(err, data.subscribers.length);
});
};

Loading…
Cancel
Save