Sharkey/src/server/api/endpoints/i/read_all_messaging_messages.ts

43 lines
814 B
TypeScript
Raw Normal View History

2018-12-27 22:06:25 +02:00
import User from '../../../../models/user';
2019-02-05 07:14:23 +02:00
import { publishMainStream } from '../../../../services/stream';
2018-12-27 22:06:25 +02:00
import Message from '../../../../models/messaging-message';
import define from '../../define';
export const meta = {
desc: {
'ja-JP': 'トークメッセージをすべて既読にします。',
'en-US': 'Mark all talk messages as read.'
},
requireCredential: true,
kind: 'account-write',
params: {
}
};
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
// Update documents
await Message.update({
recipientId: user._id,
isRead: false
}, {
$set: {
isRead: true
}
}, {
multi: true
});
User.update({ _id: user._id }, {
$set: {
hasUnreadMessagingMessage: false
}
});
publishMainStream(user._id, 'readAllMessagingMessages');
res();
}));