|
|
|
@ -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);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|