Skip to content

Commit 10b0c98

Browse files
committed
Issue #1469 - User mentions in the posts
detail: 1. add new event type notifications.connect.project.post.mention 2. extract mentions(like @userid) notifications.connect.project.post.create's content, and send mention notification to users
1 parent 735efe2 commit 10b0c98

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

connect/connectNotificationServer.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ 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+
newType: 'notifications.connect.project.post.mention',
74+
contents: {
75+
toUserHandle: true,
76+
},
77+
});
78+
matches = regexUserId.exec(content);
79+
}
80+
81+
// only one per userId
82+
notifications = _.uniqBy(notifications, 'userId');
83+
return Promise.resolve(notifications);
84+
};
85+
5486
/**
5587
* Get project members notifications
5688
*
@@ -194,6 +226,7 @@ const handler = (topic, message, callback) => {
194226
// - check that event has everything required or throw error
195227
getNotificationsForTopicStarter(eventConfig, message.topicId),
196228
getNotificationsForUserId(eventConfig, message.userId),
229+
getNotificationsForMentionedUser(eventConfig, message.contents.postContent),
197230
getProjectMembersNotifications(eventConfig, project),
198231
getTopCoderMembersNotifications(eventConfig),
199232
]).then((notificationsPerSource) => (

connect/events-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ 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,
102+
}, {
103+
type: 'notifications.connect.project.post.mention',
101104
},
102105
{
103106
type: 'notifications.connect.project.linkCreated',

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function startKafkaConsumer(handlers) {
5252
// save notifications
5353
.then((notifications) => Promise.all(_.map(notifications, (notification) => models.Notification.create({
5454
userId: notification.userId,
55-
type: topicName,
55+
type: notification.newType ? notification.newType : topicName,
5656
contents: _.extend({}, messageJSON, notification.contents),
5757
read: false,
5858
}))))

0 commit comments

Comments
 (0)