2018-12-29 15:26:15 +02:00
|
|
|
import $ from 'cafy';
|
2019-04-07 15:50:36 +03:00
|
|
|
import { ID } from '../../../../../misc/cafy-id';
|
2018-12-26 18:24:57 +02:00
|
|
|
import define from '../../../define';
|
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';
|
2019-04-07 15:50:36 +03:00
|
|
|
import { MessagingMessages } from '../../../../../models';
|
2020-11-01 05:14:42 +02:00
|
|
|
import { deleteMessage } from '../../../../../services/messages/delete';
|
2018-12-26 18:24:57 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2019-05-18 14:36:33 +03:00
|
|
|
'ja-JP': '指定したトークメッセージを削除します。',
|
2018-12-26 18:24:57 +02:00
|
|
|
'en-US': 'Delete a message.'
|
|
|
|
},
|
|
|
|
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['messaging'],
|
|
|
|
|
2020-02-15 14:33:32 +02:00
|
|
|
requireCredential: true as const,
|
2018-12-26 18:24:57 +02:00
|
|
|
|
2019-04-15 06:10:40 +03:00
|
|
|
kind: 'write:messaging',
|
2018-12-26 18:24:57 +02:00
|
|
|
|
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
|
|
|
max: 300,
|
|
|
|
minInterval: ms('1sec')
|
|
|
|
},
|
|
|
|
|
|
|
|
params: {
|
|
|
|
messageId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
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) => {
|
2019-04-07 15:50:36 +03:00
|
|
|
const message = await MessagingMessages.findOne({
|
|
|
|
id: ps.messageId,
|
|
|
|
userId: user.id
|
2018-12-26 18:24:57 +02:00
|
|
|
});
|
|
|
|
|
2019-04-07 15:50:36 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-01 05:14:42 +02:00
|
|
|
await deleteMessage(message);
|
2019-02-22 04:46:58 +02:00
|
|
|
});
|