Skip to content

Commit

Permalink
feat(Notify): Users can recieve follow notifications
Browse files Browse the repository at this point in the history
- Modify the userController to alert user on follow notification

[Delivers ##168456837]
  • Loading branch information
cvjude committed Sep 12, 2019
1 parent 1a6d125 commit 925a102
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/controllers/notificationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NotificationController {
static async getNotifications(req, res) {
const { user: { id } } = req;
const user = await models.User.findByPk(id);
return successStat(res, 200, 'notifications', await user.getNotifications());
return successStat(res, 200, 'notifications', await user.getNotifications({ where: { read: false } }));
}

/**
Expand Down
8 changes: 8 additions & 0 deletions server/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import sequelize from 'sequelize';
import dotenv from 'dotenv';
import models from '../db/models';
import helpers from '../helpers';
import Notification from '../helpers/notifications';


dotenv.config();
Expand Down Expand Up @@ -381,6 +382,13 @@ class UserController {
await user.removeFollower(id);
}

const payload = {
resourceType: 'follow',
resourceId: req.user.username,
message: `${req.user.username} just ${method === 'POST' ? '' : 'un'}followed you`,
};
Notification.notify([user], payload);

return successStat(res, 200, 'message', 'successful');
}

Expand Down
8 changes: 8 additions & 0 deletions server/helpers/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ class Notification {
text: 'View Comment',
};
break;
case 'follow':
data = {
subject: 'New Follow alert',
header: 'Someone just followed you',
messageBody: `${payload.message}. Click the link below to view the user`,
text: 'View User',
};
break;
}
mailingList.forEach((user) => {
const mail = new Mail({
Expand Down

0 comments on commit 925a102

Please sign in to comment.