diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.json index c935f1c5d8..de15a7e4ce 100644 --- a/public/language/en_GB/global.json +++ b/public/language/en_GB/global.json @@ -69,6 +69,6 @@ "invisible": "Invisible", "offline": "Offline", - "privacy": "Privacy", + "email": "Email", "language": "Language" } diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.json index 1ca6651efb..a9a384da43 100644 --- a/public/language/en_GB/user.json +++ b/public/language/en_GB/user.json @@ -47,6 +47,12 @@ "settings": "Settings", "show_email": "Show My Email", + "digest_label": "Subscribe to Digest", + "digest_description": "Subscribe to email updates for this forum (new notifications and topics) according to a set schedule", + "digest_off": "Off", + "digest_daily": "Daily", + "digest_weekly": "Weekly", + "digest_monthly": "Monthly", "has_no_follower": "This user doesn't have any followers :(", "follows_no_one": "This user isn't following anyone :(", diff --git a/public/src/forum/accountsettings.js b/public/src/forum/accountsettings.js index bb18cacb2c..4945eb8abb 100644 --- a/public/src/forum/accountsettings.js +++ b/public/src/forum/accountsettings.js @@ -16,11 +16,11 @@ define(['forum/accountheader'], function(header) { } switch (input.attr('type')) { - case 'text' : - case 'textarea' : + case 'text': + case 'textarea': settings[setting] = input.val(); break; - case 'checkbox' : + case 'checkbox': settings[setting] = input.is(':checked') ? 1 : 0; break; } diff --git a/src/routes/debug.js b/src/routes/debug.js index 6c03961251..ca7a13b665 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -54,7 +54,6 @@ module.exports = function(app, middleware, controllers) { }); app.get('/test', function(req, res) { - require('../meta').sounds.init(); res.send(200); }); }); diff --git a/src/user/jobs.js b/src/user/jobs.js index 602b889039..c2e88e752f 100644 --- a/src/user/jobs.js +++ b/src/user/jobs.js @@ -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,39 +34,61 @@ 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) { + async.parallel({ + recipients: function(next) { + User.getMultipleUserFields(data.uids, ['uid', 'username', 'lastonline'], next); + }, + userSettings: function(next) { + User.getMultipleUserSettings(data.uids, next); + } + }, function(err, users) { + var recipients = users.recipients, + userSettings = users.userSettings, + subscribed; + // Find uids subscribed to daily digest emails + subscribed = userSettings.filter(function(setting) { + return !setting.dailyDigestFreq || setting.dailyDigestFreq === 'daily'; + }).map(function(setting) { + return setting.uid; + }); + + // Find only those users who have not been online in the past 24 hours + var users = recipients.filter(function(userObj) { + return subscribed.indexOf(userObj.uid) !== -1 && yesterday > parseInt(userObj.lastonline, 10); + }); + + // Consider using eachLimit, but *only* if people complain about email relays choking -- otherwise we're ok. + 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