mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 00:15:46 +01:00
optimize notifications.getMultiple
This commit is contained in:
@@ -37,50 +37,41 @@ var utils = require('../public/src/utils');
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(notifications) || !notifications.length) {
|
notifications = notifications.filter(Boolean);
|
||||||
|
if (!notifications.length) {
|
||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.map(notifications, function(notification, next) {
|
var userKeys = notifications.map(function(notification) {
|
||||||
if (!notification) {
|
return notification.from;
|
||||||
return next(null, null);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
User.getUsersFields(userKeys, ['username', 'userslug', 'picture'], function(err, usersData) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
notifications.forEach(function(notification, index) {
|
||||||
notification.datetimeISO = utils.toISOString(notification.datetime);
|
notification.datetimeISO = utils.toISOString(notification.datetime);
|
||||||
|
|
||||||
if (notification.bodyLong) {
|
if (notification.bodyLong) {
|
||||||
notification.bodyLong = S(notification.bodyLong).escapeHTML().s;
|
notification.bodyLong = S(notification.bodyLong).escapeHTML().s;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notification.from && !notification.image) {
|
notification.user = usersData[index];
|
||||||
User.getUserFields(notification.from, ['username', 'userslug', 'picture'], function(err, userData) {
|
if (notification.user) {
|
||||||
if (err) {
|
notification.image = notification.user.picture || null;
|
||||||
return next(err);
|
if (notification.user.username === '[[global:guest]]') {
|
||||||
}
|
|
||||||
notification.image = userData.picture || null;
|
|
||||||
notification.user = userData;
|
|
||||||
|
|
||||||
if (userData.username === '[[global:guest]]') {
|
|
||||||
notification.bodyShort = notification.bodyShort.replace(/([\s\S]*?),[\s\S]*?,([\s\S]*?)/, '$1, [[global:guest]], $2');
|
notification.bodyShort = notification.bodyShort.replace(/([\s\S]*?),[\s\S]*?,([\s\S]*?)/, '$1, [[global:guest]], $2');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
next(null, notification);
|
if (notification.image === 'brand:logo' || !notification.image) {
|
||||||
|
notification.image = meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
} else if (notification.image) {
|
|
||||||
switch(notification.image) {
|
|
||||||
case 'brand:logo':
|
|
||||||
notification.image = meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return next(null, notification);
|
callback(null, notifications);
|
||||||
} else {
|
});
|
||||||
notification.image = meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png';
|
|
||||||
return next(null, notification);
|
|
||||||
}
|
|
||||||
|
|
||||||
}, callback);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user