From 44988f2a8b1803a3cd45197449aeea6a9e0386a2 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Wed, 15 May 2019 15:55:21 +0530 Subject: [PATCH 1/2] =?UTF-8?q?Github=20issue#115,=20Missing=20notificatio?= =?UTF-8?q?ns=20=E2=80=94=20Potential=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- connect/connectNotificationServer.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/connect/connectNotificationServer.js b/connect/connectNotificationServer.js index d581e09..dbb9d93 100644 --- a/connect/connectNotificationServer.js +++ b/connect/connectNotificationServer.js @@ -56,12 +56,13 @@ const getTopCoderMembersNotifications = (eventConfig) => { /** * Get notifications for mentioned users * + * @param {Object} logger object used to log in parent thread * @param {Object} eventConfig event configuration * @param {Object} message content * * @return {Promise} resolves to a list of notifications */ -const getNotificationsForMentionedUser = (eventConfig, content) => { +const getNotificationsForMentionedUser = (logger, eventConfig, content) => { if (!eventConfig.toMentionedUsers || !content) { return Promise.resolve([]); } @@ -93,6 +94,11 @@ const getNotificationsForMentionedUser = (eventConfig, content) => { notification.userId = mentionedUser ? mentionedUser.userId.toString() : notification.userHandle; }); resolve(notifications); + }).catch((error) => { + if (logger) { + logger.error(error); + } + reject(new Error('Unable to fetch details for mentioned user in the message.')); }); } else { resolve([]); @@ -249,6 +255,7 @@ const getNotificationsForTopicStarter = (eventConfig, topicId) => { /** * Exclude notifications using exclude rules of the event config * + * @param {Object} logger object used to log in parent thread * @param {Array} notifications notifications list * @param {Object} eventConfig event configuration * @param {Object} message message @@ -256,7 +263,7 @@ const getNotificationsForTopicStarter = (eventConfig, topicId) => { * * @returns {Promise} resolves to the list of filtered notifications */ -const excludeNotifications = (notifications, eventConfig, message, data) => { +const excludeNotifications = (logger, notifications, eventConfig, message, data) => { // if there are no rules to exclude notifications, just return all of them untouched if (!eventConfig.exclude) { return Promise.resolve(notifications); @@ -275,7 +282,7 @@ const excludeNotifications = (notifications, eventConfig, message, data) => { return Promise.all([ getNotificationsForTopicStarter(excludeEventConfig, message.topicId), getNotificationsForUserId(excludeEventConfig, message.userId), - getNotificationsForMentionedUser(eventConfig, message.postContent), + getNotificationsForMentionedUser(logger, excludeEventConfig, message.postContent), getProjectMembersNotifications(excludeEventConfig, project), getTopCoderMembersNotifications(excludeEventConfig), ]).then((notificationsPerSource) => ( @@ -335,7 +342,7 @@ const handler = (topic, message, logger, callback) => { getNotificationsForTopicStarter(eventConfig, message.topicId), getNotificationsForUserId(eventConfig, message.userId), getNotificationsForOriginator(eventConfig, message.originator), - getNotificationsForMentionedUser(eventConfig, message.postContent), + getNotificationsForMentionedUser(logger, eventConfig, message.postContent), getProjectMembersNotifications(eventConfig, project), getTopCoderMembersNotifications(eventConfig), ]).then((notificationsPerSource) => { @@ -344,7 +351,7 @@ const handler = (topic, message, logger, callback) => { logger.debug('all notifications: ', notificationsPerSource); return _.uniqBy(_.flatten(notificationsPerSource), 'userId'); }).then((notifications) => ( - excludeNotifications(notifications, eventConfig, message, { + excludeNotifications(logger, notifications, eventConfig, message, { project, }) )).then((notifications) => { From b82b726bc9c7392f6987f20d045ec091a9f73732 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Wed, 15 May 2019 17:36:32 +0530 Subject: [PATCH 2/2] Resolve the promise in case of error for fetching details for mentioned user to avoid skipping of notifications to other users --- connect/connectNotificationServer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/connect/connectNotificationServer.js b/connect/connectNotificationServer.js index dbb9d93..8bcbc3a 100644 --- a/connect/connectNotificationServer.js +++ b/connect/connectNotificationServer.js @@ -97,8 +97,10 @@ const getNotificationsForMentionedUser = (logger, eventConfig, content) => { }).catch((error) => { if (logger) { logger.error(error); + logger.info('Unable to send notification to mentioned user') } - reject(new Error('Unable to fetch details for mentioned user in the message.')); + //resolves with empty notification which essentially means we are unable to send notification to mentioned user + resolve([]); }); } else { resolve([]);