Skip to content
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
4 changes: 3 additions & 1 deletion connect/connectNotificationServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const handler = (topic, message, callback) => {

// now let's retrieve some additional data

// if message has userId such messages will likely need userHandle
// if message has userId such messages will likely need userHandle and user full name
// so let's get it
if (message.userId) {
const ids = [message.userId];
Expand All @@ -214,10 +214,12 @@ const handler = (topic, message, callback) => {
return [];
}).then((users) => {
_.map(allNotifications, (notification) => {
notification.version = eventConfig.version;
notification.contents.projectName = project.name;
// if found a user then add user handle
if (users.length) {
notification.contents.userHandle = users[0].handle;
notification.contents.userFullName = `${users[0].firstName} ${users[0].lastName}`;
}
});
callback(null, allNotifications);
Expand Down
12 changes: 11 additions & 1 deletion connect/events-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ const TOPCODER_ROLE_RULES = {
*
* Each event configuration object has
* type {String} [mandatory] Event type
* version {Number} [optional] Version of the event.
* projectRoles {Array} [optional] List of project member roles which has to get notification
* topcoderRoles {Array} [optional] List of TopCoder member roles which has to get notification
* toUserHandle {Boolean} [optional] If set to true, user defined in `message.userHandle` will get notification
* toTopicStarter {Boolean} [optional] If set to true, than will find who started topic `message.topicId` and send notification to him
* toTopicStarter {Boolean} [optional] If set to true, than will find who started topic `message.topicId` and
* send notification to him
*
* @type {Array}
*/
Expand Down Expand Up @@ -73,13 +75,16 @@ const EVENTS = [
projectRoles: [PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER],
}, {
type: 'notifications.connect.project.member.left',
version: 2,
projectRoles: [PROJECT_ROLE_MANAGER],
}, {
type: 'notifications.connect.project.member.removed',
version: 2,
projectRoles: [PROJECT_ROLE_MANAGER],
toUserHandle: true,
}, {
type: 'notifications.connect.project.member.assignedAsOwner',
version: 2,
projectRoles: [PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER],
toUserHandle: true,
}, {
Expand All @@ -93,20 +98,25 @@ const EVENTS = [
// Project activity
{
type: 'notifications.connect.project.topic.created',
version: 2,
projectRoles: [PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER, PROJECT_ROLE_MEMBER],
}, {
type: 'notifications.connect.project.post.created',
version: 2,
projectRoles: [PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER, PROJECT_ROLE_MEMBER],
toTopicStarter: true,
},
{
type: 'notifications.connect.project.linkCreated',
version: 2,
projectRoles: [PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER, PROJECT_ROLE_MEMBER],
}, {
type: 'notifications.connect.project.fileUploaded',
version: 2,
projectRoles: [PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER, PROJECT_ROLE_MEMBER],
}, {
type: 'notifications.connect.project.specificationModified',
version: 2,
projectRoles: [PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER, PROJECT_ROLE_MEMBER],
},
];
Expand Down
1 change: 1 addition & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function startKafkaConsumer(handlers) {
.then((notifications) => Promise.all(_.map(notifications, (notification) => models.Notification.create({
userId: notification.userId,
type: topicName,
version: notification.version || null,
contents: _.extend({}, messageJSON, notification.contents),
read: false,
}))))
Expand Down
1 change: 1 addition & 0 deletions src/models/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = (sequelize, DataTypes) => sequelize.define('Notification', {
type: { type: DataTypes.STRING, allowNull: false },
contents: { type: DataTypes.JSONB, allowNull: false },
read: { type: DataTypes.BOOLEAN, allowNull: false },
version: { type: DataTypes.SMALLINT, allowNull: true },
}, {});

// sequelize will generate and manage createdAt, updatedAt fields
3 changes: 1 addition & 2 deletions src/services/NotificationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ function* updateSettings(data, userId) {
*/
function* listNotifications(query, userId) {
const settings = yield getSettings(userId);


const filter = { where: {
userId,
}, offset: query.offset, limit: query.limit, order: [['createdAt', 'DESC']] };
if (_.keys(settings).length>0){
if (_.keys(settings).length > 0) {
// only filter out notifications types which were explicitly set to 'no' - so we return notification by default
const notificationTypes = _.keys(settings).filter((notificationType) => settings[notificationType].web !== 'no');
filter.where.type = { $in: notificationTypes };
Expand Down