diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f7bc8aeb7..c602661541 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,14 @@ +# Submitting a Pull Request to NodeBB? + +First of all, thank you! Please consider this [style guide](https://docs.nodebb.org/en/latest/contributing/style-guide.html) when submitting your changes. Also, please join our [community](https://community.nodebb.org) to meet other NodeBB developers and designers :) + +## Contributor License Agreement + +Thank you for considering contributing to NodeBB. **Before we can accept any pull requests, please take a moment to read and sign our [license agreement](https://www.clahub.com/agreements/NodeBB/NodeBB)**. In summary, signing this document means that 1) you own the code that you are contributing and 2) you give permission to NodeBB Inc. to license the code to others. This agreement applies to any repository under the NodeBB organization. + +If you are writing contributions as part of employment from another company / individual, then your employer will need to sign a separate agreement. Please [contact us](mailto:accounts@nodebb.org) so that we can send this additional agreement to your employer. + + # Having problems installing NodeBB? Chances are somebody has run into this problem before. After consulting our [documentation](https://docs.nodebb.org/en/latest/installing/os.html), please head over to our [community support forum](https://community.nodebb.org) for advice. @@ -44,8 +55,3 @@ If you have downloaded the `.zip` or `.tar.gz` packages from GitHub (or elsewher If you have installed NodeBB via GitHub clone, are familiar with utilising git, and are willing to help us narrow down the specific commit that causes a bug, consider running `git bisect`. A full guide can be found here: [Debugging with Git/Binary Search](http://git-scm.com/book/en/Git-Tools-Debugging-with-Git#Binary-Search) - - -# Submitting a Pull Request to NodeBB? - -First of all, thank you! Please consider this [style guide](https://docs.nodebb.org/en/latest/contributing/style-guide.html) when submitting your changes. Also, please join our [community](https://community.nodebb.org) to meet other NodeBB developers and designers :) diff --git a/package.json b/package.json index 1efe0580c4..c46f966b43 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "nconf": "~0.7.1", "nodebb-plugin-dbsearch": "^0.1.0", "nodebb-plugin-markdown": "^0.8.0", - "nodebb-plugin-mentions": "^0.7.0", + "nodebb-plugin-mentions": "^0.9.0", "nodebb-plugin-soundpack-default": "~0.1.1", "nodebb-plugin-spam-be-gone": "^0.4.0", "nodebb-theme-lavender": "^0.2.0", diff --git a/public/language/en_GB/email.json b/public/language/en_GB/email.json index 75813bcb58..efee400748 100644 --- a/public/language/en_GB/email.json +++ b/public/language/en_GB/email.json @@ -23,6 +23,9 @@ "notif.chat.cta": "Click here to continue the conversation", "notif.chat.unsub.info": "This chat notification was sent to you due to your subscription settings.", + "notif.post.cta": "Click here to read the full topic", + "notif.post.unsub.info": "This post notification was sent to you due to your subscription settings.", + "test.text1": "This is a test email to verify that the emailer is set up correctly for your NodeBB.", "unsub.cta": "Click here to alter those settings", diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.json index 9ee1bbfefc..9c32b2d26e 100644 --- a/public/language/en_GB/user.json +++ b/public/language/en_GB/user.json @@ -64,6 +64,7 @@ "digest_weekly": "Weekly", "digest_monthly": "Monthly", "send_chat_notifications": "Send an email if a new chat message arrives and I am not online", + "send_post_notifications": "Send an email when replies are made to topics I am subscribed to", "has_no_follower": "This user doesn't have any followers :(", "follows_no_one": "This user isn't following anyone :(", diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index 6303ca8864..8e21928498 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -127,32 +127,31 @@ define('forum/topic/posts', [ html.hide().fadeIn('slow'); - $(window).trigger('action:posts.loaded'); - onNewPostsLoaded(html, data.posts); + var pids = []; + for(var i=0; i 6) { - otherCount = data[0].length - 5; - data[0] = data[0].slice(0, 5); - } - user.getUsernamesByUids(data[0], function(err, usernames) { - callback(err, { - otherCount: otherCount, - usernames: usernames + + async.map(data, function(uids, next) { + var otherCount = 0; + if (uids.length > 6) { + otherCount = uids.length - 5; + uids = uids.slice(0, 5); + } + user.getUsernamesByUids(uids, function(err, usernames) { + next(err, { + otherCount: otherCount, + usernames: usernames + }); }); - }); + }, callback); }); }; diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index c7c59e642b..9f96f17f29 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -396,7 +396,7 @@ SocketTopics.moveAll = function(socket, data, callback) { }); }; -SocketTopics.follow = function(socket, tid, callback) { +SocketTopics.toggleFollow = function(socket, tid, callback) { if(!socket.uid) { return callback(new Error('[[error:not-logged-in]]')); } @@ -404,6 +404,14 @@ SocketTopics.follow = function(socket, tid, callback) { topics.toggleFollow(tid, socket.uid, callback); }; +SocketTopics.follow = function(socket, tid, callback) { + if(!socket.uid) { + return callback(new Error('[[error:not-logged-in]]')); + } + + topics.follow(tid, socket.uid, callback); +}; + SocketTopics.loadMore = function(socket, data, callback) { if(!data || !data.tid || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) { return callback(new Error('[[error:invalid-data]]')); diff --git a/src/topics/follow.js b/src/topics/follow.js index 00785ffd77..7d88c9752e 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -4,12 +4,15 @@ var async = require('async'), nconf = require('nconf'), S = require('string'), + winston = require('winston'), db = require('../database'), user = require('../user'), posts = require('../posts'), postTools = require('../postTools'), - notifications = require('../notifications'); + notifications = require('../notifications'), + meta = require('../meta'), + emailer = require('../emailer'); module.exports = function(Topics) { @@ -125,6 +128,28 @@ module.exports = function(Topics) { notifications.push(notification, followers); } }); + + async.eachLimit(followers, 3, function(toUid, next) { + async.parallel({ + userData: async.apply(user.getUserFields, toUid, ['username']), + userSettings: async.apply(user.getSettings, toUid) + }, function(err, data) { + if (data.userSettings.hasOwnProperty('sendPostNotifications') && data.userSettings.sendPostNotifications) { + emailer.send('notif_post', toUid, { + pid: postData.pid, + subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title, + intro: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + title + ']]', + postBody: postData.content, + site_title: meta.config.title || 'NodeBB', + username: data.userData.username, + url: nconf.get('url') + '/topics/' + postData.topic.tid, + base_url: nconf.get('url') + }, next); + } else { + winston.debug('[topics.notifyFollowers] uid ' + toUid + ' does not have post notifications enabled, skipping.'); + } + }); + }); }); }; }; \ No newline at end of file diff --git a/src/user/settings.js b/src/user/settings.js index 9ac714ea6e..9f3e1166eb 100644 --- a/src/user/settings.js +++ b/src/user/settings.js @@ -69,6 +69,7 @@ module.exports = function(User) { 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; + settings.sendPostNotifications = parseInt(settings.sendPostNotifications, 10) === 1; settings.restrictChat = parseInt(settings.restrictChat, 10) === 1; settings.topicSearchEnabled = parseInt(settings.topicSearchEnabled, 10) === 1; diff --git a/src/views/emails/notif_post.tpl b/src/views/emails/notif_post.tpl new file mode 100644 index 0000000000..1f91d044be --- /dev/null +++ b/src/views/emails/notif_post.tpl @@ -0,0 +1,16 @@ +

[[email:greeting_with_name, {username}]],

+ +

{intro}:

+
{postBody}
+ +[[email:notif.post.cta]] + +

+ [[email:closing]]
+ {site_title} +

+ +
+

+ [[email:notif.post.unsub.info]] [[email:unsub.cta]]. +

\ No newline at end of file diff --git a/src/views/emails/notif_post_plaintext.tpl b/src/views/emails/notif_post_plaintext.tpl new file mode 100644 index 0000000000..0920b2f79e --- /dev/null +++ b/src/views/emails/notif_post_plaintext.tpl @@ -0,0 +1,14 @@ +[[email:greeting_with_name, {username}]], + +{intro}: + +{postBody} + +[[email:notif.post.cta]]: {url} + +[[email:closing]] +{site_title} + +=== + +[[email:notif.post.unsub.info]] [[email:unsub.cta]]. \ No newline at end of file