mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
first pass #1249 -- this causes emails to be sent if you have not been to the site in over 24 hours.
This commit is contained in:
@@ -54,7 +54,7 @@ module.exports = function(app, middleware, controllers) {
|
||||
});
|
||||
|
||||
app.get('/test', function(req, res) {
|
||||
require('../meta').sounds.init();
|
||||
user.sendDailyDigests();
|
||||
res.send(200);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,6 @@ var db = require('../database'),
|
||||
nconf = require('nconf'),
|
||||
|
||||
user = require('../user'),
|
||||
UserNotifications = require('./notifications'),
|
||||
topics = require('../topics'),
|
||||
emailer = require('../emailer'),
|
||||
meta = require('../meta');
|
||||
@@ -23,6 +22,8 @@ module.exports = function(User) {
|
||||
};
|
||||
|
||||
User.sendDailyDigests = function() {
|
||||
var yesterday = Date.now() - (1000*60*60*24);
|
||||
|
||||
async.parallel({
|
||||
recent: function(next) {
|
||||
topics.getLatestTopics(0, 0, 10, 'day', next);
|
||||
@@ -33,29 +34,32 @@ module.exports = function(User) {
|
||||
}, function(err, data) {
|
||||
var now = new Date();
|
||||
|
||||
async.each(data.uids, function(uid, next) {
|
||||
UserNotifications.getDailyUnread(uid, function(err, notifications) {
|
||||
if (!err && notifications && notifications.length) {
|
||||
// Consider using eachLimit, but *only* if people complain about email relays choking -- otherwise we're ok.
|
||||
User.getMultipleUserFields(data.uids, ['uid', 'username', 'lastonline'], function(err, receipients) {
|
||||
// Find only those users who have not been online in the past 24 hours
|
||||
var users = receipients.filter(function(userObj) {
|
||||
return yesterday > parseInt(userObj.lastonline, 10);
|
||||
});
|
||||
|
||||
async.each(users, function(userObj, next) {
|
||||
user.notifications.getDailyUnread(userObj.uid, function(err, notifications) {
|
||||
// Turn relative URLs into absolute ones
|
||||
for(var i=0; i<notifications.length; ++i) {
|
||||
if (notifications[i].image.indexOf('http') !== 0) {
|
||||
notifications[i].image = nconf.get('url') + notifications[i].image;
|
||||
}
|
||||
}
|
||||
|
||||
user.getUserField(uid, 'username', function(err, username) {
|
||||
// Send daily digest email
|
||||
// winston.info('[user/notifications] Sending Daily Digest to uid ' + uid);
|
||||
emailer.send('dailydigest', uid, {
|
||||
// winston.info('[user/notifications] Sending Daily Digest to uid ' + userObj.uid);
|
||||
emailer.send('dailydigest', userObj.uid, {
|
||||
subject: '[' + meta.config.title + '] Daily Digest for ' + now.getFullYear()+ '/' + (now.getMonth()+1) + '/' + now.getDate(),
|
||||
username: username,
|
||||
username: userObj.username,
|
||||
url: nconf.get('url'),
|
||||
site_title: meta.config.title,
|
||||
notifications: notifications,
|
||||
recent: data.recent.topics
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
next(err);
|
||||
});
|
||||
@@ -68,6 +72,7 @@ module.exports = function(User) {
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user