@@ -14,49 +14,48 @@ const {
14
14
BUS_API_EVENT ,
15
15
SCHEDULED_EVENT_PERIOD ,
16
16
SETTINGS_EMAIL_SERVICE_ID ,
17
- ACTIVE_USER_STATUSES
17
+ ACTIVE_USER_STATUSES ,
18
18
} = require ( '../constants' ) ;
19
19
const { EVENTS , EVENT_BUNDLES } = require ( '../events-config' ) ;
20
20
const helpers = require ( '../helpers' ) ;
21
21
const service = require ( '../service' ) ;
22
22
23
23
24
- function replacePlaceholders ( term , data ) {
24
+ function replacePlaceholders ( term , data ) {
25
25
let placeholders = term . match ( / < [ a - z A - Z ] + > / g) ;
26
26
let ret = term ;
27
- if ( placeholders && placeholders . length ) {
28
- _ ( placeholders ) . each ( p => {
29
- let values = _ . map ( data , p . slice ( 1 , - 1 ) ) ;
27
+ if ( placeholders && placeholders . length ) {
28
+ _ ( placeholders ) . each ( p => {
29
+ let values = _ . map ( data , p . slice ( 1 , - 1 ) ) ;
30
30
const total = values . length ;
31
- let replacement = values . length < 3 ?
32
- values . join ( ', ' ) :
33
- values . slice ( 0 , 2 ) . join ( ', ' ) + ' and ' + ( total - 3 ) + 'others' ;
31
+ let replacement = values . length < 3 ?
32
+ values . join ( ', ' ) :
33
+ values . slice ( 0 , 2 ) . join ( ', ' ) + ' and ' + ( total - 3 ) + 'others' ;
34
34
ret = ret . replace ( p , values . join ( ', ' ) ) ;
35
- } )
35
+ } ) ;
36
36
}
37
37
return ret ;
38
38
}
39
39
40
- function getSections ( projectUserEvents ) {
40
+ function getSections ( projectUserEvents ) {
41
41
let sections = [ ] ;
42
42
_ . chain ( projectUserEvents )
43
43
. groupBy ( value => getEventGroupKey ( value ) )
44
- . forIn ( ( value , key ) => {
45
- if ( ! EVENT_BUNDLES [ key ] . groupBy ) {
44
+ . forIn ( ( value , key ) => {
45
+ if ( ! EVENT_BUNDLES [ key ] . groupBy ) {
46
46
sections . push ( {
47
- title :replacePlaceholders ( EVENT_BUNDLES [ key ] . title , _ ( value ) . map ( g => g . data . data ) . value ( ) ) ,
48
- [ key ] :true ,
49
- notifications : _ ( value ) . map ( v => v . data . data ) . value ( )
47
+ title : replacePlaceholders ( EVENT_BUNDLES [ key ] . title , _ ( value ) . map ( g => g . data . data ) . value ( ) ) ,
48
+ [ key ] : true ,
49
+ notifications : _ ( value ) . map ( v => v . data . data ) . value ( ) ,
50
50
} ) ;
51
51
} else {
52
- _ . chain ( value ) . groupBy ( n => n . data . data [ EVENT_BUNDLES [ key ] . groupBy ] ) . forIn ( ( groupValue , groupKey ) => {
53
-
52
+ _ . chain ( value ) . groupBy ( n => n . data . data [ EVENT_BUNDLES [ key ] . groupBy ] ) . forIn ( ( groupValue , groupKey ) => {
54
53
let title = EVENT_BUNDLES [ key ] . title ;
55
- title = replacePlaceholders ( title , _ ( groupValue ) . map ( g => g . data . data ) . value ( ) ) ;
54
+ title = replacePlaceholders ( title , _ ( groupValue ) . map ( g => g . data . data ) . value ( ) ) ;
56
55
sections . push ( {
57
56
title,
58
- [ key ] :true ,
59
- notifications : _ ( groupValue ) . map ( g => g . data . data ) . value ( )
57
+ [ key ] : true ,
58
+ notifications : _ ( groupValue ) . map ( g => g . data . data ) . value ( ) ,
60
59
} ) ;
61
60
} ) . value ( ) ;
62
61
}
@@ -92,7 +91,7 @@ function handleScheduledEvents(events, setEventsStatus) {
92
91
. mapValues ( projectUserEvents => ( {
93
92
id : _ . get ( projectUserEvents , '[0].data.data.projectId' ) ,
94
93
name : _ . get ( projectUserEvents , '[0].data.data.projectName' ) ,
95
- sections : getSections ( projectUserEvents )
94
+ sections : getSections ( projectUserEvents ) ,
96
95
} ) )
97
96
. values ( )
98
97
. value ( ) ,
@@ -104,7 +103,7 @@ function handleScheduledEvents(events, setEventsStatus) {
104
103
105
104
// update common values for bundled email
106
105
eventMessage . replyTo = config . DEFAULT_REPLY_EMAIL ;
107
- eventMessage . version = "v3" ;
106
+ eventMessage . version = 'v3' ;
108
107
eventMessage . cc = [ ] ;
109
108
eventMessage . from = {
110
109
name : config . REPLY_EMAIL_FROM ,
@@ -145,8 +144,8 @@ function getEventGroupKey(value) {
145
144
. keys ( )
146
145
. find ( key => _ . includes ( _ . get ( EVENT_BUNDLES , `${ key } .types` ) , _ . get ( value , 'data.data.type' ) ) )
147
146
. value ( ) ;
148
- if ( ! key ) return 'DEFAULT' ;
149
- return key ;
147
+ if ( ! key ) return 'DEFAULT' ;
148
+ return key ;
150
149
}
151
150
152
151
/**
@@ -157,7 +156,7 @@ function getEventGroupKey(value) {
157
156
*/
158
157
function wrapIndividualNotification ( data ) {
159
158
const key = getEventGroupKey ( data ) ;
160
- const subject = replacePlaceholders ( EVENT_BUNDLES [ key ] . subject , [ data . data . data ] ) ;
159
+ const subject = replacePlaceholders ( EVENT_BUNDLES [ key ] . subject , [ data . data . data ] ) ;
161
160
162
161
return {
163
162
subject,
@@ -212,7 +211,7 @@ function handler(topicName, messageJSON, notification) {
212
211
// don't send email notification for inactive users, ideally we should not have generated
213
212
// notifications for inactive users, however, for now handling it here as safe gaurd
214
213
if ( userStatus && ACTIVE_USER_STATUSES . indexOf ( userStatus ) === - 1 ) {
215
- logger . error ( ` Notification generated for inactive user, ignoring` ) ;
214
+ logger . error ( ' Notification generated for inactive user, ignoring' ) ;
216
215
return ;
217
216
}
218
217
if ( config . ENABLE_DEV_MODE === 'true' ) {
@@ -236,16 +235,16 @@ function handler(topicName, messageJSON, notification) {
236
235
emailToAffectedUser : notification . contents . userEmail === userEmail ,
237
236
} ,
238
237
recipients,
239
- version :"v3" ,
238
+ version : 'v3' ,
240
239
from : {
241
240
name : notification . contents . userHandle ,
242
241
email : config . DEFAULT_REPLY_EMAIL ,
243
242
} ,
244
243
categories,
245
244
} ;
246
- eventMessage . data [ eventMessage . data . type ] = true ;
247
- _ . assign ( eventMessage . data , notification . contents ) ;
248
-
245
+ eventMessage . data [ eventMessage . data . type ] = true ;
246
+ _ . assign ( eventMessage . data , notification . contents ) ;
247
+
249
248
250
249
// default values that get overridden when the notification is about topics/posts updates
251
250
let reference = 'project' ;
@@ -256,7 +255,7 @@ function handler(topicName, messageJSON, notification) {
256
255
messagingEvent = true ;
257
256
eventMessage . data . topicId = parseInt ( messageJSON . topicId , 10 ) ;
258
257
eventMessage . data . postId = messageJSON . postId ? parseInt ( messageJSON . postId , 10 ) : null ;
259
- if ( messageJSON . postContent ) {
258
+ if ( messageJSON . postContent ) {
260
259
eventMessage . data . post = helpers . markdownToHTML ( messageJSON . postContent ) ;
261
260
}
262
261
@@ -304,9 +303,9 @@ function handler(topicName, messageJSON, notification) {
304
303
// if we find the event category for the notification, use the bundle settings from the first event
305
304
if ( eventBundle && eventBundle . types && eventBundle . types . length ) {
306
305
const firstEvtInBundle = eventBundle . types [ 0 ] ;
307
- const firstEvtBundleSettingPath = `notifications['${ firstEvtInBundle } '].${ SETTINGS_EMAIL_SERVICE_ID } .bundlePeriod`
306
+ const firstEvtBundleSettingPath = `notifications['${ firstEvtInBundle } '].${ SETTINGS_EMAIL_SERVICE_ID } .bundlePeriod` ;
308
307
let firstEvtBundlePeriod = _ . get ( settings , firstEvtBundleSettingPath ) ;
309
- bundlePeriod = firstEvtBundlePeriod
308
+ bundlePeriod = firstEvtBundlePeriod ;
310
309
logger . debug ( 'Assuming bundle period of first event in the event category=>' , bundlePeriod ) ;
311
310
}
312
311
}
@@ -315,7 +314,7 @@ function handler(topicName, messageJSON, notification) {
315
314
}
316
315
logger . debug ( 'bundlePeriod=>' , bundlePeriod ) ;
317
316
318
- if ( bundlePeriod && " immediately" !== bundlePeriod && ! requiresImmediateAttention ) {
317
+ if ( bundlePeriod && ' immediately' !== bundlePeriod && ! requiresImmediateAttention ) {
319
318
if ( ! SCHEDULED_EVENT_PERIOD [ bundlePeriod ] ) {
320
319
throw new Error ( `User's '${ notification . userId } ' setting for service`
321
320
+ ` '${ SETTINGS_EMAIL_SERVICE_ID } ' option 'bundlePeriod' has unsupported value '${ bundlePeriod } '.` ) ;
@@ -332,7 +331,7 @@ function handler(topicName, messageJSON, notification) {
332
331
} ) ;
333
332
} else {
334
333
// send single field "notificationsHTML" with the rendered template
335
- eventMessage . data = wrapIndividualNotification ( { data :eventMessage } ) ;
334
+ eventMessage . data = wrapIndividualNotification ( { data : eventMessage } ) ;
336
335
console . log ( eventMessage . data . contents ) ;
337
336
338
337
// send event to bus api
0 commit comments