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