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