@@ -51,6 +51,37 @@ const getTopCoderMembersNotifications = (eventConfig) => {
51
51
} ) ;
52
52
} ;
53
53
54
+ /**
55
+ * Get notifications for mentioned users
56
+ *
57
+ * @param {Object } eventConfig event configuration
58
+ * @param {Object } message content
59
+ *
60
+ * @return {Promise } resolves to a list of notifications
61
+ */
62
+ const getNotificationsForMentionedUser = ( eventConfig , content ) => {
63
+ if ( ! eventConfig . toMentionedUsers ) {
64
+ return Promise . resolve ( [ ] ) ;
65
+ }
66
+
67
+ let notifications = [ ] ;
68
+ const regexUserId = / @ ( [ 0 - 9 ] + ) / g;
69
+ let matches = regexUserId . exec ( content ) ;
70
+ while ( matches ) {
71
+ notifications . push ( {
72
+ userId : matches [ 1 ] . toString ( ) ,
73
+ contents : {
74
+ toUserHandle : true ,
75
+ } ,
76
+ } ) ;
77
+ matches = regexUserId . exec ( content ) ;
78
+ }
79
+
80
+ // only one per userId
81
+ notifications = _ . uniqBy ( notifications , 'userId' ) ;
82
+ return Promise . resolve ( notifications ) ;
83
+ } ;
84
+
54
85
/**
55
86
* Get project members notifications
56
87
*
@@ -194,6 +225,7 @@ const handler = (topic, message, callback) => {
194
225
// - check that event has everything required or throw error
195
226
getNotificationsForTopicStarter ( eventConfig , message . topicId ) ,
196
227
getNotificationsForUserId ( eventConfig , message . userId ) ,
228
+ getNotificationsForMentionedUser ( eventConfig , message . contents . postContent ) ,
197
229
getProjectMembersNotifications ( eventConfig , project ) ,
198
230
getTopCoderMembersNotifications ( eventConfig ) ,
199
231
] ) . then ( ( notificationsPerSource ) => (
0 commit comments