@@ -56,12 +56,13 @@ const getTopCoderMembersNotifications = (eventConfig) => {
56
56
/**
57
57
* Get notifications for mentioned users
58
58
*
59
+ * @param {Object } logger object used to log in parent thread
59
60
* @param {Object } eventConfig event configuration
60
61
* @param {Object } message content
61
62
*
62
63
* @return {Promise } resolves to a list of notifications
63
64
*/
64
- const getNotificationsForMentionedUser = ( eventConfig , content ) => {
65
+ const getNotificationsForMentionedUser = ( logger , eventConfig , content ) => {
65
66
if ( ! eventConfig . toMentionedUsers || ! content ) {
66
67
return Promise . resolve ( [ ] ) ;
67
68
}
@@ -93,6 +94,13 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
93
94
notification . userId = mentionedUser ? mentionedUser . userId . toString ( ) : notification . userHandle ;
94
95
} ) ;
95
96
resolve ( notifications ) ;
97
+ } ) . catch ( ( error ) => {
98
+ if ( logger ) {
99
+ logger . error ( error ) ;
100
+ logger . info ( 'Unable to send notification to mentioned user' )
101
+ }
102
+ //resolves with empty notification which essentially means we are unable to send notification to mentioned user
103
+ resolve ( [ ] ) ;
96
104
} ) ;
97
105
} else {
98
106
resolve ( [ ] ) ;
@@ -249,14 +257,15 @@ const getNotificationsForTopicStarter = (eventConfig, topicId) => {
249
257
/**
250
258
* Exclude notifications using exclude rules of the event config
251
259
*
260
+ * @param {Object } logger object used to log in parent thread
252
261
* @param {Array } notifications notifications list
253
262
* @param {Object } eventConfig event configuration
254
263
* @param {Object } message message
255
264
* @param {Object } data any additional data which is retrieved once
256
265
*
257
266
* @returns {Promise } resolves to the list of filtered notifications
258
267
*/
259
- const excludeNotifications = ( notifications , eventConfig , message , data ) => {
268
+ const excludeNotifications = ( logger , notifications , eventConfig , message , data ) => {
260
269
// if there are no rules to exclude notifications, just return all of them untouched
261
270
if ( ! eventConfig . exclude ) {
262
271
return Promise . resolve ( notifications ) ;
@@ -275,7 +284,7 @@ const excludeNotifications = (notifications, eventConfig, message, data) => {
275
284
return Promise . all ( [
276
285
getNotificationsForTopicStarter ( excludeEventConfig , message . topicId ) ,
277
286
getNotificationsForUserId ( excludeEventConfig , message . userId ) ,
278
- getNotificationsForMentionedUser ( eventConfig , message . postContent ) ,
287
+ getNotificationsForMentionedUser ( logger , excludeEventConfig , message . postContent ) ,
279
288
getProjectMembersNotifications ( excludeEventConfig , project ) ,
280
289
getTopCoderMembersNotifications ( excludeEventConfig ) ,
281
290
] ) . then ( ( notificationsPerSource ) => (
@@ -335,7 +344,7 @@ const handler = (topic, message, logger, callback) => {
335
344
getNotificationsForTopicStarter ( eventConfig , message . topicId ) ,
336
345
getNotificationsForUserId ( eventConfig , message . userId ) ,
337
346
getNotificationsForOriginator ( eventConfig , message . originator ) ,
338
- getNotificationsForMentionedUser ( eventConfig , message . postContent ) ,
347
+ getNotificationsForMentionedUser ( logger , eventConfig , message . postContent ) ,
339
348
getProjectMembersNotifications ( eventConfig , project ) ,
340
349
getTopCoderMembersNotifications ( eventConfig ) ,
341
350
] ) . then ( ( notificationsPerSource ) => {
@@ -344,7 +353,7 @@ const handler = (topic, message, logger, callback) => {
344
353
logger . debug ( 'all notifications: ' , notificationsPerSource ) ;
345
354
return _ . uniqBy ( _ . flatten ( notificationsPerSource ) , 'userId' ) ;
346
355
} ) . then ( ( notifications ) => (
347
- excludeNotifications ( notifications , eventConfig , message , {
356
+ excludeNotifications ( logger , notifications , eventConfig , message , {
348
357
project,
349
358
} )
350
359
) ) . then ( ( notifications ) => {
0 commit comments