From 05df8900db4fab06ede2b15c4e133c2ebfa17f72 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 16 Dec 2015 12:15:24 -0500 Subject: [PATCH] closes #3912 --- public/language/en_GB/notifications.json | 8 ++++++++ src/notifications.js | 20 +++++++++++++++----- src/socket.io/helpers.js | 3 ++- src/socket.io/posts/flag.js | 4 +++- src/socket.io/user.js | 3 ++- src/topics/follow.js | 4 +++- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/public/language/en_GB/notifications.json b/public/language/en_GB/notifications.json index 3048f082b9..0692155373 100644 --- a/public/language/en_GB/notifications.json +++ b/public/language/en_GB/notifications.json @@ -14,15 +14,23 @@ "new_message_from": "New message from %1", "upvoted_your_post_in": "%1 has upvoted your post in %2.", + "upvoted_your_post_in_dual": "%1 and %2 have upvoted your post in %3.", + "upvoted_your_post_in_multiple": "%1 and %2 others have upvoted your post in %3.", "moved_your_post": "%1 has moved your post to %2", "moved_your_topic": "%1 has moved %2", "favourited_your_post_in": "%1 has favourited your post in %2.", "favourited_your_post_in_dual": "%1 and %2 have favourited your post in %3.", "favourited_your_post_in_multiple": "%1 and %2 others have favourited your post in %3.", "user_flagged_post_in": "%1 flagged a post in %2", + "user_flagged_post_in_dual": "%1 and %2 flagged a post in %3", + "user_flagged_post_in_multiple": "%1 and %2 others flagged a post in %3", "user_posted_to" : "%1 has posted a reply to: %2", + "user_posted_to_dual" : "%1 and %2 have posted replies to: %3", + "user_posted_to_multiple" : "%1 and %2 others have posted replies to: %3", "user_posted_topic": "%1 has posted a new topic: %2", "user_started_following_you": "%1 started following you.", + "user_started_following_you_dual": "%1 and %2 started following you.", + "user_started_following_you_multiple": "%1 and %2 others started following you.", "new_register": "%1 sent a registration request.", "email-confirmed": "Email Confirmed", diff --git a/src/notifications.js b/src/notifications.js index ec77cb4a99..c09f438fc9 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -333,12 +333,18 @@ var async = require('async'), Notifications.merge = function(notifications, callback) { // When passed a set of notification objects, merge any that can be merged - var mergeIds = ['notifications:favourited_your_post_in'], + var mergeIds = [ + 'notifications:favourited_your_post_in', + 'notifications:upvoted_your_post_in', + 'notifications:user_started_following_you', + 'notifications:user_posted_to', + 'notifications:user_flagged_post_in' + ], isolated, modifyIndex; notifications = mergeIds.reduce(function(notifications, mergeId) { isolated = notifications.filter(function(notifObj) { - return notifObj.mergeId === mergeId; + return notifObj.mergeId.split('|')[0] === mergeId; }); if (isolated.length <= 1) { @@ -348,7 +354,11 @@ var async = require('async'), modifyIndex = notifications.indexOf(isolated[0]); switch(mergeId) { - case 'notifications:favourited_your_post_in': + case 'notifications:favourited_your_post_in': // intentional fall-through + case 'notifications:upvoted_your_post_in': + case 'notifications:user_started_following_you': + case 'notifications:user_posted_to': + case 'notifications:user_flagged_post_in': var usernames = isolated.map(function(notifObj) { return notifObj.user.username; }); @@ -356,9 +366,9 @@ var async = require('async'), // Update bodyShort if (numUsers === 2) { - isolated[0].bodyShort = '[[notifications:favourited_your_post_in_dual, ' + usernames.join(', ') + ', Welcome to your NodeBB!]]' + isolated[0].bodyShort = '[[' + mergeId.split('|') + '_dual, ' + usernames.join(', ') + ', ' + isolated[0].topicTitle + ']]' } else { - isolated[0].bodyShort = '[[notifications:favourited_your_post_in_multiple, ' + usernames[0] + ', ' + (numUsers-1) + ', Welcome to your NodeBB!]]' + isolated[0].bodyShort = '[[' + mergeId.split('|') + '_multiple, ' + usernames[0] + ', ' + (numUsers-1) + ', ' + isolated[0].topicTitle + ']]' } break; } diff --git a/src/socket.io/helpers.js b/src/socket.io/helpers.js index 19e46871b3..789ec1660a 100644 --- a/src/socket.io/helpers.js +++ b/src/socket.io/helpers.js @@ -70,7 +70,8 @@ SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification) pid: pid, nid: 'post:' + pid + ':uid:' + fromuid, from: fromuid, - mergeId: notification + mergeId: notification + '|' + postData.tid, + topicTitle: results.topicTitle }, function(err, notification) { if (!err && notification) { notifications.push(notification, [postData.uid]); diff --git a/src/socket.io/posts/flag.js b/src/socket.io/posts/flag.js index aa82e84626..d3f4007e01 100644 --- a/src/socket.io/posts/flag.js +++ b/src/socket.io/posts/flag.js @@ -84,7 +84,9 @@ module.exports = function(SocketPosts) { bodyLong: post.content, pid: data.pid, nid: 'post_flag:' + data.pid + ':uid:' + socket.uid, - from: socket.uid + from: socket.uid, + mergeId: 'notifications:user_flagged_post_in|' + data.pid, + topicTitle: post.topic.title }, function(err, notification) { if (err || !notification) { return next(err); diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 14b0c2c828..3a19d62d63 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -142,7 +142,8 @@ SocketUser.follow = function(socket, data, callback) { bodyShort: '[[notifications:user_started_following_you, ' + userData.username + ']]', nid: 'follow:' + data.uid + ':uid:' + socket.uid, from: socket.uid, - path: '/user/' + userData.userslug + path: '/user/' + userData.userslug, + mergeId: 'notifications:user_started_following_you' }, next); }, function(notification, next) { diff --git a/src/topics/follow.js b/src/topics/follow.js index e05a705c51..250f571dc4 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -137,7 +137,9 @@ module.exports = function(Topics) { pid: postData.pid, nid: 'new_post:tid:' + postData.topic.tid + ':pid:' + postData.pid + ':uid:' + exceptUid, tid: postData.topic.tid, - from: exceptUid + from: exceptUid, + mergeId: 'notifications:user_posted_to|' + postData.topic.tid, + topicTitle: title }, function(err, notification) { if (err) { return next(err);