2018-11-01 20:32:24 +02:00
|
|
|
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
2018-08-11 15:01:39 +03:00
|
|
|
import Message from '../../../../../models/messaging-message';
|
|
|
|
import { ILocalUser } from '../../../../../models/user';
|
|
|
|
import read from '../../../common/read-messaging-message';
|
|
|
|
import getParams from '../../../get-params';
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2018-08-29 00:59:43 +03:00
|
|
|
'ja-JP': '指定した自分宛てのメッセージを既読にします。',
|
|
|
|
'en-US': 'Mark as read a message of messaging.'
|
2018-08-11 15:01:39 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
kind: 'messaging-write',
|
|
|
|
|
|
|
|
params: {
|
2018-11-01 20:32:24 +02:00
|
|
|
messageId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
transform: transform,
|
2018-08-11 15:01:39 +03:00
|
|
|
desc: {
|
2018-08-29 00:59:43 +03:00
|
|
|
'ja-JP': '既読にするメッセージのID',
|
|
|
|
'en-US': 'The ID of a message that you want to mark as read'
|
2018-08-11 15:01:39 +03:00
|
|
|
}
|
2018-11-01 20:32:24 +02:00
|
|
|
}
|
2018-08-11 15:01:39 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
|
|
|
const [ps, psErr] = getParams(meta, params);
|
2018-10-26 02:36:50 +03:00
|
|
|
if (psErr) return rej(psErr);
|
2018-08-11 15:01:39 +03:00
|
|
|
|
|
|
|
const message = await Message.findOne({
|
|
|
|
_id: ps.messageId,
|
|
|
|
recipientId: user._id
|
|
|
|
});
|
|
|
|
|
|
|
|
if (message == null) {
|
|
|
|
return rej('message not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
read(user._id, message.userId, message);
|
|
|
|
|
|
|
|
res();
|
|
|
|
});
|