iceshrimp/src/server/api/endpoints/notifications/mark-all-as-read.ts

42 lines
870 B
TypeScript
Raw Normal View History

2018-03-29 20:32:18 +09:00
import Notification from '../../../../models/notification';
2019-02-05 14:14:23 +09:00
import { publishMainStream } from '../../../../services/stream';
2018-11-02 13:47:44 +09:00
import User from '../../../../models/user';
import define from '../../define';
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
},
tags: ['notifications', 'account'],
2018-07-17 04:36:44 +09:00
requireCredential: true,
kind: 'notification-write'
};
export default define(meta, async (ps, user) => {
// Update documents
await Notification.update({
2018-03-29 14:48:47 +09:00
notifieeId: user._id,
isRead: false
}, {
$set: {
isRead: true
}
}, {
multi: true
});
2018-05-29 01:22:39 +09:00
// Update flag
User.update({ _id: user._id }, {
$set: {
hasUnreadNotification: false
}
});
// 全ての通知を読みましたよというイベントを発行
publishMainStream(user._id, 'readAllNotifications');
});