Skip to content

Commit 42fd50d

Browse files
author
vikasrohit
authored
Merge pull request #34 from topcoder-platform/dev
Email notification updates for connect
2 parents 3c9b634 + c1e4117 commit 42fd50d

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

connect/connectNotificationServer.js

Lines changed: 5 additions & 4 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) {
74-
const handle = matches[1].toString();
75+
const handle = matches[1] ? matches[1].toString() : matches[2].toString();
7576
notifications.push({
7677
userHandle: handle,
77-
newType: 'notifications.connect.project.post.mention',
78+
newType: BUS_API_EVENT.CONNECT.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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"sequelize": "^4.21.0",
3636
"superagent": "^3.8.0",
3737
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.2",
38-
"winston": "^2.2.0"
38+
"winston": "^2.2.0",
39+
"remarkable": "^1.7.1"
3940
},
4041
"engines": {
4142
"node": "6.x"

src/app.js

Lines changed: 2 additions & 2 deletions
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');
@@ -113,7 +113,7 @@ function startKafkaConsumer(handlers) {
113113
name: user.firstName + ' ' + user.lastName,
114114
handle: user.handle,
115115
topicTitle: connectTopic.title || '',
116-
post: messageJSON.postContent,
116+
post: helperService.markdownToHTML(messageJSON.postContent),
117117
date: (new Date()).toISOString(),
118118
projectName: notification.contents.projectName,
119119
projectId: messageJSON.projectId,

src/services/helper.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const request = require('superagent');
55
const config = require('config');
66
const _ = require('lodash');
7-
7+
const Remarkable = require('remarkable')
88

99
/**
1010
* Get users details by ids
@@ -63,7 +63,29 @@ const getTopic = (topicId, logger) => request
6363
});
6464

6565

66+
67+
/**
68+
* Convert markdown into raw draftjs state
69+
*
70+
* @param {String} markdown - markdown to convert into raw draftjs object
71+
* @param {Object} options - optional additional data
72+
*
73+
* @return {Object} ContentState
74+
**/
75+
const markdownToHTML = (markdown) => {
76+
const md = new Remarkable('full', {
77+
html: true,
78+
linkify: true,
79+
// typographer: true,
80+
})
81+
// Replace the BBCode [u][/u] to markdown '++' for underline style
82+
const _markdown = markdown.replace(new RegExp('\\[/?u\\]', 'g'), '++')
83+
return md.render(_markdown, {}) // remarkable js takes markdown and makes it an array of style objects for us to easily parse
84+
}
85+
86+
6687
module.exports = {
6788
getUsersById,
6889
getTopic,
90+
markdownToHTML,
6991
};

0 commit comments

Comments
 (0)