yumechi-no-kuni/src/server/api/endpoints/i/read_all_unread_notes.ts

39 lines
848 B
TypeScript
Raw Normal View History

2018-11-01 23:47:44 -05:00
import User from '../../../../models/user';
import { publishMainStream } from '../../../../stream';
import NoteUnread from '../../../../models/note-unread';
2018-11-01 23:47:44 -05:00
import define from '../../define';
export const meta = {
desc: {
'ja-JP': '未読の投稿をすべて既読にします。',
'en-US': 'Mark all messages as read.'
},
requireCredential: true,
kind: 'account-write',
params: {
}
};
2018-11-01 23:47:44 -05:00
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
// 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');
res();
2018-11-01 23:47:44 -05:00
}));