Skip to content

Node.js based forum software built for the modern web

re: #2098, chat message emails are now opt-in

Julian Lamb80b0e1e995b
diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.json
index 92d50ee4ab..2948c47292 100644
--- a/public/language/en_GB/user.json
+++ b/public/language/en_GB/user.json
@@ -57,6 +57,7 @@
"digest_daily": "Daily",
"digest_weekly": "Weekly",
"digest_monthly": "Monthly",
+ "send_chat_notifications": "Send an email if a new chat message arrives and I am not online",
"has_no_follower": "This user doesn't have any followers :(",
"follows_no_one": "This user isn't following anyone :(",
diff --git a/src/messaging.js b/src/messaging.js
index bbea385473..0d9d9ca3fb 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -376,13 +376,17 @@ var db = require('./database'),
}
});
- emailer.send('notif_chat', touid, {
- subject: '[[email:notif.chat.subject, ' + messageObj.fromUser.username + ']]',
- username: messageObj.toUser.username,
- summary: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
- message: messageObj,
- site_title: meta.config.site_title || 'NodeBB',
- url: nconf.get('url') + '/chats/' + utils.slugify(messageObj.fromUser.username)
+ user.getSettings(messageObj.toUser.uid, function(err, settings) {
+ if (settings.sendChatNotifications && !parseInt(meta.config.disableEmailSubscriptions, 10)) {
+ emailer.send('notif_chat', touid, {
+ subject: '[[email:notif.chat.subject, ' + messageObj.fromUser.username + ']]',
+ username: messageObj.toUser.username,
+ summary: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
+ message: messageObj,
+ site_title: meta.config.site_title || 'NodeBB',
+ url: nconf.get('url') + '/chats/' + utils.slugify(messageObj.fromUser.username)
+ });
+ }
});
}
}
diff --git a/src/user/settings.js b/src/user/settings.js
index 362019491a..a98a050006 100644
--- a/src/user/settings.js
+++ b/src/user/settings.js
@@ -35,6 +35,8 @@ module.exports = function(User) {
settings.topicPostSort = settings.topicPostSort || meta.config.topicPostSort || 'oldest_to_newest';
settings.followTopicsOnCreate = (settings.followTopicsOnCreate === null || settings.followTopicsOnCreate === undefined) ? true : parseInt(settings.followTopicsOnCreate, 10) === 1;
settings.followTopicsOnReply = parseInt(settings.followTopicsOnReply, 10) === 1;
+ settings.sendChatNotifications = parseInt(settings.sendChatNotifications, 10) === 1;
+
callback(null, settings);
});
});
@@ -83,7 +85,8 @@ module.exports = function(User) {
notificationSounds: data.notificationSounds,
language: data.language || meta.config.defaultLang,
followTopicsOnCreate: data.followTopicsOnCreate,
- followTopicsOnReply: data.followTopicsOnReply
+ followTopicsOnReply: data.followTopicsOnReply,
+ sendChatNotifications: data.sendChatNotifications
}, callback);
};