Skip to content

Commit 9a068a6

Browse files
author
Vikas Agarwal
committed
Using constants for events name in connectNotificationServer
Updated regular expression to detect user mention
1 parent 4a054de commit 9a068a6

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

connect/connectNotificationServer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const config = require('./config');
99
const notificationServer = require('../index');
1010
const _ = require('lodash');
1111
const service = require('./service');
12+
const { BUS_API_EVENT } = require('../src/constants')
1213
const EVENTS = require('./events-config').EVENTS;
1314
const TOPCODER_ROLE_RULES = require('./events-config').TOPCODER_ROLE_RULES;
1415
const PROJECT_ROLE_RULES = require('./events-config').PROJECT_ROLE_RULES;
@@ -67,14 +68,14 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
6768

6869
let notifications = [];
6970
// eslint-disable-next-line
70-
const regexUserHandle = /title=\"@([a-zA-Z0-9-_.{}\[\]]+)\"/g;
71+
const regexUserHandle = /title=\"@([a-zA-Z0-9-_.{}\[\]]+)\"|\[(.*)\]\(.*\"\@(.*)\"\)/g;
7172
const handles = [];
7273
let matches = regexUserHandle.exec(content);
7374
while (matches) {
7475
const handle = matches[1].toString();
7576
notifications.push({
7677
userHandle: handle,
77-
newType: 'notifications.connect.project.post.mention',
78+
newType: BUS_API_EVENT.EMAIL.MENTIONED_IN_POST,
7879
contents: {
7980
toUserHandle: true,
8081
},
@@ -279,7 +280,7 @@ const handler = (topic, message, callback) => {
279280

280281
// filter out `notifications.connect.project.topic.created` events send by bot
281282
// because they create too much clutter and duplicate info
282-
if (topic === 'notifications.connect.project.topic.created' && message.userId.toString() === config.TCWEBSERVICE_ID) {
283+
if (topic === BUS_API_EVENT.CONNECT.TOPIC_CREATED && message.userId.toString() === config.TCWEBSERVICE_ID) {
283284
return callback(null, []);
284285
}
285286

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const jwt = require('jsonwebtoken');
1111
const _ = require('lodash');
1212
const cors = require('cors');
1313
const bodyParser = require('body-parser');
14-
const { BUS_API_EVENT } = require('./constants')
14+
const { BUS_API_EVENT } = require('./constants');
1515
const helper = require('./common/helper');
1616
const helperService = require('./services/helper');
1717
const logger = require('./common/logger');

0 commit comments

Comments
 (0)