mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-15 10:16:12 +01:00
Merge branch 'issue-1249'
This commit is contained in:
@@ -69,6 +69,6 @@
|
|||||||
"invisible": "Invisible",
|
"invisible": "Invisible",
|
||||||
"offline": "Offline",
|
"offline": "Offline",
|
||||||
|
|
||||||
"privacy": "Privacy",
|
"email": "Email",
|
||||||
"language": "Language"
|
"language": "Language"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,12 @@
|
|||||||
|
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"show_email": "Show My Email",
|
"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 :(",
|
"has_no_follower": "This user doesn't have any followers :(",
|
||||||
"follows_no_one": "This user isn't following anyone :(",
|
"follows_no_one": "This user isn't following anyone :(",
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ define(['forum/accountheader'], function(header) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (input.attr('type')) {
|
switch (input.attr('type')) {
|
||||||
case 'text' :
|
case 'text':
|
||||||
case 'textarea' :
|
case 'textarea':
|
||||||
settings[setting] = input.val();
|
settings[setting] = input.val();
|
||||||
break;
|
break;
|
||||||
case 'checkbox' :
|
case 'checkbox':
|
||||||
settings[setting] = input.is(':checked') ? 1 : 0;
|
settings[setting] = input.is(':checked') ? 1 : 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ module.exports = function(app, middleware, controllers) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/test', function(req, res) {
|
app.get('/test', function(req, res) {
|
||||||
require('../meta').sounds.init();
|
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ var db = require('../database'),
|
|||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
|
|
||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
UserNotifications = require('./notifications'),
|
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
emailer = require('../emailer'),
|
emailer = require('../emailer'),
|
||||||
meta = require('../meta');
|
meta = require('../meta');
|
||||||
@@ -23,6 +22,8 @@ module.exports = function(User) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
User.sendDailyDigests = function() {
|
User.sendDailyDigests = function() {
|
||||||
|
var yesterday = Date.now() - (1000*60*60*24);
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
recent: function(next) {
|
recent: function(next) {
|
||||||
topics.getLatestTopics(0, 0, 10, 'day', next);
|
topics.getLatestTopics(0, 0, 10, 'day', next);
|
||||||
@@ -33,39 +34,61 @@ module.exports = function(User) {
|
|||||||
}, function(err, data) {
|
}, function(err, data) {
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
|
|
||||||
async.each(data.uids, function(uid, next) {
|
async.parallel({
|
||||||
UserNotifications.getDailyUnread(uid, function(err, notifications) {
|
recipients: function(next) {
|
||||||
if (!err && notifications && notifications.length) {
|
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<notifications.length; ++i) {
|
for(var i=0; i<notifications.length; ++i) {
|
||||||
if (notifications[i].image.indexOf('http') !== 0) {
|
if (notifications[i].image.indexOf('http') !== 0) {
|
||||||
notifications[i].image = nconf.get('url') + notifications[i].image;
|
notifications[i].image = nconf.get('url') + notifications[i].image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
user.getUserField(uid, 'username', function(err, username) {
|
// Send daily digest email
|
||||||
// Send daily digest email
|
// winston.info('[user/notifications] Sending Daily Digest to uid ' + userObj.uid);
|
||||||
// winston.info('[user/notifications] Sending Daily Digest to uid ' + uid);
|
emailer.send('dailydigest', userObj.uid, {
|
||||||
emailer.send('dailydigest', uid, {
|
subject: '[' + meta.config.title + '] Daily Digest for ' + now.getFullYear()+ '/' + (now.getMonth()+1) + '/' + now.getDate(),
|
||||||
subject: '[' + meta.config.title + '] Daily Digest for ' + now.getFullYear()+ '/' + (now.getMonth()+1) + '/' + now.getDate(),
|
username: userObj.username,
|
||||||
username: username,
|
url: nconf.get('url'),
|
||||||
url: nconf.get('url'),
|
site_title: meta.config.title,
|
||||||
site_title: meta.config.title,
|
notifications: notifications,
|
||||||
notifications: notifications,
|
recent: data.recent.topics
|
||||||
recent: data.recent.topics
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
next(err);
|
next(err);
|
||||||
|
});
|
||||||
|
}, function(err) {
|
||||||
|
// When finished...
|
||||||
|
if (!err) {
|
||||||
|
winston.info('[user/jobs] Daily Digests sent!');
|
||||||
|
} else {
|
||||||
|
winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, function(err) {
|
|
||||||
// When finished...
|
|
||||||
if (!err) {
|
|
||||||
winston.info('[user/jobs] Daily Digests sent!');
|
|
||||||
} else {
|
|
||||||
winston.error('[user/jobs] Could not send daily digests: ' + err.message);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ module.exports = function(User) {
|
|||||||
settings = data.settings;
|
settings = data.settings;
|
||||||
|
|
||||||
settings.showemail = settings.showemail ? parseInt(settings.showemail, 10) !== 0 : false;
|
settings.showemail = settings.showemail ? parseInt(settings.showemail, 10) !== 0 : false;
|
||||||
|
settings.dailyDigestFreq = settings.dailyDigestFreq || 'daily';
|
||||||
settings.usePagination = settings.usePagination ? parseInt(settings.usePagination, 10) === 1 : parseInt(meta.config.usePagination, 10) === 1;
|
settings.usePagination = settings.usePagination ? parseInt(settings.usePagination, 10) === 1 : parseInt(meta.config.usePagination, 10) === 1;
|
||||||
settings.topicsPerPage = settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20;
|
settings.topicsPerPage = settings.topicsPerPage ? parseInt(settings.topicsPerPage, 10) : parseInt(meta.config.topicsPerPage, 10) || 20;
|
||||||
settings.postsPerPage = settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10;
|
settings.postsPerPage = settings.postsPerPage ? parseInt(settings.postsPerPage, 10) : parseInt(meta.config.postsPerPage, 10) || 10;
|
||||||
@@ -35,16 +36,43 @@ module.exports = function(User) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
User.getMultipleUserSettings = function(uids, callback) {
|
||||||
|
if (!Array.isArray(uids) || !uids.length) {
|
||||||
|
return callback(null, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
var keys = uids.map(function(uid) {
|
||||||
|
return 'user:' + uid + ':settings';
|
||||||
|
});
|
||||||
|
|
||||||
|
db.getObjects(keys, function(err, settings) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Associate uid
|
||||||
|
settings = settings.map(function(setting, idx) {
|
||||||
|
setting = setting || {};
|
||||||
|
setting.uid = uids[idx];
|
||||||
|
return setting;
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, settings);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
User.saveSettings = function(uid, data, callback) {
|
User.saveSettings = function(uid, data, callback) {
|
||||||
|
|
||||||
if(!data.topicsPerPage || !data.postsPerPage || parseInt(data.topicsPerPage, 10) <= 0 || parseInt(data.postsPerPage, 10) <= 0) {
|
if(!data.topicsPerPage || !data.postsPerPage || parseInt(data.topicsPerPage, 10) <= 0 || parseInt(data.postsPerPage, 10) <= 0) {
|
||||||
return callback(new Error('[[error:invalid-pagination-value]]'));
|
return callback(new Error('[[error:invalid-pagination-value]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data});
|
data.language = data.language || meta.config.defaultLang;
|
||||||
|
|
||||||
|
plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data});
|
||||||
db.setObject('user:' + uid + ':settings', {
|
db.setObject('user:' + uid + ':settings', {
|
||||||
showemail: data.showemail,
|
showemail: data.showemail,
|
||||||
|
dailyDigestFreq: data.dailyDigestFreq || 'daily',
|
||||||
usePagination: data.usePagination,
|
usePagination: data.usePagination,
|
||||||
topicsPerPage: data.topicsPerPage,
|
topicsPerPage: data.topicsPerPage,
|
||||||
postsPerPage: data.postsPerPage,
|
postsPerPage: data.postsPerPage,
|
||||||
|
|||||||
Reference in New Issue
Block a user