2018-12-29 15:26:15 +02:00
|
|
|
import $ from 'cafy';
|
|
|
|
import ID, { transform } from '../../../../../misc/cafy-id';
|
2018-12-26 18:24:57 +02:00
|
|
|
import Message from '../../../../../models/messaging-message';
|
|
|
|
import define from '../../../define';
|
2019-02-05 07:14:23 +02:00
|
|
|
import { publishMessagingStream } from '../../../../../services/stream';
|
2019-02-01 17:16:27 +02:00
|
|
|
import * as ms from 'ms';
|
2019-02-22 04:46:58 +02:00
|
|
|
import { ApiError } from '../../../error';
|
2018-12-26 18:24:57 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
stability: 'stable',
|
|
|
|
|
|
|
|
desc: {
|
|
|
|
'ja-JP': '指定したメッセージを削除します。',
|
|
|
|
'en-US': 'Delete a message.'
|
|
|
|
},
|
|
|
|
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['messaging'],
|
|
|
|
|
2018-12-26 18:24:57 +02:00
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
kind: 'messaging-write',
|
|
|
|
|
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
|
|
|
max: 300,
|
|
|
|
minInterval: ms('1sec')
|
|
|
|
},
|
|
|
|
|
|
|
|
params: {
|
|
|
|
messageId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
transform: transform,
|
|
|
|
desc: {
|
|
|
|
'ja-JP': '対象のメッセージのID',
|
|
|
|
'en-US': 'Target message ID.'
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 04:46:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchMessage: {
|
|
|
|
message: 'No such message.',
|
|
|
|
code: 'NO_SUCH_MESSAGE',
|
|
|
|
id: '54b5b326-7925-42cf-8019-130fda8b56af'
|
|
|
|
},
|
2018-12-26 18:24:57 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 04:46:58 +02:00
|
|
|
export default define(meta, async (ps, user) => {
|
2018-12-26 18:24:57 +02:00
|
|
|
const message = await Message.findOne({
|
|
|
|
_id: ps.messageId,
|
|
|
|
userId: user._id
|
|
|
|
});
|
|
|
|
|
|
|
|
if (message === null) {
|
2019-02-22 04:46:58 +02:00
|
|
|
throw new ApiError(meta.errors.noSuchMessage);
|
2018-12-26 18:24:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
await Message.remove({ _id: message._id });
|
|
|
|
|
|
|
|
publishMessagingStream(message.userId, message.recipientId, 'deleted', message._id);
|
|
|
|
publishMessagingStream(message.recipientId, message.userId, 'deleted', message._id);
|
|
|
|
|
2019-02-22 04:46:58 +02:00
|
|
|
return;
|
|
|
|
});
|