2018-03-29 20:32:18 +09:00
|
|
|
import Notification from '../../../../models/notification';
|
2018-10-07 11:06:17 +09:00
|
|
|
import { publishMainStream } from '../../../../stream';
|
2018-06-18 09:54:53 +09:00
|
|
|
import User, { ILocalUser } from '../../../../models/user';
|
2017-10-30 22:12:10 +09:00
|
|
|
|
2018-07-17 04:36:44 +09:00
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2018-08-29 06:59:43 +09:00
|
|
|
'ja-JP': '全ての通知を既読にします。',
|
|
|
|
'en-US': 'Mark all notifications as read.'
|
2018-07-17 04:36:44 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
kind: 'notification-write'
|
|
|
|
};
|
|
|
|
|
2017-10-30 22:12:10 +09:00
|
|
|
/**
|
2018-07-20 14:16:02 +09:00
|
|
|
* Mark all notifications as read
|
2017-10-30 22:12:10 +09:00
|
|
|
*/
|
2018-07-06 02:58:29 +09:00
|
|
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
2017-10-30 22:12:10 +09:00
|
|
|
// Update documents
|
|
|
|
await Notification.update({
|
2018-03-29 14:48:47 +09:00
|
|
|
notifieeId: user._id,
|
|
|
|
isRead: false
|
2017-10-30 22:12:10 +09:00
|
|
|
}, {
|
2018-07-20 14:16:02 +09:00
|
|
|
$set: {
|
|
|
|
isRead: true
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
multi: true
|
|
|
|
});
|
2017-10-30 22:12:10 +09:00
|
|
|
|
|
|
|
// Response
|
|
|
|
res();
|
|
|
|
|
2018-05-29 01:22:39 +09:00
|
|
|
// Update flag
|
|
|
|
User.update({ _id: user._id }, {
|
|
|
|
$set: {
|
|
|
|
hasUnreadNotification: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-10-30 22:12:10 +09:00
|
|
|
// 全ての通知を読みましたよというイベントを発行
|
2018-10-07 11:06:17 +09:00
|
|
|
publishMainStream(user._id, 'readAllNotifications');
|
2017-10-30 22:12:10 +09:00
|
|
|
});
|