rudeshark.net/src/server/api/endpoints/i/read-all-unread-notes.ts

41 lines
852 B
TypeScript
Raw Normal View History

2018-11-02 05:47:44 +01:00
import User from '../../../../models/user';
2019-02-05 06:14:23 +01:00
import { publishMainStream } from '../../../../services/stream';
import NoteUnread from '../../../../models/note-unread';
2018-11-02 05:47:44 +01:00
import define from '../../define';
export const meta = {
desc: {
'ja-JP': '未読の投稿をすべて既読にします。',
'en-US': 'Mark all messages as read.'
},
tags: ['account'],
requireCredential: true,
kind: 'account-write',
params: {
}
};
export default define(meta, async (ps, user) => {
// Remove documents
await NoteUnread.remove({
userId: user._id
});
User.update({ _id: user._id }, {
$set: {
hasUnreadMentions: false,
hasUnreadSpecifiedNotes: false
}
});
// 全て既読になったイベントを発行
publishMainStream(user._id, 'readAllUnreadMentions');
publishMainStream(user._id, 'readAllUnreadSpecifiedNotes');
return;
});