Skip to content

Commit 6c03788

Browse files
committed
Issue #1469 - User mentions in the posts
- detail: extract @userid from post and send notification to each @userid
1 parent 735efe2 commit 6c03788

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

connect/connectNotificationServer.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,37 @@ const getTopCoderMembersNotifications = (eventConfig) => {
5151
});
5252
};
5353

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+
5485
/**
5586
* Get project members notifications
5687
*
@@ -194,6 +225,7 @@ const handler = (topic, message, callback) => {
194225
// - check that event has everything required or throw error
195226
getNotificationsForTopicStarter(eventConfig, message.topicId),
196227
getNotificationsForUserId(eventConfig, message.userId),
228+
getNotificationsForMentionedUser(eventConfig, message.contents.postContent),
197229
getProjectMembersNotifications(eventConfig, project),
198230
getTopCoderMembersNotifications(eventConfig),
199231
]).then((notificationsPerSource) => (

connect/events-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const EVENTS = [
9898
type: 'notifications.connect.project.post.created',
9999
projectRoles: [PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER, PROJECT_ROLE_MEMBER],
100100
toTopicStarter: true,
101+
toMentionedUsers: true,
101102
},
102103
{
103104
type: 'notifications.connect.project.linkCreated',

0 commit comments

Comments
 (0)