Skip to content

Commit febce84

Browse files
author
Vikas Agarwal
committed
Github issue#115, Missing notifications
— Potential fix
1 parent 8fc97a7 commit febce84

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

connect/connectNotificationServer.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ const getTopCoderMembersNotifications = (eventConfig) => {
5656
/**
5757
* Get notifications for mentioned users
5858
*
59+
* @param {Object} logger object used to log in parent thread
5960
* @param {Object} eventConfig event configuration
6061
* @param {Object} message content
6162
*
6263
* @return {Promise} resolves to a list of notifications
6364
*/
64-
const getNotificationsForMentionedUser = (eventConfig, content) => {
65+
const getNotificationsForMentionedUser = (logger, eventConfig, content) => {
6566
if (!eventConfig.toMentionedUsers || !content) {
6667
return Promise.resolve([]);
6768
}
@@ -93,6 +94,11 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
9394
notification.userId = mentionedUser ? mentionedUser.userId.toString() : notification.userHandle;
9495
});
9596
resolve(notifications);
97+
}).catch((error) => {
98+
if (logger) {
99+
logger.error(error);
100+
}
101+
reject(new Error('Unable to fetch details for mentioned user in the message.'));
96102
});
97103
} else {
98104
resolve([]);
@@ -249,14 +255,15 @@ const getNotificationsForTopicStarter = (eventConfig, topicId) => {
249255
/**
250256
* Exclude notifications using exclude rules of the event config
251257
*
258+
* @param {Object} logger object used to log in parent thread
252259
* @param {Array} notifications notifications list
253260
* @param {Object} eventConfig event configuration
254261
* @param {Object} message message
255262
* @param {Object} data any additional data which is retrieved once
256263
*
257264
* @returns {Promise} resolves to the list of filtered notifications
258265
*/
259-
const excludeNotifications = (notifications, eventConfig, message, data) => {
266+
const excludeNotifications = (logger, notifications, eventConfig, message, data) => {
260267
// if there are no rules to exclude notifications, just return all of them untouched
261268
if (!eventConfig.exclude) {
262269
return Promise.resolve(notifications);
@@ -275,7 +282,7 @@ const excludeNotifications = (notifications, eventConfig, message, data) => {
275282
return Promise.all([
276283
getNotificationsForTopicStarter(excludeEventConfig, message.topicId),
277284
getNotificationsForUserId(excludeEventConfig, message.userId),
278-
getNotificationsForMentionedUser(eventConfig, message.postContent),
285+
getNotificationsForMentionedUser(logger, excludeEventConfig, message.postContent),
279286
getProjectMembersNotifications(excludeEventConfig, project),
280287
getTopCoderMembersNotifications(excludeEventConfig),
281288
]).then((notificationsPerSource) => (
@@ -335,7 +342,7 @@ const handler = (topic, message, logger, callback) => {
335342
getNotificationsForTopicStarter(eventConfig, message.topicId),
336343
getNotificationsForUserId(eventConfig, message.userId),
337344
getNotificationsForOriginator(eventConfig, message.originator),
338-
getNotificationsForMentionedUser(eventConfig, message.postContent),
345+
getNotificationsForMentionedUser(logger, eventConfig, message.postContent),
339346
getProjectMembersNotifications(eventConfig, project),
340347
getTopCoderMembersNotifications(eventConfig),
341348
]).then((notificationsPerSource) => {
@@ -344,7 +351,7 @@ const handler = (topic, message, logger, callback) => {
344351
logger.debug('all notifications: ', notificationsPerSource);
345352
return _.uniqBy(_.flatten(notificationsPerSource), 'userId');
346353
}).then((notifications) => (
347-
excludeNotifications(notifications, eventConfig, message, {
354+
excludeNotifications(logger, notifications, eventConfig, message, {
348355
project,
349356
})
350357
)).then((notifications) => {

0 commit comments

Comments
 (0)