@@ -66,22 +66,35 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
66
66
}
67
67
68
68
let notifications = [ ] ;
69
- const regexUserId = / @ ( [ 0 - 9 ] + ) / g;
70
- let matches = regexUserId . exec ( content ) ;
69
+ const regexUserId = / @ ( [ a - z A - Z 0 - 9 - _ .{ } \[ \] ] + ) / g;
70
+ let handles = [ ] ;
71
+ let matches = regexUserId . exec ( content ) ;
72
+ console . log ( "matches" + matches )
71
73
while ( matches ) {
74
+ let handle = matches [ 1 ] . toString ( ) ;
72
75
notifications . push ( {
73
- userId : matches [ 1 ] . toString ( ) ,
76
+ userHandle : handle ,
74
77
newType : 'notifications.connect.project.post.mention' ,
75
78
contents : {
76
79
toUserHandle : true ,
77
80
} ,
78
81
} ) ;
79
82
matches = regexUserId . exec ( content ) ;
83
+ handles . push ( handle ) ;
80
84
}
81
-
82
- // only one per userId
83
- notifications = _ . uniqBy ( notifications , 'userId' ) ;
84
- return Promise . resolve ( notifications ) ;
85
+ // only one per userHandle
86
+ notifications = _ . uniqBy ( notifications , 'userHandle' ) ;
87
+
88
+ return new Promise ( ( resolve ) => {
89
+ service . getUsersByHandle ( handles ) . then ( ( users ) => {
90
+ console . log ( users ) ;
91
+ _ . map ( notifications , ( notification ) => {
92
+ console . log ( "userhandle: " + notification . userHandle ) ;
93
+ notification . userId = _ . find ( users , { handle :notification . userHandle } ) . userId ;
94
+ } ) ;
95
+ resolve ( notifications ) ;
96
+ } )
97
+ } ) ;
85
98
} ;
86
99
87
100
/**
@@ -284,7 +297,7 @@ const handler = (topic, message, callback) => {
284
297
// - check that event has everything required or throw error
285
298
getNotificationsForTopicStarter ( eventConfig , message . topicId ) ,
286
299
getNotificationsForUserId ( eventConfig , message . userId ) ,
287
- message . contents && message . contents . postContent ? getNotificationsForMentionedUser ( eventConfig , message . contents . postContent ) : Promise . resolve ( [ ] ) ,
300
+ message . postContent ? getNotificationsForMentionedUser ( eventConfig , message . postContent ) : Promise . resolve ( [ ] ) ,
288
301
getProjectMembersNotifications ( eventConfig , project ) ,
289
302
getTopCoderMembersNotifications ( eventConfig ) ,
290
303
] ) . then ( ( notificationsPerSource ) => (
0 commit comments