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