mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
part of #3912
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
"moved_your_post": "<strong>%1</strong> has moved your post to <strong>%2</strong>",
|
||||
"moved_your_topic": "<strong>%1</strong> has moved <strong>%2</strong>",
|
||||
"favourited_your_post_in": "<strong>%1</strong> has favourited your post in <strong>%2</strong>.",
|
||||
"favourited_your_post_in_dual": "<strong>%1</strong> and <strong>%2</strong> have favourited your post in <strong>%3</strong>.",
|
||||
"favourited_your_post_in_multiple": "<strong>%1</strong> and %2 others have favourited your post in <strong>%3</strong>.",
|
||||
"user_flagged_post_in": "<strong>%1</strong> flagged a post in <strong>%2</strong>",
|
||||
"user_posted_to" : "<strong>%1</strong> has posted a reply to: <strong>%2</strong>",
|
||||
"user_posted_topic": "<strong>%1</strong> has posted a new topic: <strong>%2</strong>",
|
||||
|
||||
@@ -331,5 +331,50 @@ 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'],
|
||||
isolated, modifyIndex;
|
||||
|
||||
notifications = mergeIds.reduce(function(notifications, mergeId) {
|
||||
isolated = notifications.filter(function(notifObj) {
|
||||
return notifObj.mergeId === mergeId;
|
||||
});
|
||||
|
||||
if (isolated.length <= 1) {
|
||||
return notifications; // Nothing to merge
|
||||
}
|
||||
|
||||
modifyIndex = notifications.indexOf(isolated[0]);
|
||||
|
||||
switch(mergeId) {
|
||||
case 'notifications:favourited_your_post_in':
|
||||
var usernames = isolated.map(function(notifObj) {
|
||||
return notifObj.user.username;
|
||||
});
|
||||
var numUsers = usernames.length;
|
||||
|
||||
// Update bodyShort
|
||||
if (numUsers === 2) {
|
||||
isolated[0].bodyShort = '[[notifications:favourited_your_post_in_dual, ' + usernames.join(', ') + ', Welcome to your NodeBB!]]'
|
||||
} else {
|
||||
isolated[0].bodyShort = '[[notifications:favourited_your_post_in_multiple, ' + usernames[0] + ', ' + (numUsers-1) + ', Welcome to your NodeBB!]]'
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Filter out duplicates
|
||||
return notifications.filter(function(notifObj, idx) {
|
||||
return notifObj.mergeId !== mergeId || idx === modifyIndex;
|
||||
});
|
||||
}, notifications);
|
||||
|
||||
plugins.fireHook('filter:notifications.merge', {
|
||||
notifications: notifications
|
||||
}, function(err, data) {
|
||||
callback(err, data.notifications);
|
||||
});
|
||||
};
|
||||
|
||||
}(exports));
|
||||
|
||||
|
||||
@@ -69,7 +69,8 @@ SocketHelpers.sendNotificationToPostOwner = function(pid, fromuid, notification)
|
||||
bodyLong: results.postObj.content,
|
||||
pid: pid,
|
||||
nid: 'post:' + pid + ':uid:' + fromuid,
|
||||
from: fromuid
|
||||
from: fromuid,
|
||||
mergeId: notification
|
||||
}, function(err, notification) {
|
||||
if (!err && notification) {
|
||||
notifications.push(notification, [postData.uid]);
|
||||
|
||||
@@ -64,28 +64,21 @@ var async = require('async'),
|
||||
}
|
||||
|
||||
function getNotificationsFromSet(set, read, uid, start, stop, callback) {
|
||||
db.getSortedSetRevRange(set, start, stop, function(err, nids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(!Array.isArray(nids) || !nids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
UserNotifications.getNotifications(nids, uid, function(err, notifications) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
async.waterfall([
|
||||
async.apply(db.getSortedSetRevRange, set, start, stop),
|
||||
function(nids, next) {
|
||||
if(!Array.isArray(nids) || !nids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
UserNotifications.getNotifications(nids, uid, next);
|
||||
},
|
||||
function(notifs, next) {
|
||||
var deletedNids = [];
|
||||
|
||||
notifications.forEach(function(notification, index) {
|
||||
notifs.forEach(function(notification, index) {
|
||||
if (!notification) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
winston.info('[notifications.get] nid ' + nids[index] + ' not found. Removing.');
|
||||
}
|
||||
|
||||
winston.verbose('[notifications.get] nid ' + nids[index] + ' not found. Removing.');
|
||||
deletedNids.push(nids[index]);
|
||||
} else {
|
||||
notification.read = read;
|
||||
@@ -97,9 +90,9 @@ var async = require('async'),
|
||||
db.sortedSetRemove(set, deletedNids);
|
||||
}
|
||||
|
||||
callback(null, notifications);
|
||||
});
|
||||
});
|
||||
notifications.merge(notifs, next);
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
||||
UserNotifications.getNotifications = function(nids, uid, callback) {
|
||||
|
||||
Reference in New Issue
Block a user