Skip to content

Email notification updates for connect #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions connect/connectNotificationServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const config = require('./config');
const notificationServer = require('../index');
const _ = require('lodash');
const service = require('./service');
const { BUS_API_EVENT } = require('../src/constants')
const EVENTS = require('./events-config').EVENTS;
const TOPCODER_ROLE_RULES = require('./events-config').TOPCODER_ROLE_RULES;
const PROJECT_ROLE_RULES = require('./events-config').PROJECT_ROLE_RULES;
Expand Down Expand Up @@ -67,14 +68,14 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {

let notifications = [];
// eslint-disable-next-line
const regexUserHandle = /title=\"@([a-zA-Z0-9-_.{}\[\]]+)\"/g;
const regexUserHandle = /title=\"@([a-zA-Z0-9-_.{}\[\]]+)\"|\[.*\]\(.*\"\@(.*)\"\)/g;
const handles = [];
let matches = regexUserHandle.exec(content);
while (matches) {
const handle = matches[1].toString();
const handle = matches[1] ? matches[1].toString() : matches[2].toString();
notifications.push({
userHandle: handle,
newType: 'notifications.connect.project.post.mention',
newType: BUS_API_EVENT.CONNECT.MENTIONED_IN_POST,
contents: {
toUserHandle: true,
},
Expand Down Expand Up @@ -279,7 +280,7 @@ const handler = (topic, message, callback) => {

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

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"sequelize": "^4.21.0",
"superagent": "^3.8.0",
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.2",
"winston": "^2.2.0"
"winston": "^2.2.0",
"remarkable": "^1.7.1"
},
"engines": {
"node": "6.x"
Expand Down
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const jwt = require('jsonwebtoken');
const _ = require('lodash');
const cors = require('cors');
const bodyParser = require('body-parser');
const { BUS_API_EVENT } = require('./constants')
const { BUS_API_EVENT } = require('./constants');
const helper = require('./common/helper');
const helperService = require('./services/helper');
const logger = require('./common/logger');
Expand Down Expand Up @@ -113,7 +113,7 @@ function startKafkaConsumer(handlers) {
name: user.firstName + ' ' + user.lastName,
handle: user.handle,
topicTitle: connectTopic.title || '',
post: messageJSON.postContent,
post: helperService.markdownToHTML(messageJSON.postContent),
date: (new Date()).toISOString(),
projectName: notification.contents.projectName,
projectId: messageJSON.projectId,
Expand Down
24 changes: 23 additions & 1 deletion src/services/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const request = require('superagent');
const config = require('config');
const _ = require('lodash');

const Remarkable = require('remarkable')

/**
* Get users details by ids
Expand Down Expand Up @@ -63,7 +63,29 @@ const getTopic = (topicId, logger) => request
});



/**
* Convert markdown into raw draftjs state
*
* @param {String} markdown - markdown to convert into raw draftjs object
* @param {Object} options - optional additional data
*
* @return {Object} ContentState
**/
const markdownToHTML = (markdown) => {
const md = new Remarkable('full', {
html: true,
linkify: true,
// typographer: true,
})
// Replace the BBCode [u][/u] to markdown '++' for underline style
const _markdown = markdown.replace(new RegExp('\\[/?u\\]', 'g'), '++')
return md.render(_markdown, {}) // remarkable js takes markdown and makes it an array of style objects for us to easily parse
}


module.exports = {
getUsersById,
getTopic,
markdownToHTML,
};