parent
a8cf67198f
commit
5d09b7e38b
6 changed files with 33 additions and 33 deletions
44
src/server/api/endpoints/notifications/mark_all_as_read.ts
Normal file
44
src/server/api/endpoints/notifications/mark_all_as_read.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import Notification from '../../../../models/notification';
|
||||
import event from '../../../../stream';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
ja: '全ての通知を既読にします。',
|
||||
en: 'Mark all notifications as read.'
|
||||
},
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'notification-write'
|
||||
};
|
||||
|
||||
/**
|
||||
* Mark all notifications as read
|
||||
*/
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
// Update documents
|
||||
await Notification.update({
|
||||
notifieeId: user._id,
|
||||
isRead: false
|
||||
}, {
|
||||
$set: {
|
||||
isRead: true
|
||||
}
|
||||
}, {
|
||||
multi: true
|
||||
});
|
||||
|
||||
// Response
|
||||
res();
|
||||
|
||||
// Update flag
|
||||
User.update({ _id: user._id }, {
|
||||
$set: {
|
||||
hasUnreadNotification: false
|
||||
}
|
||||
});
|
||||
|
||||
// 全ての通知を読みましたよというイベントを発行
|
||||
event(user._id, 'read_all_notifications');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue