From b80b0e1e995b8297046861a54e841633f6d699b9 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 16 Sep 2014 13:54:03 -0400 Subject: [PATCH] re: #2098, chat message emails are now opt-in --- public/language/en_GB/user.json | 1 + src/messaging.js | 18 +++++++++++------- src/user/settings.js | 5 ++++- 3 files changed, 16 insertions(+), 8 deletions(-) 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); };