Notifications v2 and Bailey API (#9716)

* Added initial bailey api

* wip

* implement new panel header

* Fixed lint

* add ability to mark notification as seen

* add notification count, remove top badge from user and add ability to mark multiple notifications as seen

* add support dismissall and mark all as read

* do not dismiss actionable notif

* mark as seen when menu is opened instead of closed

* implement ordering, list of actionable notifications

* add groups messages and fix badges count

* add notifications for received cards

* send card received notification to target not sender

* rename notificaion field

* fix integration tests

* mark cards notifications as read and update tests

* add mystery items notifications

* add unallocated stats points notifications

* fix linting

* simplify code

* refactoring and fixes

* fix dropdown opening

* start splitting notifications into their own component

* add notifications for inbox messages

* fix unit tests

* fix default buttons styles

* add initial bailey support

* add title and tests to new stuff notification

* add notification if a group task needs more work

* add tests and fixes for marking a task as needing more work

* make sure user._v is updated

* remove console.log

* notification: hover status and margins

* start styling notifications, add separate files and basic functionalities

* fix tests

* start adding mystery items notification

* wip card notification

* fix cards text

* initial implementation inbox messages

* initial implementation group messages

* disable inbox notifications until mobile is ready

* wip group chat messages

* finish mystery and card notifications

* add bailey notification and fix a lot of stuff

* start adding guilds and parties invitations

* misc invitation fixes

* fix lint issues

* remove old code and add key to notifications

* fix tests

* remove unused code

* add link for public guilds invite

* starts to implement needs work notification design and feature

* fixes to needs work, add group task approved notification

* finish needs work feature

* lots of fixes

* implement quest notification

* bailey fixes and static page

* routing fixes

* fixes #      this.$store.dispatch(guilds:join, {groupId: group.id, type: party});

* read notifications on click

* chat notifications

* fix tests for chat notifications

* fix chat notification test

* fix tests

* fix tests (again)

* try awaiting

* remove only

* more sleep

* add bailey tests

* fix icons alignment

* fix issue with multiple points notifications

* remove merge code

* fix rejecting guild invitation

* make remove area bigger

* fix error with notifications and add migration

* fix migration

* fix typos

* add cleanup migration too

* notifications empty state, new counter color, fix marking messages as seen in guilds

* fixes

* add image and install correct packages

* fix mongoose version

* update bailey

* typo

* make sure chat is marked as read after other requests
This commit is contained in:
Matteo Pagliazzi
2018-01-31 11:55:39 +01:00
committed by GitHub
parent a85282763f
commit 33b249d078
98 changed files with 3003 additions and 1026 deletions

View File

@@ -3,11 +3,13 @@ import _ from 'lodash';
import {
NotFound,
} from '../../libs/errors';
import {
model as User,
} from '../../models/user';
let api = {};
/**
* @apiIgnore Not yet part of the public API
* @api {post} /api/v3/notifications/:notificationId/read Mark one notification as read
* @apiName ReadNotification
* @apiGroup Notification
@@ -38,6 +40,11 @@ api.readNotification = {
user.notifications.splice(index, 1);
// Update the user version field manually,
// it cannot be updated in the pre update hook
// See https://github.com/HabitRPG/habitica/pull/9321#issuecomment-354187666 for more info
user._v++;
await user.update({
$pull: { notifications: { id: req.params.notificationId } },
}).exec();
@@ -47,12 +54,10 @@ api.readNotification = {
};
/**
* @apiIgnore Not yet part of the public API
* @api {post} /api/v3/notifications Mark notifications as read
* @api {post} /api/v3/notifications/read Mark multiple notifications as read
* @apiName ReadNotifications
* @apiGroup Notification
*
*
* @apiSuccess {Object} data user.notifications
*/
api.readNotifications = {
@@ -84,6 +89,102 @@ api.readNotifications = {
$pull: { notifications: { id: { $in: notifications } } },
}).exec();
// Update the user version field manually,
// it cannot be updated in the pre update hook
// See https://github.com/HabitRPG/habitica/pull/9321#issuecomment-354187666 for more info
user._v++;
res.respond(200, user.notifications);
},
};
/**
* @api {post} /api/v3/notifications/:notificationId/see Mark one notification as seen
* @apiDescription Mark a notification as seen. Different from marking them as read in that the notification isn't removed but the `seen` field is set to `true`
* @apiName SeeNotification
* @apiGroup Notification
*
* @apiParam (Path) {UUID} notificationId
*
* @apiSuccess {Object} data The modified notification
*/
api.seeNotification = {
method: 'POST',
url: '/notifications/:notificationId/see',
middlewares: [authWithHeaders()],
async handler (req, res) {
let user = res.locals.user;
req.checkParams('notificationId', res.t('notificationIdRequired')).notEmpty();
let validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
const notificationId = req.params.notificationId;
let notification = _.find(user.notifications, {
id: notificationId,
});
if (!notification) {
throw new NotFound(res.t('messageNotificationNotFound'));
}
notification.seen = true;
await User.update({
_id: user._id,
'notifications.id': notificationId,
}, {
$set: {
'notifications.$.seen': true,
},
}).exec();
// Update the user version field manually,
// it cannot be updated in the pre update hook
// See https://github.com/HabitRPG/habitica/pull/9321#issuecomment-354187666 for more info
user._v++;
res.respond(200, notification);
},
};
/**
* @api {post} /api/v3/notifications/see Mark multiple notifications as seen
* @apiName SeeNotifications
* @apiGroup Notification
*
* @apiSuccess {Object} data user.notifications
*/
api.seeNotifications = {
method: 'POST',
url: '/notifications/see',
middlewares: [authWithHeaders()],
async handler (req, res) {
let user = res.locals.user;
req.checkBody('notificationIds', res.t('notificationsRequired')).notEmpty();
let validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors;
let notificationsIds = req.body.notificationIds;
for (let notificationId of notificationsIds) {
let notification = _.find(user.notifications, {
id: notificationId,
});
if (!notification) {
throw new NotFound(res.t('messageNotificationNotFound'));
}
notification.seen = true;
}
await user.save();
res.respond(200, user.notifications);
},
};