2019-02-05 03:48:08 +01:00
|
|
|
import $ from 'cafy';
|
|
|
|
import ID, { transform } from '../../../../../misc/cafy-id';
|
2018-08-11 14:01:39 +02:00
|
|
|
import Message from '../../../../../models/messaging-message';
|
|
|
|
import read from '../../../common/read-messaging-message';
|
2018-11-02 05:47:44 +01:00
|
|
|
import define from '../../../define';
|
2019-02-22 03:46:58 +01:00
|
|
|
import { ApiError } from '../../../error';
|
2018-08-11 14:01:39 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2018-08-28 23:59:43 +02:00
|
|
|
'ja-JP': '指定した自分宛てのメッセージを既読にします。',
|
|
|
|
'en-US': 'Mark as read a message of messaging.'
|
2018-08-11 14:01:39 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
kind: 'messaging-write',
|
|
|
|
|
|
|
|
params: {
|
2018-11-01 19:32:24 +01:00
|
|
|
messageId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
transform: transform,
|
2018-08-11 14:01:39 +02:00
|
|
|
desc: {
|
2018-08-28 23:59:43 +02:00
|
|
|
'ja-JP': '既読にするメッセージのID',
|
|
|
|
'en-US': 'The ID of a message that you want to mark as read'
|
2018-08-11 14:01:39 +02:00
|
|
|
}
|
2018-11-01 19:32:24 +01:00
|
|
|
}
|
2019-02-22 03:46:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchMessage: {
|
|
|
|
message: 'No such message.',
|
|
|
|
code: 'NO_SUCH_MESSAGE',
|
|
|
|
id: '86d56a2f-a9c3-4afb-b13c-3e9bfef9aa14'
|
|
|
|
},
|
2018-08-11 14:01:39 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
export default define(meta, async (ps, user) => {
|
2018-08-11 14:01:39 +02:00
|
|
|
const message = await Message.findOne({
|
|
|
|
_id: ps.messageId,
|
|
|
|
recipientId: user._id
|
|
|
|
});
|
|
|
|
|
|
|
|
if (message == null) {
|
2019-02-22 03:46:58 +01:00
|
|
|
throw new ApiError(meta.errors.noSuchMessage);
|
2018-08-11 14:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
read(user._id, message.userId, message);
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
return;
|
|
|
|
});
|